The Pedigree Project  0.1
BoardState.h
1 /*
2  *
3  * Copyright (c) 2008-2014, Pedigree Developers
4  *
5  * Please see the CONTRIB file in the root of the source tree for a full
6  * list of contributors.
7  *
8  * Permission to use, copy, modify, and distribute this software for any
9  * purpose with or without fee is hereby granted, provided that the above
10  * copyright notice and this permission notice appear in all copies.
11  *
12  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
15  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19  */
20 
21 #ifndef BOARDSTATE_H
22 #define BOARDSTATE_H
23 
24 enum Side {White=0, Black=1};
25 
26 #include "SideState.h"
27 #include "SearchAlgorithm.h"
28 #include <stdlib.h>
29 
34 {
35 public:
39  BoardState();
40 
41  ~BoardState();
42 
46  void move(Move m, Side s, Piece promotion=Pawn);
47 
51  bool isLegal(Move m, Side s);
52 
56  bool canCastle(Side side);
57  bool inCheck(Side side);
58  bool inCheckmate(Side side);
59  bool underAttack(Square sq, Side side); // Is (col,row) under attack by side?
60  bool rightCastleSquaresFree(Side side);
61  bool leftCastleSquaresFree(Side side);
62 
66  Square firstPawn(Side s, Bitboard *b=NULL);
67  Square nextPawn(Side s, Bitboard *b=NULL);
68  Square firstRook(Side s, Bitboard *b=NULL);
69  Square nextRook(Side s, Bitboard *b=NULL);
70  Square firstKnight(Side s, Bitboard *b=NULL);
71  Square nextKnight(Side s, Bitboard *b=NULL);
72  Square firstBishop(Side s, Bitboard *b=NULL);
73  Square nextBishop(Side s, Bitboard *b=NULL);
74  Square firstQueen(Side s, Bitboard *b=NULL);
75  Square nextQueen(Side s, Bitboard *b=NULL);
76  Square firstKing(Side s, Bitboard *b=NULL);
77 
81  void swapSides();
82 
86  long heuristic(Side side);
87 
91  void dump();
92 
96  bool load(int minPly, Side toPlay, MoveList &ml, long &h);
97 
101  void save(int ply, Side toPlay, long h, MoveList &ml);
102  void savePartial();
103 
104  void uncache(Side toPlay);
105 
106  uint32_t hash();
107  uint32_t hash2();
108 
109  SideState white;
110  SideState black;
111 
112  bool whiteInCheck; bool whiteCheckStateCalculated;
113  bool blackInCheck; bool blackCheckStateCalculated;
114  bool whiteInMate; bool whiteMateStateCalculated;
115  bool blackInMate; bool blackMateStateCalculated;
116  long cachedHash; bool hashCalculated;
117  long cachedHash2; bool hash2Calculated;
118 };
119 
120 #endif
void move(Move m, Side s, Piece promotion=Pawn)
Definition: BoardState.cc:49
bool load(int minPly, Side toPlay, MoveList &ml, long &h)
Definition: BoardState.cc:704
bool canCastle(Side side)
Square firstPawn(Side s, Bitboard *b=NULL)
Definition: BoardState.cc:260
long heuristic(Side side)
Definition: BoardState.cc:649
Definition: Move.h:29
void save(int ply, Side toPlay, long h, MoveList &ml)
Definition: BoardState.cc:709
void swapSides()
Definition: BoardState.cc:642
void dump()
Definition: BoardState.cc:657
Definition: Square.h:24
bool isLegal(Move m, Side s)
Definition: BoardState.cc:73