-
Notifications
You must be signed in to change notification settings - Fork 0
/
board.h
68 lines (49 loc) · 1.86 KB
/
board.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
#ifndef FATPUP_UI_BOARD_H
#define FATPUP_UI_BOARD_H
#include <map>
#include <thread>
#include <mutex>
#include <condition_variable>
#include <atomic>
#include "SFML/Graphics.hpp"
#include "fatpup/position.h"
#include "fatpup/engine.h"
class MovePanel;
class Board
{
public:
explicit Board(const sf::Vector2u windowSize, bool playingWhite = true);
virtual ~Board();
void SetEngine(fatpup::Engine* engine);
void SetMovePanel(MovePanel* movePanel);
void SetPosition(const fatpup::Position& pos);
void Move(fatpup::Move move);
void OnClick(const sf::Vector2f pos);
void Draw(sf::RenderWindow& window) const;
sf::Vector2f GetSize() const { return sf::Vector2f(fatpup::BOARD_SIZE * _squareSize, fatpup::BOARD_SIZE * _squareSize); }
private:
void UpdatePieces();
void ProcessUserMove(const int destSquareIdx);
void EngineThreadFunc();
void RequestEngineMove(fatpup::Move move);
void ShutdownEngineThread();
inline int DisplayRowToFatpup(int row) const { return (_playingWhite ? (fatpup::BOARD_SIZE - 1 - row) : row); }
inline int DisplayColToFatpup(int col) const { return (_playingWhite ? col : (fatpup::BOARD_SIZE - 1 - col)); }
sf::RectangleShape _squares[fatpup::BOARD_SIZE * fatpup::BOARD_SIZE];
mutable sf::Sprite _pieces[fatpup::BOARD_SIZE * fatpup::BOARD_SIZE];
sf::RectangleShape _selectedSquare;
int _selectedSquareIdx = -1;
std::map<unsigned char, sf::Texture> _textures;
fatpup::Position _position;
MovePanel* _movePanel = nullptr;
float _squareSize;
bool _playingWhite;
fatpup::Move _lastMove;
fatpup::Engine* _engine = nullptr;
std::thread* _engineThread = nullptr;
std::mutex _engineMutex;
std::condition_variable _engineCv;
std::atomic<bool> _shutdown{false};
static constexpr float SELECTED_BORDER_WIDTH = 8.0f;
};
#endif // #define FATPUP_UI_BOARD_H