Rev 33 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 33 | Rev 108 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | #include "chess.h" |
1 | #include "chess.h" |
2 | #include "data.h" |
2 | #include "data.h" |
3 | /* last modified |
3 | /* last modified 01/06/16 */ |
4 | /* |
4 | /* |
5 | ******************************************************************************* |
5 | ******************************************************************************* |
6 | * * |
6 | * * |
7 | * UnmakeMove() is responsible for updating the position database whenever a * |
7 | * UnmakeMove() is responsible for updating the position database whenever a * |
8 | * move is retracted. It is the exact inverse of MakeMove(). The hash * |
8 | * move is retracted. It is the exact inverse of MakeMove(). The hash * |
9 | * signature(s) are not updated, they are just restored to their status that * |
9 | * signature(s) are not updated, they are just restored to their status that * |
10 | * was saved before the move was made, to save time. * |
10 | * was saved before the move was made, to save time. * |
11 | * * |
11 | * * |
12 | ******************************************************************************* |
12 | ******************************************************************************* |
13 | */ |
13 | */ |
14 | void UnmakeMove(TREE * RESTRICT tree, int ply, int |
14 | void UnmakeMove(TREE * RESTRICT tree, int ply, int side, int move) { |
15 | uint64_t bit_move; |
15 | uint64_t bit_move; |
16 | int piece, from, to, captured, promote, enemy = Flip(side); |
16 | int piece, from, to, captured, promote, enemy = Flip(side); |
17 | 17 | ||
18 | /* |
18 | /* |
19 | ************************************************************ |
19 | ************************************************************ |
20 | * * |
20 | * * |
21 | * First, restore the hash signatures to their state prior * |
21 | * First, restore the hash signatures to their state prior * |
22 | * to this move being |
22 | * to this move being made by simply copying the old * |
23 | * |
23 | * values. * |
24 | * * |
24 | * * |
25 | ************************************************************ |
25 | ************************************************************ |
26 | */ |
26 | */ |
27 | HashKey = tree->save_hash_key[ply]; |
27 | HashKey = tree->save_hash_key[ply]; |
28 | PawnHashKey = tree->save_pawn_hash_key[ply]; |
28 | PawnHashKey = tree->save_pawn_hash_key[ply]; |
Line 46... | Line 46... | ||
46 | PcOnSq(from) = pieces[side][piece]; |
46 | PcOnSq(from) = pieces[side][piece]; |
47 | /* |
47 | /* |
48 | ************************************************************ |
48 | ************************************************************ |
49 | * * |
49 | * * |
50 | * Now do the piece-specific things by jumping to the * |
50 | * Now do the piece-specific things by jumping to the * |
51 | * appropriate routine |
51 | * appropriate routine (this only has to deal with pawns * |
- | 52 | * and king moves that are castling moves. * |
|
52 | * * |
53 | * * |
53 | ************************************************************ |
54 | ************************************************************ |
54 | */ |
55 | */ |
55 | switch (piece) { |
56 | switch (piece) { |
56 | case pawn: |
57 | case pawn: |
Line 72... | Line 73... | ||
72 | Clear(to, Pieces(side, promote)); |
73 | Clear(to, Pieces(side, promote)); |
73 | Material -= PieceValues(side, promote); |
74 | Material -= PieceValues(side, promote); |
74 | Material += PieceValues(side, pawn); |
75 | Material += PieceValues(side, pawn); |
75 | TotalPieces(side, occupied) -= p_vals[promote]; |
76 | TotalPieces(side, occupied) -= p_vals[promote]; |
76 | TotalPieces(side, promote)--; |
77 | TotalPieces(side, promote)--; |
77 | switch (promote) { |
- | |
78 | case knight: |
- | |
79 | case bishop: |
- | |
80 | TotalMinors(side)--; |
- | |
81 | break; |
- | |
82 | case rook: |
- | |
83 | TotalMajors(side)--; |
- | |
84 | break; |
- | |
85 | case queen: |
- | |
86 | TotalMajors(side) -= 2; |
- | |
87 | break; |
- | |
88 | } |
- | |
89 | } |
78 | } |
90 | break; |
79 | break; |
91 | case knight: |
80 | case knight: |
92 | case bishop: |
81 | case bishop: |
93 | case rook: |
82 | case rook: |
Line 126... | Line 115... | ||
126 | Material += PieceValues(enemy, captured); |
115 | Material += PieceValues(enemy, captured); |
127 | PcOnSq(to) = pieces[enemy][captured]; |
116 | PcOnSq(to) = pieces[enemy][captured]; |
128 | TotalPieces(enemy, captured)++; |
117 | TotalPieces(enemy, captured)++; |
129 | if (captured != pawn) |
118 | if (captured != pawn) |
130 | TotalPieces(enemy, occupied) += p_vals[captured]; |
119 | TotalPieces(enemy, occupied) += p_vals[captured]; |
131 | switch (captured) { |
- | |
132 | case pawn: |
- | |
133 | break; |
- | |
134 | case knight: |
- | |
135 | case bishop: |
- | |
136 | TotalMinors(enemy)++; |
- | |
137 | break; |
- | |
138 | case rook: |
- | |
139 | TotalMajors(enemy)++; |
- | |
140 | break; |
- | |
141 | case queen: |
- | |
142 | TotalMajors(enemy) += 2; |
- | |
143 | break; |
- | |
144 | case king: |
- | |
145 | break; |
- | |
146 | } |
- | |
147 | } |
120 | } |
148 | #if defined(DEBUG) |
121 | #if defined(DEBUG) |
149 | ValidatePosition(tree, ply, move, "UnmakeMove(1)"); |
122 | ValidatePosition(tree, ply, move, "UnmakeMove(1)"); |
150 | #endif |
123 | #endif |
151 | return; |
124 | return; |