-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgame_engine.hpp
More file actions
50 lines (38 loc) · 1.22 KB
/
game_engine.hpp
File metadata and controls
50 lines (38 loc) · 1.22 KB
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
//
// Created by Łukasz Stachowicz on 01/09/2022.
//
#pragma once
#include "rank.hpp"
#include "game.hpp"
#include "player.hpp"
#include "game_session.hpp"
#include "inactive_reciver.hpp"
#include "inactive_detection.hpp"
#include <map>
#include <string>
#include <memory>
namespace RPSGame
{
class GameEngine : public GameInterface, public InactiveReciver<PlayerId>
{
public:
GameEngine();
// Implement Game interface
void rank(std::multimap<uint64_t, std::string>& rank) override;
bool createPlayer(std::string& player_id) override;
bool move(const std::string& player_id, const std::string& action) override;
bool events(const std::string& player_id, std::list<std::string>& events) override;
protected:
void inactive(const std::set<PlayerId>& inactive) override;
std::shared_ptr<GameSession> createGame();
void checkResult(GameSession* game_session, Player* player1, Player* player2);
private:
// std::mutex m_games_lock;
// std::map<GameId, std::shared_ptr<GameSession> > m_games;
std::mutex m_players_lock;
std::map<PlayerId, std::unique_ptr<Player> > m_players;
std::shared_ptr<GameSession> m_last_game;
Rank m_rank;
InactiveDetection<PlayerId> m_detector;
};
}