Inspiration We decided to create a simple Tic Tac Toe game in Python to practice my programming skills and learn more about using numpy arrays for game boards. The project aimed to implement a basic two-player game where the user can play against the computer. What it does Board Representation The game board is represented as a 3x3 NumPy array. Empty cells are denoted by 0, player moves by 1, and computer moves by 2.
Player and Computer Moves Player Move: Takes user input for the row and column and ensures the selected cell is empty before placing the player's move. Computer Move: Randomly selects an available cell for the computer's move. Winning Conditions Functions (row_win, col_win, diag_win) check for a winning condition in rows, columns, and diagonals, respectively. The evaluate function checks for any winning condition or a tie, updating the winner variable accordingly. Game Loop The game loop alternates between the player and computer moves until a winner is determined or the game ends in a tie. The board is printed after each move, providing a visual representation of the game's progression. How we built it The project started with the creation of the game board using NumPy. Functions were implemented to handle player and computer moves, check for winning conditions, and evaluate the overall game state. The game loop was set up to alternate between the player and computer until a winner was determined or the game ended in a tie. Challenges we ran into The computer's moves were intentionally kept random for simplicity. Developing a more sophisticated algorithm for the computer's strategy could be a future improvement. Accomplishments that we're proud of
What we learned I learned how to use numpy arrays to represent the game board efficiently. Numpy made it easier to perform operations on the board and check for winning conditions. Implementing the game logic involved checking for row wins, column wins, and diagonal wins. This project helped me understand how to structure and organize the code for various game functionalities. What's next for PyGridPlay Enhanced Computer AI: Implementing a more sophisticated AI algorithm, such as the minimax algorithm, could make the computer opponent more challenging and strategic.
Log in or sign up for Devpost to join the conversation.