-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
executable file
·111 lines (91 loc) · 2.16 KB
/
main.cpp
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#include <stdio.h>
#include <vector>
#include <iostream>
#include <algorithm>
#include <exception>
#include "pos.hpp"
#include "bitboard.hpp"
#include "checkers.hpp"
#include "evaluate.hpp"
#include "search.hpp"
checkers::Move getUserInput(const std::vector<checkers::Move> &legal_moves)
{
for (size_t i = 0; i < legal_moves.size(); i++)
{
checkers::Move move = legal_moves[i];
printf("(%ld) Start: (Y=%d, X=%d), End: (Y=%d, X=%d), Takes:",
i, move.start.y, move.start.x, move.end.y, move.end.x);
for (int y = 0; y < constants::BOARD_SIZE; y++)
{
for (int x = 0; x < constants::BOARD_SIZE; x++)
{
pos::Pos current_pos = pos::Pos(x, y);
if (bitboard::hasBitAt(move.taken, current_pos))
{
printf("(Y=%d, X=%d), ", y, x);
}
}
}
printf("\n");
}
printf("Enter move: ");
size_t inpt;
std::cin >> inpt;
if (inpt >= legal_moves.size())
{
throw std::runtime_error("Move chosen is out of bounds.");
}
return legal_moves[inpt];
}
int main()
{
checkers::Checkers game = checkers::Checkers();
while (true)
{
if (game.getCurrentPlayer() == bitboard::Color::Black)
{
std::cout << "Black turn: " << std::endl;
}
else
{
std::cout << "White turn: " << std::endl;
}
std::cout << game.toString() << std::endl;
auto legal_moves = game.generateLegalMoves();
std::cout << "Found " << legal_moves.size() << " moves." << std::endl;
if (game.isWon(legal_moves))
{
if (game.getCurrentPlayer() == bitboard::Color::Black)
{
std::cout << "White won!" << std::endl;
}
else
{
std::cout << "Black won! " << std::endl;
}
break;
}
// By changing the color here you can configure which color the user plays
if (game.getCurrentPlayer() == bitboard::Color::Black)
{
while (true)
{
try
{
game.step(getUserInput(legal_moves));
break;
}
catch (const std::runtime_error &error)
{
std::cout << "Illegal move entered, try again:" << std::endl;
continue;
}
}
}
else
{
game.step(search::searchTo(game, 26, 8));
}
}
return 0;
}