-
Notifications
You must be signed in to change notification settings - Fork 0
/
HumanPlayer.cpp
42 lines (33 loc) · 1006 Bytes
/
HumanPlayer.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
#include "HumanPlayer.h"
#include <iostream>
#include <limits>
HumanPlayer::~HumanPlayer() {
}
HumanPlayer::HumanPlayer(std::string seed) {
this->seed = seed;
}
int HumanPlayer::getInput(std::string message, int maxInput) {
int ret = 0;
do {
std::cout << message;
std::cin >> ret;
if (std::cin.fail()) {
std::cin.clear();
std::cin.ignore(std::numeric_limits<std::streamsize>::max(),'\n');
continue;
}
} while (ret > maxInput || ret <= 0 );
ret--;
return ret;
}
GameMove HumanPlayer::askMove(const Game& game) {
BoardCoords coords;
Game humanGame = game;
Board* board = humanGame.getBoard();
coords.row = this->getInput("Input the row[1-" + std::to_string(board->getHeight())
+ "]: ", board->getHeight());
coords.column = this->getInput("Input the column[1-" + std::to_string(board->getWidth())
+ "]: ", board->getWidth());
GameMove move(coords);
return move;
}