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;
124  virtual bool hasCastling() const;
130  virtual bool pawnHasDoubleStep() const;
136  virtual bool hasEnPassantCaptures() const;
144  virtual bool variantHasChanneling(Side side, int square) const;
153  virtual void addPromotions(int sourceSquare,
154  int targetSquare,
155  QVarLengthArray<Move>& moves) const;
157  int kingSquare(Side side) const;
159  int enpassantSquare() const;
164  virtual bool parseCastlingRights(QChar c);
172  bool hasCastlingRight(Side side, CastlingSide castlingSide) const;
180  void removeCastlingRights(int square);
184  void removeCastlingRights(Side side);
189  virtual int castlingFile(CastlingSide castlingSide) const;
194  virtual bool inCheck(Side side, int square = 0) const;
195 
203  virtual QString vFenIncludeString(FenNotation notation) const;
204 
205  // Inherited from Board
206  virtual void vInitialize();
207  virtual QString vFenString(FenNotation notation) const;
208  virtual bool vSetFenString(const QStringList& fen);
209  virtual QString lanMoveString(const Move& move);
210  virtual QString sanMoveString(const Move& move);
211  virtual Move moveFromLanString(const QString& str);
212  virtual Move moveFromSanString(const QString& str);
213  virtual void vMakeMove(const Move& move,
214  BoardTransition* transition);
215  virtual void vUndoMove(const Move& move);
216  virtual void generateMovesForPiece(QVarLengthArray<Move>& moves,
217  int pieceType,
218  int square) const;
219  virtual bool vIsLegalMove(const Move& move);
220  virtual bool isLegalPosition();
221  virtual int captureType(const Move& move) const;
222 
223  private:
224  struct CastlingRights
225  {
226  // Usage: 'rookSquare[Side][CastlingSide]'
227  // A value of zero (square 0) means no castling rights
228  int rookSquare[2][2];
229  };
230 
231  // Data for reversing/unmaking a move
232  struct MoveData
233  {
234  Piece capture;
235  int enpassantSquare;
236  int enpassantTarget;
237  CastlingRights castlingRights;
238  CastlingSide castlingSide;
239  int reversibleMoveCount;
240  };
241 
242  void generateCastlingMoves(QVarLengthArray<Move>& moves) const;
243  void generatePawnMoves(int sourceSquare,
244  QVarLengthArray<Move>& moves) const;
245 
246  bool canCastle(CastlingSide castlingSide) const;
247  QString castlingRightsString(FenNotation notation) const;
248  CastlingSide castlingSide(const Move& move) const;
249  void setEnpassantSquare(int square,
250  int target=0);
251  void setCastlingSquare(Side side,
252  CastlingSide cside,
253  int square);
256  inline int pawnPushOffset(const PawnStep& ps,
257  int sign) const;
258 
259  int m_arwidth;
260  int m_sign;
261  int m_kingSquare[2];
262  int m_enpassantSquare;
263  int m_enpassantTarget;
264  int m_plyOffset;
265  int m_reversibleMoveCount;
266  bool m_kingCanCapture;
267  bool m_hasCastling;
268  bool m_pawnHasDoubleStep;
269  bool m_hasEnPassantCaptures;
270  bool m_pawnAmbiguous;
271  bool m_multiDigitNotation;
272  QVector<MoveData> m_history;
273  CastlingRights m_castlingRights;
274  int m_castleTarget[2][2];
275  const WesternZobrist* m_zobrist;
276 
277  QVarLengthArray<int> m_knightOffsets;
278  QVarLengthArray<int> m_bishopOffsets;
279  QVarLengthArray<int> m_rookOffsets;
280 };
281 
282 
283 } // namespace Chess
284 #endif // WESTERNBOARD_H
Knight.
Definition: westernboard.h:47
WesternPieceType
Definition: westernboard.h:44
FenNotation
Definition: board.h:93
Bishop.
Definition: westernboard.h:48
An internal chessboard class.
Definition: board.h:57
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:29
QVarLengthArray< PawnStep, 8 > m_pawnSteps
Definition: westernboard.h:98
The side or color of a chess player.
Definition: side.h:35
King side (O-O)
Definition: westernboard.h:68
A chess piece.
Definition: piece.h:40
The result of a chess game.
Definition: result.h:34
CastlingSide
Definition: westernboard.h:65
Details of a board transition caused by a move.
Definition: boardtransition.h:40
A small and efficient chessmove class.
Definition: move.h:42
Queen.
Definition: westernboard.h:50
Rook.
Definition: westernboard.h:49
Zobrist keys for Western chess variants.
Definition: westernzobrist.h:28