This project implements a Tic-Tac-Toe game on the Solana blockchain using the Anchor framework. The game demonstrates fundamental concepts of program state, user interaction, and error handling.
- Game Setup: Initializes a new game with two players.
- Play Turns: Players take turns placing their marks on a 3x3 board.
- Win/Tie Detection: Automatically detects a win or a tie.
- Error Handling: Ensures only valid moves are allowed.
The game's state is managed through a custom Solana account. Key attributes include:
- Players: Public keys of the two players.
- Turn: Tracks the current turn.
- Board: A 3x3 grid representing the board.
- State: Tracks if the game is active, tied, or won.
The game logic is implemented in the Game
struct, which provides methods for:
- Starting the game: Setting initial players and turn.
- Making moves: Placing marks on the board and validating them.
- Checking game status: Detecting wins, ties, and updating the state.
-
setup_game
- Initializes the game account and sets the players.
- Allocates space for the account and sets the turn.
-
play
- Updates the board with a player's move.
- Checks for a win or tie.