-
Notifications
You must be signed in to change notification settings - Fork 0
/
hangman_player.h
56 lines (43 loc) · 1.29 KB
/
hangman_player.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
/* Hangman game maker, and scorer.
GPL Copyright 2016, Nathan Parker
*/
#ifndef HANGMAN_PLAYER_H_
#define HANGMAN_PLAYER_H_
#include <string>
#include <unordered_map>
#include <memory>
#include <unordered_set>
// Interface for a player to implement.
class HangmanPlayer {
public:
virtual ~HangmanPlayer() {};
// Interface for a single game.
class Game {
public:
// The Maker calls this repeatedly with an updated pattern.
// Player should fill in word_guess only if it has the answer.
// Otherwise, it returns a char to guess.
virtual char GuessNextChar(const std::string& pattern,
std::string* word_guess) = 0;
virtual ~Game() {};
};
virtual std::unique_ptr<Game> MakeNewGame(size_t word_len) = 0;
};
///
// The "Highest-Probability Character Choice" (HPC) algorithm impl.
typedef std::unordered_set<std::string> StringSet;
// Precomputed data
struct HPCData {
std::unordered_map<size_t, StringSet> words_by_len;
};
class HPCPlayer : public HangmanPlayer {
public:
// This pre-computes things.
HPCPlayer(const StringSet& dictionary);
virtual ~HPCPlayer() override {};
virtual std::unique_ptr<HangmanPlayer::Game> MakeNewGame(size_t word_len)
override;
private:
HPCData data_;
};
#endif // #ifndef HANGMAN_PLAYER_H_