forked from abendebury/checkers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathboard.h
57 lines (48 loc) · 1.9 KB
/
board.h
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
#ifndef __BOARD_H__
#define __BOARD_H__
#include <unordered_set>
#include "checker.h"
using namespace std;
#define NUM_CHECKERS 12
#define NUM_COLS 8
#define NUM_ROWS 8
#define NUM_PLAYERS 2
const int player0_start_x[NUM_CHECKERS] = {1, 3, 5, 7, 0, 2, 4, 6, 1, 3, 5, 7};
const int player0_start_y[NUM_CHECKERS] = {0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2};
const int player1_start_x[NUM_CHECKERS] = {0, 2, 4, 6, 1, 3, 5, 7, 0, 2, 4, 6};
const int player1_start_y[NUM_CHECKERS] = {7, 7, 7, 7, 6, 6, 6, 6, 5, 5, 5, 5};
const int player_symbols[NUM_PLAYERS] = {'X', 'O'};
const int vectors[2][2][2] = {
{
{-1, 1}, //only for player 0
{1, 1}, //only for player 0
},
{
{-1, -1}, //only for player 1
{1, -1}, //only for player1
},
};
class Board {
private:
unordered_set<Checker*> checkers;
public:
Board();
Checker* get_checker_at(const int x, const int y) const;
void kill_checker_at(const int x, const int y);
void print_board() const;
int player_checker_count(const int playernum) const;
bool can_player_move(const int playernum) const;
bool is_move_legal(const int x_start, const int y_start,
const int x_finish, const int y_finish,
const int player) const;
bool is_move_legal(const Checker& piece, const int vector, const int player) const;
int get_capture_vector(const Checker& checker) const;
bool is_move_capture(const Checker& checker, const int x_end,
const int y_end) const;
bool is_position_legal(const int x, const int y) const;
bool can_player_move_piece(const int x, const int y, const int player) const;
bool can_player_move_piece(const Checker& checker, const int player) const;
void make_random_move(int player);
void make_capture(Checker& checker, const int vector);
};
#endif //__GAME_H__