A simple Tic-Tac-Toe game implemented in Go where you play against the computer. The game runs in the console, with the player using X and the computer using O.
- Console-based Tic-Tac-Toe game
- Player vs Computer
- Randomized computer moves
- Checks for win or draw
- Simple and easy-to-understand code
- Clone the repository or download the source code.
- Open a terminal in the project directory.
- Build or run the game:
go run main.go- You are
Xand the computer isO. - Enter the row and column numbers (0-2) to place your
X. - The computer will automatically place its
O. - The game continues until either the player or computer wins, or the board is full (draw).
-------------
| | | |
-------------
| | | |
-------------
| | | |
-------------
Enter row (0-2): 1
Enter col (0-2): 1
Computer chose row 0, col 2
- The board is a 3x3 grid represented by a 2D array.
playerMovefunction handles user input.computerMovefunction picks a random empty cell.checkWinchecks for winning combinations in rows, columns, and diagonals.checkDrawchecks if the board is full without a winner.
- Go 1.18+
This project is licensed under the MIT License.