7
7
import os
8
8
9
9
# dictionaries
10
- APP_ROOT = os .path .dirname (os .path .abspath (__file__ ))
11
- FILE_ROOT = os .path .join (APP_ROOT , '..' , 'dictionaries' )
12
-
13
- DICTIONARIES = {}
14
- DICTIONARIES ["English" ] = FILE_ROOT + "/english.txt"
15
- DICTIONARIES ["Czech" ] = FILE_ROOT + "/czech.txt"
16
- DICTIONARIES ["French" ] = FILE_ROOT + "/french.txt"
17
- DICTIONARIES ["German" ] = FILE_ROOT + "/german.txt"
18
- DICTIONARIES ["Greek" ] = FILE_ROOT + "/greek.txt"
19
- DICTIONARIES ["Italian" ] = FILE_ROOT + "/italian.txt"
20
- DICTIONARIES ["Portuguese" ] = FILE_ROOT + "/portuguese.txt"
21
- DICTIONARIES ["Russian" ] = FILE_ROOT + "/russian.txt"
22
- DICTIONARIES ["Spanish" ] = FILE_ROOT + "/spanish.txt"
23
- DICTIONARIES ["Cards Against Humanity" ] = FILE_ROOT + "/cards_against_humanity.txt"
24
-
25
10
# colors per team
26
11
RED = 'R'
27
12
BLUE = 'B'
36
21
class Info (object ):
37
22
# pylint: disable=too-many-instance-attributes
38
23
"""Object for tracking game stats"""
39
- def __init__ (self , dictionary = 'English' , size = 'normal' , teams = 2 , wordbank = False , mix = False ):
24
+ def __init__ (self , dictionary = 'English' , size = 'normal' , teams = 2 , wordbank = False , mix = False , dictionaries = [] ):
40
25
self .wordbank = wordbank
41
26
self .game_id = self .generate_room_id ()
42
27
self .starting_color = RED
@@ -46,8 +31,8 @@ def __init__(self, dictionary='English', size='normal', teams=2, wordbank=False,
46
31
self .size = size
47
32
self .teams = teams
48
33
self .dictionary = dictionary
34
+ self .dictionaries = dictionaries
49
35
self .mix = mix
50
- self .dictionaries = DICTIONARIES .keys ()
51
36
self .minWords = BOARD_SIZE [self .size ]
52
37
53
38
# gererate board
@@ -120,31 +105,25 @@ def playtime(self):
120
105
121
106
def __get_words (self , size ):
122
107
"""Generate a list of words"""
123
- if not self .dictionary in DICTIONARIES .keys ():
124
- print ("Error: dictionary '" + self .dictionary + "' doesn't exist" )
125
- return None
126
108
# override words with the wordbank
127
109
words = self .wordbank
128
110
if not self .wordbank :
129
111
if self .mix :
130
112
words = []
131
113
for key in self .mix :
132
114
# load and shuffle current dict
133
- tempWords = self .__load_words ( key )
115
+ tempWords = self .dictionaries [ key ]
134
116
random .shuffle (tempWords )
135
117
# get word ratio (rounded up)
136
118
numWords = int (math .ceil ((self .mix [key ]/ 100.0 )* BOARD_SIZE [size ]))
137
119
words = words + tempWords [0 :numWords ]
138
120
else :
139
- words = self .__load_words (self .dictionary )
121
+ print (self .dictionary )
122
+ words = self .dictionaries [self .dictionary ]
140
123
random .shuffle (words )
141
124
final_words = words [0 :BOARD_SIZE [size ]]
142
125
return final_words
143
126
144
- def __load_words (self , d ):
145
- with open (DICTIONARIES .get (d ), 'r' ) as words_file :
146
- return [elem for elem in words_file .read ().split ('\n ' ) if len (elem .strip ()) > 0 ]
147
-
148
127
def __get_layout (self , size , teams ):
149
128
"""Randomly generate a card layout"""
150
129
size = BOARD_SIZE [size ]
0 commit comments