-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDummyPlayers.cpp
58 lines (50 loc) · 1.36 KB
/
DummyPlayers.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
/**
*cpp file of classes XYPlayer,YXPlayer,IllegalPlayer and ExceptionPlayer
*Author Erel Segal-Halevi
*From https://github.com/erelsgl/ariel-cpp-5778/tree/master/week06-inheritance/homework
*Version 1.0
**/
//library
#include "DummyPlayers.h"
const Coordinate XYPlayer::play(const Board& board) {
for (uint x=0; x<board.size(); ++x) {
for (uint 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 (uint y=0; y<board.size(); ++y) {
for (uint 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 = (
myChar=='X'? 'O': 'X'
);
for (uint y=0; y<board.size(); ++y) {
for (uint 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");
}