Giter Site home page Giter Site logo

chess's Introduction

C++ Chess

This is a chess app written in C++. It's primary purpose is for me to learn C++.

Most of the code is in Vecboard.cpp. This file defines several functions that assist in the parsing of a chess game written in PGN (portable game notation) format. PGN format is the most common way of writing chess moves. It provides enough information to recreate a game of chess from start to finish, eliminating any ambiguity that may arise. The main problem that this file solves is taking the current board state and a move as a SAN (standard algebraic notation) string and determining the starting and destination squares.

Most modern chess engines take a fundamentally different approach to game-state representation and move generation than is found in this project. This project uses a 2D Vector to represent the board (board-centric). This is in contrast to the bitboard representation that is used in most modern engines (piece-centric). The bitboard representation is more efficient and allows for faster move generation. However, the board-centric representation is easier to understand and is more intuitive. Which is why I chose to use it.

The main functions in Vecboard.cpp are:

  • void move(string san): Moves a piece from one square to another given the SAN string. Handles move logic and validation and relies on many of the other functions below.
  • vector<pair<int, int>> getValidMoves(int x, int y): Returns a vector of pairs of indices that represent the valid moves for a piece at a given square.
  • pair<pair<int, int>, pair<int, int>> sanToIndices(const string& san) : Converts a SAN move to a pair of pairs of indices for the origin and destination squares.

Other useful functions include:

  • void start(): Sets pieces to their starting positions.
  • void load(string fen): Loads a board state from a FEN string.
  • void forceMove(int fromX, int fromY, int toX, int toY): Moves a piece from one square to another.
  • void print(): Prints the current board state to the console.

TODO

  • Checkmate detection

  • board.prev(), board.next(), board.start: Search through the moves

  • board.eval(): Evaluate the current players position with an integer

  • board.play(): Play moves against a basic engine

  • Refactor the move validation for pins.

chess's People

Contributors

jackbullen avatar

Watchers

 avatar

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.