77import os
88
99# 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-
2510# colors per team
2611RED = 'R'
2712BLUE = 'B'
3621class Info (object ):
3722 # pylint: disable=too-many-instance-attributes
3823 """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 = [] ):
4025 self .wordbank = wordbank
4126 self .game_id = self .generate_room_id ()
4227 self .starting_color = RED
@@ -46,8 +31,8 @@ def __init__(self, dictionary='English', size='normal', teams=2, wordbank=False,
4631 self .size = size
4732 self .teams = teams
4833 self .dictionary = dictionary
34+ self .dictionaries = dictionaries
4935 self .mix = mix
50- self .dictionaries = DICTIONARIES .keys ()
5136 self .minWords = BOARD_SIZE [self .size ]
5237
5338 # gererate board
@@ -120,31 +105,25 @@ def playtime(self):
120105
121106 def __get_words (self , size ):
122107 """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
126108 # override words with the wordbank
127109 words = self .wordbank
128110 if not self .wordbank :
129111 if self .mix :
130112 words = []
131113 for key in self .mix :
132114 # load and shuffle current dict
133- tempWords = self .__load_words ( key )
115+ tempWords = self .dictionaries [ key ]
134116 random .shuffle (tempWords )
135117 # get word ratio (rounded up)
136118 numWords = int (math .ceil ((self .mix [key ]/ 100.0 )* BOARD_SIZE [size ]))
137119 words = words + tempWords [0 :numWords ]
138120 else :
139- words = self .__load_words (self .dictionary )
121+ print (self .dictionary )
122+ words = self .dictionaries [self .dictionary ]
140123 random .shuffle (words )
141124 final_words = words [0 :BOARD_SIZE [size ]]
142125 return final_words
143126
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-
148127 def __get_layout (self , size , teams ):
149128 """Randomly generate a card layout"""
150129 size = BOARD_SIZE [size ]
0 commit comments