/
test_moves_main.hpp
78 lines (67 loc) · 3.69 KB
/
test_moves_main.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#ifndef TEST_MOVES_MAIN_HPP
#define TEST_MOVES_MAIN_HPP
#include <iostream>
#include <vector>
#include "constants.hh"
#include "move_representation.hpp"
#include "board_object.hh"
#include "utilityMethods.hh"
#include "moveMaker.hpp"
#include "FEN.hpp"
namespace test_moves_main_namespace{
int main() {
/*---------- Required initialization ---------*/
move_rep::init();
/*---------- Test encode/decode move ---------*/
Move move1 = move_rep::encodeMove(63, 59, 14, 10, 1, 0, 1);
for (char target = move_rep::startPosIndex; target <= move_rep::pieceThatMovedIndex; target++) {
std::cout << "i:" << (int)target << " data:" << move_rep::decodeMove(move1, target) << std::endl;
}
/*---------- Test print/apply move ---------*/
board::Board testBoard = board::Board();
parseFEN(STARTING_BOARD_FEN, &testBoard);
utility::printBoardArray(&testBoard);
Move move2 = move_rep::encodeMove(index120to64[27], index120to64[46], WN);
move_rep::applyMove(&testBoard, move2);
utility::printBoardArray(&testBoard);
Move move3 = move_rep::encodeMove(index120to64[83], index120to64[63], BP, EMPTY, false, true /*double jump*/);
move_rep::applyMove(&testBoard, move3);
utility::printBoard(&testBoard, true);
std::vector<Move> testMoves {
move_rep::encodeMove(index120to64[37], index120to64[47], WP),
move_rep::encodeMove(index120to64[84], index120to64[74], BP),
move_rep::encodeMove(index120to64[26], index120to64[48], WB),
move_rep::encodeMove(index120to64[92], index120to64[71], BN),
move_rep::encodeMove(index120to64[25], index120to64[27], WK, EMPTY, true /*castle*/),
move_rep::encodeMove(index120to64[93], index120to64[48], BB, WB /*capture*/),
move_rep::encodeMove(index120to64[34], index120to64[54], WP, EMPTY, false, true /*double jump*/),
move_rep::encodeMove(index120to64[94], index120to64[61], BQ),
move_rep::encodeMove(index120to64[46], index120to64[34], WN),
move_rep::encodeMove(index120to64[63], index120to64[53], BP),
move_rep::encodeMove(index120to64[32], index120to64[52], WP, EMPTY, false, true /*double jump*/),
move_rep::encodeMove(index120to64[53], index120to64[42], BP, WP, false, true /*en passant*/),
move_rep::encodeMove(index120to64[34], index120to64[55], WN),
move_rep::encodeMove(index120to64[42], index120to64[31], BP, WP),
move_rep::encodeMove(index120to64[55], index120to64[74], WN, BP),
move_rep::encodeMove(index120to64[31], index120to64[22], BQ, WN /*capture*/, false, false, true /*promote*/),
};
for (auto moveIter = testMoves.begin(); moveIter != testMoves.end(); moveIter++) {
move_rep::applyMove(&testBoard, *moveIter);
utility::printBoard(&testBoard, false, true);
utility::printBoardPieceLocations(&testBoard);
board::Board temp = utility::boardFromPieceLocations(&testBoard);
utility::printBoard(&temp, false, true);
}
/*---------- Test undo move ---------*/
std::cout << "\n\n\n\n------------------------\nTESING UNDO MOVES\n------------------------\n\n\n" << std::endl;
for (auto moveIter = testMoves.rbegin(); moveIter != testMoves.rend(); moveIter++) {
move_rep::undoMove(&testBoard);
utility::printBoard(&testBoard, false, true);
utility::printBoardPieceLocations(&testBoard);
board::Board temp = utility::boardFromPieceLocations(&testBoard);
utility::printBoard(&temp, false, true);
}
return 0;
}
}
#endif