Code Monkey home page Code Monkey logo

chess's Introduction

Data-Structure-Project: CHESS ENGINE

Story

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.

Resources

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).

Overview

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.

Chess Game Mechanics

  • 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

Bot Implementation

  • 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.

Feautures

The main features that are implemented include:

  • ASCII Gameboard
  • Player vs Player
  • Hardcoded decision Bot

Interface

image

  1. Bot vs. Player: The main aim of our project, make the game such that players can play against the chess bot.
  2. Player vs Player: Matchmaking between 2 players. Player 1 always plays as white and Player 2 is black.
  3. Bot vs Bot: A mode to measure the Bot's performance, preference of moves to be played, and general bug searching

Gameboard

image

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).

Player

image

The player has 3 options as shown above.

Make a move:

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.
image

image

Undo a move

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.
image

Resignation

The current player forfeits, giving the opponent the win. Takes the player back to the main menu screen. image

Bot

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).

End of Game

Checkmate

image

Stalemate

image

Draw by Repition

image

Resign

image

chess's People

Contributors

shizzleblitz avatar syedmirtazahyder avatar

Watchers

 avatar

Forkers

shizzleblitz

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.