-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDummyPlayers.cpp
More file actions
52 lines (43 loc) · 1.09 KB
/
DummyPlayers.cpp
File metadata and controls
52 lines (43 loc) · 1.09 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
45
46
47
48
49
50
51
52
#include "DummyPlayers.h"
const Coordinate XYPlayer::play(const Board& board) {
for (int x=0; x<board.size(); ++x) {
for (int y=0; y<board.size(); ++y) {
Coordinate c{x,y};
if (board[c]=='.') {
return c;
}
}
}
return {0,0}; // did not find an empty square - play on the top-left
}
const Coordinate YXPlayer::play(const Board& board) {
for (int y=0; y<board.size(); ++y) {
for (int x=0; x<board.size(); ++x) {
Coordinate c{x,y};
if (board[c]=='.') {
return c;
}
}
}
return {0,0}; // did not find an empty square - play on the top-left
}
/**
* The illegal player tries to put a char on a cell owned by the other player.
*/
const Coordinate IllegalPlayer::play(const Board& board) {
char charOfOtherPlayer = (
getChar()=='X'? 'O': 'X'
);
for (int y=0; y<board.size(); ++y) {
for (int x=0; x<board.size(); ++x) {
Coordinate c{x,y};
if (board[c]==charOfOtherPlayer) {
return c;
}
}
}
return {0,0}; // did not find an illegal square - play on the top-left
}
const Coordinate ExceptionPlayer::play(const Board& board) {
throw string("hahaha");
}