-
Notifications
You must be signed in to change notification settings - Fork 0
/
SimulatedGame.h
76 lines (59 loc) · 1.59 KB
/
SimulatedGame.h
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
#ifndef _SIMULATED_GAME_H
#define _SIMULATED_GAME_H
#include "GameInterface.h"
#include "GameLogic.h"
#include "log.h"
#include <cassert>
class SimulatedGame : public GameInterface
{
public:
virtual void startNewGame(int rows, int cols, int num_mines)
{
_gl.newGame(rows, cols, num_mines);
}
virtual bool loadGame(const std::string& filename)
{
return _gl.loadGame(filename);
}
virtual void executeAction(const SweepAction& action)
{
if (_gl.getCell(action.getLocation()).getState() != Cell::UNKNOWN) return;
switch (action.getAction())
{
case SweepAction::FLAG_CELL:
_gl.mark(action.getRow(), action.getCol());
break;
case SweepAction::CLICK_CELL:
verifyClick(action);
_gl.dig(action.getRow(), action.getCol());
break;
default:
assert(0);
}
}
virtual const MineField* getMineField()
{
return _gl.getMineField();
}
virtual GameState getGameState() const
{
return _gl.getState();
}
virtual int getNumMines() const
{
return _gl.getNumMines();
}
protected:
void verifyClick(const SweepAction& action)
{
if ((_gl.getCell(action.getLocation()).getValue() == Cell::MINE) &&
action.isCertain())
{
Log::print(Log::ERROR, "FATAL SOLVER ERROR: certain click at %d,%d is a mine!\n",
action.getRow(), action.getCol());
exit(1);
}
}
GameLogic _gl;
};
#endif // _SIMULATED_GAME_H