platform link:"https://wokwi.com/projects/442629526380624897"
♟️ Arduino Chess Game for OLED (SSD1306)
This project implements a complete, two-player chess game on an Arduino microcontroller, using an SSD1306 OLED display for the graphical interface and physical buttons for user input.
The game includes essential chess logic such as move validation, path checking, King safety checks (to prevent moving into check), castling, pawn promotion, check detection, and handling checkmate/stalemate.
✨ Features
8x8 Board Visualization: The chessboard is rendered clearly on a 128x64 pixel OLED display.
Solid Piece Graphics: Custom 8x8 pixel bitmaps for all pieces, featuring solid shapes for White and outline shapes for Black for clear contrast.
Full Game Logic: Implements legal moves for all pieces, including special moves like:
Castling (King-side and Queen-side).
Pawn Promotion (automatically to Queen).
Checkmate and Stalemate Detection: The game accurately identifies and declares Check, Checkmate, and Stalemate conditions.
Interactive Controls: Uses five dedicated buttons for cursor movement and piece selection.
Player Turn Indication: Displays the current player's turn status.
Note: Since the button pins are configured with INPUT_PULLUP, the buttons should be wired between the specified Arduino pin and GND (Ground). Pressing the button pulls the pin LOW (digitalRead returns false).
⚙️ Software Setup
Libraries
This project requires the following standard libraries, which can be installed via the Arduino IDE's Library Manager:
Adafruit GFX Library
Adafruit SSD1306
Wire (Standard Arduino Library for I2C communication)
Arduino Code (.ino)
The entire game logic is contained within the single Arduino sketch file. The main components of the code are:
Bitmaps: Defines the 8x8 pixel arrays for all twelve chess pieces.
Board State: A char board[8][8] array stores the current state of the game.
Input Handling: The loop() function handles button debouncing, cursor movement, and piece selection/deselection.
Game Logic: Functions like isLegalMove, isCastlingLegal, doesMoveLeaveKingSafe, and isSquareAttacked handle the complex rules of chess.
Display: The drawBoard() function is responsible for rendering the board, pieces, cursor, selection highlight, and game status messages.
🚀 How to Play
Start: The game begins with White to move.
Move Cursor: Use the UP, DOWN, LEFT, RIGHT buttons to position the cursor (the double-box border) over the piece you want to move.
Select Piece: Press the SELECT button. A piece highlight will appear.
Select Destination: Move the cursor to the desired destination square.
Execute Move: Press the SELECT button again.
If the move is legal and safe (doesn't expose the King), the move is executed, the board is updated, and the turn switches.
If the move is illegal or unsafe, the selection is canceled, and the game continues.
Endgame: The game ends
