-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathGobanModel.h
97 lines (68 loc) · 2.44 KB
/
GobanModel.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
//
// Created by jan on 7.5.17.
//
#ifndef GOBAN_GOBANMODEL_H
#define GOBAN_GOBANMODEL_H
#include "Metrics.h"
#include "Board.h"
#include "GameState.h"
#include <spdlog/spdlog.h>
#include "AudioPlayer.hpp"
#include "GameObserver.h"
#include "GameRecord.h"
class ElementGame;
class GobanModel: public GameObserver {
public:
GobanModel(ElementGame *p, int boardSize = Board::DEFAULTSIZE, int handicap = 0, float komi = 0.0f)
: parent(p), prevPass(false), over(false), invalidated(false),
calcCapturedBlack(0), calcCapturedWhite(0), cursor({0,0}) {
spdlog::info("Preloading sounds...");
//newGame(boardSize, handicap, komi);
}
~GobanModel();
virtual void onGameMove(const Move&, const std::string& comment);
virtual void onKomiChange(float);
virtual void onHandicapChange(const std::vector<Position>&);
virtual void onPlayerChange(int, const std::string&);
virtual void onBoardSized(int);
virtual void onBoardChange(const Board&);
//void newGame(int boardSize = Board::DEFAULTSIZE, int handicap = 0, float komi = 0.0f);
bool isPointOnBoard(const Position& coord);
void start() {
started = true;
over = false;
game.initGame(board.getSize(), state.komi, handicapStones.size(), state.black, state.white);
game.setHandicapStones(handicapStones);
}
Color changeTurn() {
state.colorToMove = Color::other(state.colorToMove);
spdlog::debug("changeTurn = {}", state.colorToMove.toString());
return state.colorToMove;
}
bool isGameOver() { return state.adata.reason != GameState::NOREASON;}
unsigned getBoardSize() const;
Move getPassMove();
Move getUndoMove();
float result(const Move& lastMove, GameState::Result& ret);
void calcCaptured(Metrics& m, int capturedBlack, int capturedWhite);
operator bool() { return !over && started; }
void setCursor(const Position& p) { cursor = p;}
public:
ElementGame* parent;
//TODO multiple views in the future
Board board;
bool prevPass;
bool over;
bool started;
GameState state;
GameRecord game; //TODO find usage and create API including SGF generation
bool invalidated;
static const int maxCaptured = 191;
int calcCapturedBlack, calcCapturedWhite;
float ddc[8 * maxCaptured];
Metrics metrics;
std::mutex mutex;
Position cursor;
std::vector<Position> handicapStones;
};
#endif //GOBAN_GOBANMODEL_H