-
Notifications
You must be signed in to change notification settings - Fork 0
/
AI2_make_move.cpp
56 lines (49 loc) · 1.17 KB
/
AI2_make_move.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
#include "AI.h"
#include <iostream>
#include "conio.h"
#include <thread>
#include <chrono>
bool ch2(Player* p, Board* t, char& c)
{
p->can_take_pawns_from_the_board = true;
AI2_take_pawns_off_the_board(t, p, c);
if (p->dice1 == 0 && p->dice2 == 0)
return true;
return false;
}
// This function will make a move as an AI, if we are unable to make any move, than we return false
void AI2_make_move(Board* t, Player* p)
{
int d1, d2;
get_random_numbers(&d1, &d2);
int ds = d1 + d2;
p->dice1 = d1;
p->dice2 = d2;
char c = p->pawn_char;
for (int i = N_COLUMNS - 1; i >= 0; i--)
{
for (int j = NUMBER_OF_ROWS_IN_COLUMN - 1; j >= 0; j--)
{
/*
Checks whether or not we are able to take pawn out of the board
*/
AI2_insert_pawn_from_bar(t, p, p->dice1 + p->dice2, c);
AI2_insert_pawn_from_bar(t, p, p->dice1, c);
AI2_insert_pawn_from_bar(t, p, p->dice2, c);
if (p->dice1 == 0 && p->dice2 == 0)
return;
// Update dice_sum variable
ds = p->dice1 + p->dice2;
if (check_if_all_pawns_in_home(t, 'R'))
{
if (ch2(p, t, c))
return;
}
else
{
p->can_take_pawns_from_the_board = false;
}
AI2_move_pawn(t, p, i, j, ds, c);
}
}
}