1 #ifndef	__TRANSPOSITION_H__
2 #define	__TRANSPOSITION_H__
3 
4 /* Transposition.h (c) Noah Roberts 2003-03-28
5  * Table and node classes responsible for keeping track of game positions that have
6  * already been searched under a different line or in an earlier iteration.
7  */
8 
9 #include	"HashTable.h"
10 
11 class Board;
12 class Move;
13 
14 #include	<string>
15 
16 enum { NOT_FOUND = 0, EXACT_SCORE = 1, UPPER_BOUND = 2, LOWER_BOUND = 3 };
17 
18 class TNode : public HashNode
19 {
20   unsigned short	bestMove;
21   short			_score;
22   unsigned char		_flag;
23   int			_depth;
24   bool			_stale;
25   std::string		_posText;
26 
27  public:
TNode()28   TNode() { _flag = NOT_FOUND; _depth = -1; _score = 0; bestMove = 0;_stale=true;}
29   TNode(Board *brd);
30   void move(Move &m);
score(short s)31   void score(short s)         { _score = s; }
flag(unsigned char f)32   void flag(unsigned char f)  { _flag = f; }
depth(int d)33   void depth(int d) { _depth = d; }
stale(bool s)34   void stale(bool s) { _stale = s; }
35 
36   Move move();
score()37   short score()         { return _score; }
flag()38   unsigned char flag()  { return _flag; }
depth()39   int depth() { return _depth; }
stale()40   bool stale() { return _stale; }
pos()41   std::string pos() { return _posText; }
42 };
43 
44 class TranspositionTable
45 {
46   HashTable<TNode>	*redTable;
47   HashTable<TNode>	*blueTable;
48 
49   int size;
50 
51   void _find(Board *board, TNode &node, HashTable<TNode> *in);
52   void _store(TNode &node, HashTable<TNode> *in);
53 
54  public:
55   TranspositionTable(int bits);
56   ~TranspositionTable();
57 
58   void store(TNode &node);
59   void find(Board *board, TNode &node);
60 
61   void flush();
62 };
63 
64 #endif /* __TRANSPOSITION_H__ */
65