Skip to content

Latest commit

 

History

History
39 lines (23 loc) · 2.16 KB

File metadata and controls

39 lines (23 loc) · 2.16 KB

🕹️ Project\_01: The "War Games" Simulation (Tic-Tac-Toe) ✖️⭕

MicroPython Badge Game Loop Badge Playable Badge

"Shall we play a game? Before we connect this microcontroller to the global internet, you must prove you can build a closed-loop, interactive system. This is your first real dopamine hit: pure logic turned into a playable simulation."

This project synthesizes everything you have learned so far: variables, loops, functions, lists, and crucially, the error handling. We are building a fully playable, two-player Tic-Tac-Toe game that runs directly inside the Thonny shell.


🧩 THE ARCHITECTURE (How It Works)

We aren't just writing spaghetti code. We are engineering a state machine. The game relies on four distinct "Lego Blocks" of logic snapping together:

1. The Matrix (Data Structure)

The board is just a standard Python list containing 9 elements, representing slots 1 through 9. As players make moves, we overwrite the numbers with an "X" or an "O".

board = ["1", "2", "3", "4", "5", "6", "7", "8", "9"]

2. The Render Engine (Display)

A function that clears the mental clutter and prints the board list into a beautiful, human-readable 3x3 grid in the console.

3. The Input Sanitizer (Error Handling)

Users are unpredictable. If you ask for a number and they type the letter "A", a normal script will crash. We use a try/except block to catch the ValueError, scold the user, and keep the game running flawlessly.

4. The Referee (Win Logic)

After every single turn, a function checks all 8 possible winning combinations (3 rows, 3 columns, 2 diagonals). If it finds three matching symbols, it halts the loop and declares a victor.