Skip to content

Commit

Permalink
Move dictionary config into the language module
Browse files Browse the repository at this point in the history
  • Loading branch information
samfoo committed Apr 3, 2012
1 parent 0f75f1b commit ed391e2
Show file tree
Hide file tree
Showing 4 changed files with 85,923 additions and 4 deletions.
3 changes: 3 additions & 0 deletions bag.py
Expand Up @@ -3,6 +3,8 @@
from random import randint

class en:
dictionary = 'en.txt'

scores = {
'a':1, 'b':3, 'c':3, 'd':2, 'e':1, 'f':4, 'g':2, 'h':4, 'i':1,
'j':8, 'k':5, 'l':1, 'm':3, 'n':1, 'o':1, 'p':3, 'q':10, 'r':1,
Expand All @@ -20,6 +22,7 @@ def normalize(word):
return word

class es:
dictionary = 'es.txt'
scores = {
'a':1, 'b':3, 'c':3, 'd':2, 'e':1, 'f':4, 'g':2, 'h':4, 'i':1,
'j':8, 'l':1, 'm':3, 'n':1, 'o':1, 'p':3, 'q':5, 'r':1, 's':1,
Expand Down
6 changes: 2 additions & 4 deletions board.py
@@ -1,8 +1,6 @@
from dawg import *
from bag import *

DICTIONARY = "scrabble.txt"

# Location of special squares.
# T triple word
# t triple letter
Expand Down Expand Up @@ -32,7 +30,7 @@ class BoardError (Exception):
pass

class Board (object):
def __init__(self, words=open(DICTIONARY), language=en):
def __init__(self, language=en):
self.dawg = Dawg(digraphs=[k for k in language.scores.keys() if len(k) > 1])
self.grid = []
self.language = language
Expand All @@ -47,7 +45,7 @@ def __init__(self, words=open(DICTIONARY), language=en):
self.grid.append(['.'] * 15)

# Initialize the word search from the dictionary.
for line in words:
for line in open(language.dictionary):
self.dawg.insert(language.normalize(unicode(line.strip(), 'UTF-8')))

def __repr__(self):
Expand Down
File renamed without changes.

0 comments on commit ed391e2

Please sign in to comment.