-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathmain.cc
95 lines (77 loc) · 2.42 KB
/
main.cc
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include <iostream>
#include <stdlib.h>
#include "CBoard.h"
#include "ai.h"
/***************************************************************
* main
*
* This is where it all starts!
***************************************************************/
int main()
{
srand(time(0)); // Seed the random number generator.
CBoard board;
AI ai(board);
while (true) // Repeat forever
{
// Display board
std::cout << board;
std::cout << "Input command : ";
// Read input from player
std::string str;
getline(std::cin, str);
std::cout << std::endl;
// Parse input from player
if (std::cin.eof() || str == "quit")
{
exit(1);
}
if (str.compare(0, 5, "move ") == 0)
{
CMove move;
if (move.FromString(str.c_str()+5) == NULL)
{
// Could not parse move.
std::cout << "Try again. Use long notation, e.g. e2e4" << std::endl;
continue; // Go back to beginning
}
if (board.IsMoveValid(move))
{
board.make_move(move);
bool check = board.isOtherKingInCheck();
board.undo_move(move);
if (check)
{
std::cout << "You are in CHECK. Play another move." << std::endl;
continue;
}
std::cout << "You move : " << move << std::endl;
board.make_move(move);
}
else
{
std::cout << "Move " << move << " is not legal." << std::endl;
continue;
}
} // end of "move "
else if (str.compare(0, 2, "go") == 0)
{
CMove best_move = ai.find_best_move();
std::cout << "bestmove " << best_move << std::endl;
board.make_move(best_move);
} // end of "go"
else if (str == "show")
{
CMoveList moves;
board.find_legal_moves(moves);
// std::cout << moves.ToShortString() << std::endl;
std::cout << moves << std::endl;
}
else
{
std::cout << "Unknown command" << std::endl;
std::cout << "Valid commands are: quit, move, go, show" << std::endl;
}
} // end of while (true)
return 0;
} // end of int main()