-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathManualAI.cpp
More file actions
45 lines (40 loc) · 1.05 KB
/
ManualAI.cpp
File metadata and controls
45 lines (40 loc) · 1.05 KB
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
#include "ManualAI.h"
#include <iostream>
ManualAI::ManualAI(int col, int row, int p)
:AI(col, row, p)
{
board = Board(col,row,p);
board.initializeGame();
player = 2;
}
Move ManualAI::GetMove(Move move)
{
if (move.seq.empty())
{
player = 1;
} else{
board.makeMove(move, (player == 1) ? 2 : 1);
}
vector<vector<Move> > moves = board.getAllPossibleMoves(player);
for (int i = 0; i < moves.size();i++)
{
cout<<i<<" : [";
for (int j = 0; j < moves[i].size();j++)
{
cout<<j<<" : "<<moves[i][j].toString()<<", ";
}
cout<<"]"<<endl;
}
cout<<"Waiting input {int} {int}: ";
int n = -1;
int m = -1;
do {
cin >> n;
cin >> m;
if ((n < 0 || n >= moves.size()) || (m < 0 || m >= moves[n].size()))
cout << "Invalid move" << "\n" << "Waiting for input {int} {int}: ";
} while ((n < 0 || n >= moves.size()) || (m < 0 || m >= moves[n].size()));
Move res = moves[n][m];
board.makeMove(res,player);
return res;
}