[update] Documentation.
This commit is contained in:
@@ -1,38 +1,73 @@
|
||||
# Connect Four
|
||||
|
||||
Connect Four is a two player game played on a 7 by 6 grid. Each player has a color: one player is red, and the other player is yellow. The first player starts Connect Four by dropping one of their yellow discs into the (center) column of an empty game board. The two players then alternate turns dropping one of their discs at a time into an unfilled column, until the second player, with red discs, achieves a diagonal four in a row, and wins the game. If the board fills up before either player achieves four in a row, then the game is a draw.
|
||||
Connect Four is a two-player game played on a 7 by 6 grid. Each player has a color: one player is red, and the other player is yellow. The first player starts Connect Four by dropping one of their yellow discs into the (center) column of an empty game board. The two players then alternate turns dropping one of their discs at a time into an unfilled column, until the second player, with red discs, achieves a diagonal four in a row, and wins the game. If the board fills up before either player achieves four in a row, then the game is a draw.
|
||||
|
||||
## Technical specifications
|
||||
|
||||
The game board is an 8 x 8 NeoPixel grid. To mark the limits of the board, the top row is off, in the row below the pixels are blue, and in the rightmost column's pixels are blue from the row below the empty row until the bottom row.
|
||||
The game consists of a rotary encoder, using the Encoder.h library connected to pins:
|
||||
|
||||
```c++
|
||||
#define ENCODER_A 2
|
||||
#define ENCODER_B 3
|
||||
#define ENCODER_SW 4
|
||||
#define ENC_A 0
|
||||
#define ENC_B 1
|
||||
#define ENC_SW 6
|
||||
```
|
||||
|
||||
The grid is managed using the FastLED.h library and is connected to:
|
||||
|
||||
```c++
|
||||
#define LED_PIN 6
|
||||
#define LED_PIN 4
|
||||
#define LED_WIDTH 8
|
||||
#define LED_HEIGHT 8
|
||||
#define NUM_LEDS (LED_WIDTH * LED_HEIGHT)
|
||||
#define NUM_LEDS 64
|
||||
#define LED_TYPE WS2812B
|
||||
#define COLOR_ORDER GRB
|
||||
```
|
||||
|
||||
Players play by turning the rotary encoder to choose a column by rotating the encoder. When they press the button, the disc is dropped and falls to the lowest free position in the grid. If a column is full and a player tries to drop a disc, the disc at the top (column selection row) blinks, indicating that no disc can be dropped. If the player rotates the encoder to a non-full column, a disc can be played.
|
||||
|
||||
A win is when one of the players achieves four connecting discs of the same color: horizontal, vertical, or diagonal. If a player wins, all the discs on the board a dimmed to 15% intensity, and the winning four discs are blinking at high intensity.
|
||||
A win is when one of the players achieves four connecting discs of the same color: horizontal, vertical, or diagonal. If a player wins, all the discs on the board are dimmed to 15% intensity, and the winning four discs are blinking at high intensity.
|
||||
|
||||
If the board is full and none of the players win, a draw, then all the discs on the board are dimmed, and a blinking animation indicates a draw.
|
||||
|
||||
The game has four states:
|
||||
1. Menu: Here the players choose the type of game they want to play, 1 or 2 player. This is indicated on the board by a single yellow vertical bar in the center column (single player versus computer) or two vertical bars: two player game. Rotating the encoder switches between game modes, and pressing the button selects the game mode.
|
||||
|
||||
1. Menu: Here the players choose the type of game they want to play, 1 or 2 player. This is indicated on the board by a single yellow vertical bar in the center column (single player versus computer) or two vertical bars: two player game. Rotating the encoder switches between game modes, and pressing the button selects the game mode.
|
||||
2. Game play: Players are playing the game until one of the players connects four or they achieve a draw.
|
||||
3. Game over: One of the players connects four, or they achieve a draw. If the rotary encoder button is pressed, this state switches to the Menu state.
|
||||
4. Demo mode: The computer plays against itself. This mode is automatically triggered if there is no input for 60 seconds. If the rotary encoder is turned or pushed, the demo mode exits and the game returns to the menu state.
|
||||
|
||||
The program initializes the SerialPrint output (baud 115200) and outputs useful (debugging) information regarding the game state and selections.
|
||||
|
||||
## Implementation Details
|
||||
|
||||
The game is implemented using the following components:
|
||||
|
||||
- **Arduino**: The main platform for the game.
|
||||
- **FastLED.h**: Library for managing the NeoPixel grid.
|
||||
- **Encoder.h**: Library for handling the rotary encoder.
|
||||
|
||||
The game logic includes:
|
||||
|
||||
- **Board Representation**: A 7x6 grid represented as a 2D array.
|
||||
- **Minimax Algorithm**: Used for the AI to determine the best move.
|
||||
- **Win Detection**: Scans the board for four connected discs in any direction.
|
||||
- **Visual Feedback**: Uses LED animations to indicate game state and player actions.
|
||||
|
||||
## Game Modes
|
||||
|
||||
1. **Single Player (Yellow)**: Player vs. AI (Red).
|
||||
2. **Single Player (Red)**: Player vs. AI (Yellow).
|
||||
3. **Two Player**: Player vs. Player.
|
||||
|
||||
## Controls
|
||||
|
||||
- **Rotate Encoder**: Move the cursor to select a column or game mode.
|
||||
- **Press Encoder Button**: Drop a disc or select a game mode.
|
||||
|
||||
## Visual Indicators
|
||||
|
||||
- **Blue LEDs**: Mark the boundaries of the game board.
|
||||
- **Blinking Disc**: Indicates a full column.
|
||||
- **Blinking Win Animation**: Indicates the winning discs.
|
||||
- **Dimmed Board**: Indicates a game over state.
|
||||
|
||||
Reference in New Issue
Block a user