-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
67 lines (57 loc) · 1.86 KB
/
main.py
File metadata and controls
67 lines (57 loc) · 1.86 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
61
62
63
64
65
66
67
# -*- coding: utf-8 -*-
# New game: trígrafos
# Sam Ettinger, May 2015
# sam_ettinger@hmc.edu
import pickle
import random
import os, os.path
# Determine all the language packs we have.
# We just decide each directory in here is a language.
languages = [lang for lang in os.listdir('.') if os.path.isdir(lang) and '.' not in lang]
print('Select your language:')
for i, lang in enumerate(languages):
print('{}: {}'.format(i + 1, lang))
while True:
# Make the user pick a language
try:
selected = int(raw_input('Language number:\n'))
if selected > 0 and selected <= len(languages):
# Set the language
language = languages[selected - 1]
break
except:
pass
print(u'¡No!')
print('Loading {} unigrams...'.format(language))
uni = open(language + '/unigram.dict', 'r')
unigram = pickle.load(uni)
uni.close()
print('Loading {} levels...'.format(language))
lev = open(language + '/levels.list', 'r')
levels = pickle.load(lev)
lev.close()
N = len(levels)
# Start the game!
onStreak = True
level = 0
while 1:
trig = random.choice(levels[level].keys())
guess = raw_input('Level {}: name a word that contains \'{}\':\n'.format(str(level+1), trig))
if trig in guess and guess in unigram.keys():
print(u'¡Muy bien!')
if onStreak and level<N-1:
level += 1
else:
onStreak = True
else:
# Say what would have been good
ok_answers = levels[level][trig][1][0:]
print('Mais non! We would have accepted: {}, etc.'.format(', '.join(ok_answers)))
if len(guess) < 5:
# This should not be a secret rule.
print('Remember, words must be 5 letters or more.')
if not onStreak and level>0:
level += -1
else:
onStreak = False
#áâãàéêíóôõúçü