This project was made for our course EC-200 Data Structure. When we first started this project we had thought to make it in our own terms and make the project using mainly OOP and DS concepts. Hence this implementation does not use bitboards or any other chess programming concepts generally used by people who pursue a working chess Engine. Generally, the outline for how to start working on any chess engine is listed here: https://www.chessprogramming.org/Main_Page
The Project involved many parts, and me and my teammate learned a lot along the way. This was the first project I had used Git Bash for, as well as the first project where I broke down the whole code into smaller segments using header files.
This project means a lot to me and the time and effort poured into this was absurd (a month and a half almost). However, I am proud of this engine. It may not be good at evaluating moves and may not be properly programmed using bitboard, but this is one of the most challenging projects I have undertaken as me writing this README.
Must Read: https://alexanderameye.github.io/notes/chess-engine/
Bot Ideas: https://www.freecodecamp.org/news/simple-chess-ai-step-by-step-1d55a9266977/
How to Properly make a chess engine: https://www.chessprogramming.org/Main_Page
Generating Psuedo Legal and Legal Moves: https://peterellisjones.com/posts/generating-legal-chess-moves-efficiently/#:~:text=Pseudo-legal%20move%20generation,enemy%20pieces%20on%20(captures).
This C++ project implements a Chess Game with a built-in bot player. It focuses on two main components: the core chess game mechanics and the development of a basic bot player.
- Pseudo-legal moves for jumping pieces (pawn, king & knight), and sliding pieces (queen, rook & bishop).
- Checks and Pins for filtering Legal moves from all generated pseudo-legal moves.
- Castling and En-Passant
- Checkmate, Stalemate, Draw by Repetition, Resignation
- Filtering the best position to move based on a heatmap.
- Filtering the best piece to move in a given scenario.
- Avoids check and can deliver checkmate.
The main features that are implemented include:
- ASCII Gameboard
- Player vs Player
- Hardcoded decision Bot
- Bot vs. Player: The main aim of our project, make the game such that players can play against the chess bot.
- Player vs Player: Matchmaking between 2 players. Player 1 always plays as white and Player 2 is black.
- Bot vs Bot: A mode to measure the Bot's performance, preference of moves to be played, and general bug searching
We developed a simple Ascii chessboard. The lowercase first letter tells the color of the piece ("w" = white and "b" = black) and the latter capital case letter denotes the Piece's type ("P" = Pawn, "R" = Rook, "B" = Bishop, "Q" = Queen, "N" = Knight, "K" = King). The board is implemented as a 2D vector containing pointers to the Pieces in the backend (A more optimal approach would be to declare a single 64-element long vector as it would simplify programming piece movement).
The player has 3 options as shown above.
The player is shown the prompt where they enter a valid current position and future position of one of their existing pieces on the board.
Undo's both the players move back to an earlier game state. However, this option is not allowed after castling and promotions. Each piece has its own list where it stores its previous x and y coordinates whenever it is moved. The undo was initially implemented as a stack but was changed to a list to cater to the 3 fold repition rule.
The current player forfeits, giving the opponent the win. Takes the player back to the main menu screen.
A lot of time and effort was put into making the game cater to the Bot. I had to refractor the whole code to generate legal moves so it was easier for the Bot to pick a move. After that, I designed a custom class called moves which took the move and some evaluation metrics, which were sent to a priority queue to always get the Best Computed move based on our evaluation functions. This operation was applied to all the pieces on a single side and then the played move was chosen randomly between the top 3 moves among all the existing pieces (if the evaluation difference between the best and the other moves is 15 or less).