Board.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. #ifndef CHESSY_BOARD_H
  2. #define CHESSY_BOARD_H
  3. #include "BitBoard.h"
  4. #include "MoveGeneration.h"
  5. #include <string>
  6. namespace chessy
  7. {
  8. enum PieceType : int;
  9. class Board;
  10. }
  11. enum chessy::PieceType : int
  12. {
  13. EMPTY = -1,
  14. PAWN = 0,
  15. KNIGHT = 1,
  16. BISHOP = 2,
  17. ROOK = 3,
  18. QUEEN = 4,
  19. KING = 5
  20. };
  21. class chessy::Board
  22. {
  23. Bitboard whites[6];
  24. Bitboard blacks[6];
  25. public:
  26. Board(void) = default;
  27. Board(const Board&) = default;
  28. ~Board(void) = default;
  29. /*!
  30. * resets the board to the chess starting position.
  31. */
  32. void resetBoard(void);
  33. void setEmpty(void);
  34. private:
  35. bool tryToMove(Bitboard start, Bitboard end, Bitboard& b);
  36. public:
  37. Bitboard getWhitePawns (void) const { return whites[PAWN]; }
  38. Bitboard getWhiteKnights(void) const { return whites[KNIGHT]; }
  39. Bitboard getWhiteBishops(void) const { return whites[BISHOP]; }
  40. Bitboard getWhiteRooks (void) const { return whites[ROOK]; }
  41. Bitboard getWhiteQueens (void) const { return whites[QUEEN]; }
  42. Bitboard getWhiteKings (void) const { return whites[KING]; }
  43. Bitboard getBlackPawns (void) const { return blacks[PAWN]; }
  44. Bitboard getBlackKnights(void) const { return blacks[KNIGHT]; }
  45. Bitboard getBlackBishops(void) const { return blacks[BISHOP]; }
  46. Bitboard getBlackRooks (void) const { return blacks[ROOK]; }
  47. Bitboard getBlackQueens (void) const { return blacks[QUEEN]; }
  48. Bitboard getBlackKings (void) const { return blacks[KING]; }
  49. /*!
  50. * parses the first part of a FEN string and sets the board
  51. * to the accourding position
  52. */
  53. void setBoard(const std::string& fenPosition);
  54. std::string getFenBoard(void) const;
  55. PieceType getWhiteAtPosition(Index i) const;
  56. PieceType getBlackAtPosition(Index i) const;
  57. /*!
  58. * applies a move to the board
  59. */
  60. void applyMove(const Move& move);
  61. /*!
  62. * \return
  63. * a bitboard where every field occupied by a white piece
  64. * is 1, every free field 0
  65. */
  66. Bitboard getWhites(void) const;
  67. /*!
  68. * \return
  69. * a bitboard where every field occupied by a black piece
  70. * is 1, every free field 0
  71. */
  72. Bitboard getBlacks(void) const;
  73. /*!
  74. * \return
  75. * a bitboard where every field occupied by any piece
  76. * is 1, every free field 0
  77. */
  78. Bitboard getOccupied(void) const;
  79. /*!
  80. * \return
  81. * a bitboard where every field occupied by any piece
  82. * is 0, every free field 1
  83. */
  84. Bitboard getFree(void) const;
  85. };
  86. #endif // CHESSY_BOARD_H