-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdict.h
More file actions
60 lines (51 loc) · 1.17 KB
/
Copy pathdict.h
File metadata and controls
60 lines (51 loc) · 1.17 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
51
52
53
54
55
56
57
58
59
60
#ifndef DICT
#define DICT
#include "board.h"
#include "util.h"
const int ALPHABET_SIZE = 26;
// we store the dictionary in a Trie made of nodes
// children nodes are indexed by alphabet letters
// encoded as ints.
// We increment a global timestamp g_timestamp each
// time we begin a search. When we find a word, we
// can check to see if we've encountered this word
// before on this search by checking the node's local
// timestamp and comparing it with the global timestamp.
class Node {
public:
Node *children[ALPHABET_SIZE];
bool is_word;
int timestamp;
static int g_timestamp;
Node();
void add_word(const string &s, int i);
void print_words() const;
bool lookup_word(const string &s, int i) const;
int score_tile(const Board &b, int tile, int depth);
~Node();
private:
void print_words(string prefix) const;
};
bool read_dictionary(Node &root, char *dict_file);
inline int word_score(int l) {
switch (l) {
case 0:
return 0;
case 1:
return 0;
case 2:
return 0;
case 3:
case 4:
return 1;
case 5:
return 2;
case 6:
return 3;
case 7:
return 5;
default:
return 11;
}
}
#endif