GithubHelp home page GithubHelp logo

chess-engine's Introduction

chessEngine

Import it to your project and include the header chessEngine.h to never worry about the chess backend logic.

How to use?

Initiate the game:

  1. Create object chessEngine.

  2. Create a object of MATRIX in which the output will be given from the library.

    • It is a 9x9 array in which 1,1 to 8,8 will represent the board.
  3. Begin the game by initializing:

    1. To start the game without any need to save it use int initGame(MATRIX* ptrClientMatrix).

    2. Call the fuction int gameSetup(std::ifstream *gamedata, MATRIX* ptrClientMatrix) and pass the pointer to std::ifstream which has the corresponding file open and points at the beginning of the file. (This is a test version so only .txt files are supported)

      1. To initiate a new game, the file should be empty.
      2. To load the game, the ifstream should point at the beginning of where the saveGame() began to start writing.(It is advisable to keep this file only for game data.)

Play the game:

  1. When user performs the move save the source and destination coordinates in the COORD object.

  2. Call the function int makeMove(COORD sourceCoord, COORD destCoord, MATRIX* ptrClientMatrix, int optionalArgs):

    • optionalArgs will be NULL in most cases. It will be used to take input when a pawn is to be promoted.

    The function will return three types of messsages:

    1. Error Mesages:

      Input is inconsistant with the rules of chess so input is to be taken again

    Message Meaning
    NO_PIECE No piece is found at source
    ME_DESTOUTOFBOARD Destination coordinates are not on the board
    ME_INVALIDMOVE Move is against chess rules
    ME_BLOCKEDMOVE A piece blocks the path of the move
    ME_SELFCHECK Performed move causes check to its own king
    ME_SELFCHECKMATE Performed move causes checkmate to its own king
    ME_SELFSTALEMATE Performed move causes stalemate to its own king
    1. Warning Messages: These messages are to display the next player
    Message Meaning
    CK_CHECK Check to the next player
    CK_CHECKMATE Checkmate of the next player
    CK_STALEMATE Stalemate of the next player
    1. Other messages:
    Message Meaning
    MISC_INPUTPROMOTETO Pawn of the player is to be promoted

    To handle pormote message, take the input from the player to which piece it needs to promote. Then again call the function with source and dest coords without setting any value, address to matrix (to update) and optionalArgs with the value of the piece to which it is to be promoted.

Save the game:

To save the game, call the function int saveGame(std::ofstream *gamedata) with std::ofstream pointing at beginning of the file.(Since this is test version, only .txt format is supported.)

Undo move:

Currently this feature is not porvided by the library. However, if developer needs to implement it then after each move save the game. When the user wants to undo, simply load the game at the previous move.(This feature may be rolled out with with optimizations in further updates)

Sample program:

A sample program in the terminal is made for any reference to how to implement it into code.

Bugs:

-Stalemate and checkmate messages even when not:

The program identifies the check and checkmate conditions properly. However, it cannot be determine if any opponent piece can be killed or obstructed to prevent it. This is the reason why the game is not terminated at checkmate. (An algorithm is currently being tested for the same. It will soon be implemented with an update.)

Features left to program:

-The conditions for draw when a player has no legal move left 
-50 step draw after only king surviving
-Castling and En Passant

chess-engine's People

Contributors

bhavya-tech avatar

Watchers

 avatar

Forkers

khushali6

chess-engine's Issues

Detect draw

The code cannot detect draw automatically.

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.