-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGame.cpp
86 lines (57 loc) · 1.73 KB
/
Game.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// file Game.cpp
#include <cppunit/config/SourcePrefix.h>
#include "Game.h"
#include <algorithm>
#include <iostream>
//---------------------------------------------------------------
Game::Game(Player* human_p, Player* computer_p)
{
reset(human_p, computer_p);
}
//---------------------------------------------------------------
Game::~Game()
{
}
//---------------------------------------------------------------
void Game::reset(Player* human_p, Player* computer_p) throw()
{
human_p->clear();
computer_p->clear();
availableMoves_m.clear();
for ( int i = 0; i <= 8; i++ )
availableMoves_m.insert(i);
}
//---------------------------------------------------------------
void Game::addMove(int move, Player* player_p) throw (invalid_argument)
{
checkAvailableMoves(move);
player_p->insert(move);
}
//---------------------------------------------------------------
void Game::checkAvailableMoves(int move) throw (invalid_argument)
{
IntSet::iterator it = availableMoves_m.find(move);
if ( availableMoves_m.end() == it )
throw invalid_argument("move not valid");
availableMoves_m.erase(it);
}
//---------------------------------------------------------------
bool Game::moveAvailable() const
{
return !availableMoves_m.empty();
}
//---------------------------------------------------------------
bool Game::moveAvailable(int move) const
{
bool returnValue = false;
IntSet::const_iterator it = availableMoves_m.find(move);
if ( availableMoves_m.end() != it )
returnValue = true;
return returnValue;
}
//---------------------------------------------------------------
const IntSet& Game::getAvailable() const
{
return availableMoves_m;
}
//---------------------------------------------------------------