Cute Chess  0.1
westernboard.h
1 /*
2  This file is part of Cute Chess.
3 
4  Cute Chess is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  Cute Chess is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with Cute Chess. If not, see <http://www.gnu.org/licenses/>.
16 */
17 
18 #ifndef WESTERNBOARD_H
19 #define WESTERNBOARD_H
20 
21 #include "board.h"
22 
23 namespace Chess {
24 
25 class WesternZobrist;
26 
27 
40 class LIB_EXPORT WesternBoard : public Board
41 {
42  public:
45  {
46  Pawn = 1,
49  Rook,
51  King
52  };
53 
55  WesternBoard(WesternZobrist* zobrist);
56 
57  // Inherited from Board
58  virtual int width() const;
59  virtual int height() const;
60  virtual Result result();
61  virtual int reversibleMoveCount() const;
62 
63  protected:
66  {
69  NoCastlingSide
70  };
71 
73  static const unsigned KnightMovement = 2;
75  static const unsigned BishopMovement = 4;
77  static const unsigned RookMovement = 8;
78 
80  enum StepType
81  {
82  NoStep = 0,
83  FreeStep = 1,
84  CaptureStep = 2
85  /* FreeOrCaptureStep = FreeStep|CaptureStep //!< like King or Sergeant*/
86  };
88  struct PawnStep { StepType type; int file; };
103  int pawnAmbiguity(StepType type = FreeStep) const;
111  virtual bool kingsCountAssertion(int whiteKings,
112  int blackKings) const;
118  virtual bool kingCanCapture() const;
127  virtual void addPromotions(int sourceSquare,
128  int targetSquare,
129  QVarLengthArray<Move>& moves) const;
131  int kingSquare(Side side) const;
133  int enpassantSquare() const;
141  bool hasCastlingRight(Side side, CastlingSide castlingSide) const;
149  void removeCastlingRights(int square);
154  virtual int castlingFile(CastlingSide castlingSide) const;
159  virtual bool inCheck(Side side, int square = 0) const;
160 
168  virtual QString vFenIncludeString(FenNotation notation) const;
169 
170  // Inherited from Board
171  virtual void vInitialize();
172  virtual QString vFenString(FenNotation notation) const;
173  virtual bool vSetFenString(const QStringList& fen);
174  virtual QString lanMoveString(const Move& move);
175  virtual QString sanMoveString(const Move& move);
176  virtual Move moveFromLanString(const QString& str);
177  virtual Move moveFromSanString(const QString& str);
178  virtual void vMakeMove(const Move& move,
179  BoardTransition* transition);
180  virtual void vUndoMove(const Move& move);
181  virtual void generateMovesForPiece(QVarLengthArray<Move>& moves,
182  int pieceType,
183  int square) const;
184  virtual bool vIsLegalMove(const Move& move);
185  virtual bool isLegalPosition();
186  virtual int captureType(const Move& move) const;
187 
188  private:
189  struct CastlingRights
190  {
191  // Usage: 'rookSquare[Side][CastlingSide]'
192  // A value of zero (square 0) means no castling rights
193  int rookSquare[2][2];
194  };
195 
196  // Data for reversing/unmaking a move
197  struct MoveData
198  {
199  Piece capture;
200  int enpassantSquare;
201  int enpassantTarget;
202  CastlingRights castlingRights;
203  CastlingSide castlingSide;
204  int reversibleMoveCount;
205  };
206 
207  void generateCastlingMoves(QVarLengthArray<Move>& moves) const;
208  void generatePawnMoves(int sourceSquare,
209  QVarLengthArray<Move>& moves) const;
210 
211  bool canCastle(CastlingSide castlingSide) const;
212  QString castlingRightsString(FenNotation notation) const;
213  bool parseCastlingRights(QChar c);
214  CastlingSide castlingSide(const Move& move) const;
215  void setEnpassantSquare(int square,
216  int target=0);
217  void setCastlingSquare(Side side,
218  CastlingSide cside,
219  int square);
222  inline int pawnPushOffset(const PawnStep& ps,
223  int sign) const;
224 
225  int m_arwidth;
226  int m_sign;
227  int m_kingSquare[2];
228  int m_enpassantSquare;
229  int m_enpassantTarget;
230  int m_reversibleMoveCount;
231  bool m_kingCanCapture;
232  bool m_pawnAmbiguous;
233  QVector<MoveData> m_history;
234  CastlingRights m_castlingRights;
235  int m_castleTarget[2][2];
236  const WesternZobrist* m_zobrist;
237 
238  QVarLengthArray<int> m_knightOffsets;
239  QVarLengthArray<int> m_bishopOffsets;
240  QVarLengthArray<int> m_rookOffsets;
241 };
242 
243 
244 } // namespace Chess
245 #endif // WESTERNBOARD_H
Knight.
Definition: westernboard.h:47
WesternPieceType
Definition: westernboard.h:44
FenNotation
Definition: board.h:92
Bishop.
Definition: westernboard.h:48
An internal chessboard class.
Definition: board.h:56
StepType
Definition: westernboard.h:80
A board for western chess variants.
Definition: westernboard.h:40
Definition: westernboard.h:88
Queen side (O-O-O)
Definition: westernboard.h:67
Definition: boardscene.h:28
QVarLengthArray< PawnStep, 8 > m_pawnSteps
Definition: westernboard.h:98
The side or color of a chess player.
Definition: side.h:34
King side (O-O)
Definition: westernboard.h:68
A chess piece.
Definition: piece.h:39
The result of a chess game.
Definition: result.h:33
CastlingSide
Definition: westernboard.h:65
Details of a board transition caused by a move.
Definition: boardtransition.h:39
A small and efficient chessmove class.
Definition: move.h:41
Queen.
Definition: westernboard.h:50
Rook.
Definition: westernboard.h:49
Zobrist keys for Western chess variants.
Definition: westernzobrist.h:27