-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_all_pawns_in_home.cpp
79 lines (75 loc) · 1.36 KB
/
check_all_pawns_in_home.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
#include <iostream>
#include "functions_definitions.h"
#include "conio.h"
void check_if_pawns_in_home(Board* table_s, Player* player_1, Player* player_2, char player_sign)
{
if (check_if_all_pawns_in_home(table_s, player_sign))
{
if (player_sign == 'B')
{
player_1->can_take_pawns_from_the_board = true;
}
else
{
player_2->can_take_pawns_from_the_board = true;
}
}
/*
There may be the case that player was able to take pawns off the board,
but sth happened and now he is not able to do this
*/
else
{
if (player_sign == 'B')
{
player_1->can_take_pawns_from_the_board = false;
}
else
{
player_2->can_take_pawns_from_the_board = false;
}
}
}
bool check_if_all_pawns_in_home(Board* table_s, char player_sign)
{
// Check the board itself
for (int i = 0; i < N_COLUMNS; ++i)
{
for (int j = 0; j < NUMBER_OF_ROWS_IN_COLUMN; ++j)
{
if (player_sign == 'B')
{
if (table_s->pawns[i][j] == player_sign && i > 5)
{
return false;
}
}
else
{
if (table_s->pawns[i][j] == player_sign && i < 18)
{
return false;
}
}
}
}
// Check the bars
for (size_t i = 0; i < BAR_SIZE; ++i)
{
if (player_sign == 'B')
{
if (table_s->player_1_bar[i] == player_sign)
{
return false;
}
}
else
{
if (table_s->player_2_bar[i] == player_sign)
{
return false;
}
}
}
return true;
}