Advertisement
loloof64

ThcPosition.h

Apr 12th, 2020
608
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.15 KB | None | 0 0
  1. #ifndef THCPOSITION_H
  2. #define THCPOSITION_H
  3.  
  4. #include "../chessboard/IPosition.h"
  5. #include "../../libs/thc-chess-library/ChessRules.h"
  6.  
  7. namespace loloof64 {
  8.  
  9.     // Empty structure
  10.     struct IllegalPositionException {};
  11.  
  12.     // Empty structure
  13.     struct IllegalMoveException {};
  14.  
  15.     // Structure with fields file and rank
  16.     struct IllegalCoordinate{
  17.         IllegalCoordinate(int file, int rank): file(file), rank(rank){};
  18.         int file, rank;
  19.     };
  20.  
  21.     class ThcPosition: public IPosition
  22.     {
  23.     public:
  24.         // Takes an option string of the Forsyth-Edwards Notation of the position,
  25.         // sets to standard if no given.
  26.         ThcPosition(std::string fen="rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1");
  27.         ~ThcPosition(){}
  28.         // Gets the Forsyth-Edwards Notation of the position
  29.         std::string getFen() const override;
  30.  
  31.         // True if white turn, false if black turn
  32.         bool isWhiteTurn() const override;
  33.  
  34.         // Gets the piece, in Forsyth-Edwards Notation, at the requested cell.
  35.         // You can use the constants from File and Rank enumerations.
  36.         // May throw IllegalCoordinates
  37.         char getPieceFenAt(int file, int rank) const override;
  38.  
  39.         // True if the given move is legal
  40.         // False otherwise
  41.         bool isLegalMove(int startFile, int startRank, int endFile, int endRank) const override;
  42.  
  43.         // Tries to make the given move
  44.         // Returns the new position in Forsyth-Edwards Notation if success, and throws an IllegalMoveException otherwise.
  45.         // promotionFen should be 'q' or 'Q' (either value whatever the side to move) for queen, 'r' or 'R' for rook,
  46.         // 'b' or 'B' for bishop, or 'n' or 'N' for knight.
  47.         std::string makeMove(int startFile, int startRank, int endFile, int endRank, char promotionFen = 'q') override;
  48.  
  49.  
  50.         // True if the given move leads to a promotion.
  51.         // False if not or if it is an illegal move.
  52.         bool isPromotionMove(int startFile, int startRank, int endFile, int endRank) const override;
  53.     private:
  54.         thc::ChessRules _position;
  55.     };
  56.  
  57. }
  58.  
  59. #endif // THCPOSITION_H
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement