This is a Windows Forms application written in C# that implements a Tic-Tac-Toe game (also known as Gomoku or Caro in some regions) on a 20x17 grid. The game supports two modes: Player vs. Player and Player vs. Computer. The objective is to align five symbols ("O" or "X") in a row, column, or diagonal to win. The game includes features like a timer for moves, an undo option, and a simple AI for the computer opponent.
- Game Modes:
- Player vs. Player: Two players take turns placing "O" or "X" symbols.
- Player vs. Computer: A single player competes against an AI opponent.
- Game Board: A 20x17 grid where players place their symbols.
- Timer: A cooldown timer enforces a time limit for each move, with a timeout resulting in the opponent winning.
- Undo Move: Players can undo their last move (or last two moves in Player vs. Computer mode).
- Win Detection: Automatically checks for five aligned symbols in rows, columns, or diagonals.
- AI Opponent: Uses a heuristic scoring system to prioritize moves based on attack and defense strategies.
- Visual Feedback: Hover effects and game-over background color changes enhance the user experience.
- .NET Framework: Ensure you have .NET Framework installed (compatible with the Windows Forms application).
- Visual Studio: Recommended for building and running the project.
- Resources: The project references image resources (
o.png,x.png,o_img.png,x_img.png) in theProperties.Resourcesnamespace. Ensure these are included in the project.
- Clone the Repository:
git clone https://github.com/realthdat/TicTacToe.git
- Open the Project:
- Open the solution file (
TicTacToe.sln) in Visual Studio.
- Open the solution file (
- Add Resources:
- Ensure the required image files (
o.png,x.png,o_img.png,x_img.png) are added to the project's resources.
- Ensure the required image files (
- Build and Run:
- Build the solution in Visual Studio (Ctrl+Shift+B).
- Run the application (F5).
- Game Controls:
- Use the menu strip to start a new game (Player vs. Player or Player vs. Computer).
- Click on a grid cell to place a symbol.
- Use the "Undo" option to revert the last move(s).
- Select "Quit" to exit the game.
- Form1.cs: The main form containing the game logic, UI setup, and event handlers.
- Initializes a 20x17 grid of
Labelcontrols for the game board. - Manages game state (
player,gameover,vsComputer, etc.). - Handles user interactions (clicks, hover effects, timer ticks).
- Implements AI logic for the computer opponent using attack and defense scoring.
- Initializes a 20x17 grid of
- Chess.cs: A class representing a move on the board, storing the
Labelcontrol and coordinates (X,Y). - Contain.cs: (Assumed) A static class defining constants like
edgeChess(cell size). - Resources: Image files for "O" and "X" symbols used in the game.
- Start a Game:
- Choose "Player vs. Player" or "Player vs. Computer" from the menu.
- Make a Move:
- Click an empty cell to place your symbol ("O" for Player 1, "X" for Player 2 or Computer).
- A timer starts after each move. If it expires, the opponent wins.
- Undo a Move:
- Click "Undo" to revert the last move (or last two moves in Player vs. Computer mode).
- Win Condition:
- Align five symbols in a row, column, or diagonal to win.
- The game ends with a message box announcing the winner, and the board turns gray.
- Quit:
- Select "Quit" from the menu to exit the game.
The computer opponent uses a heuristic-based approach:
- Scoring System:
- Attack Scores: Prioritize moves that create or extend sequences of "X" symbols (e.g., 2, 3, or 4 in a line).
- Defense Scores: Prioritize moves that block or counter sequences of "O" symbols.
- Scores are defined in arrays
AttackandDefensewith increasing values for longer sequences.
- Move Selection:
- The AI evaluates all empty cells, calculating a combined attack and defense score.
- It selects the cell with the highest score to place its "X" symbol.
- The
Containclass is referenced but not provided in the code. Ensure it definesedgeChess(e.g.,public static int edgeChess = 30;) for the grid cell size. - The project assumes image resources are correctly set up in
Properties.Resources. - The timer (
tmCooldown) and progress bar (psbCooldownTime) must be configured in the form designer with appropriate properties (e.g.,Maximum,Step).
- Add difficulty seviyeler for the AI (e.g., easy, medium, hard).
- Enhance the UI with customizable board sizes or themes.
- Implement a move history log or replay feature.
- Add sound effects for moves and game-over events.
This project is for educational purposes. Feel free to modify and distribute as needed.