-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayer.py
155 lines (126 loc) · 3.56 KB
/
player.py
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
import requests
import re
base_url = 'https://pds-nerdle-b475e73d0e76.herokuapp.com'
player_key = 'MUNO206'
def send_data(game,key,equality):
data = {
'game': game,
'key': key,
'equality': equality
}
r = requests.post(f'{base_url}/api/play/', data=data)
return r.json()
def load_possible_equations(largo):
if largo==5:
file=open('options/5.txt')
options = [line.strip() for line in file]
return options,"1+2=3","9-5=4"
elif largo==6:
file=open('options/6.txt')
options = [line.strip() for line in file]
return options,"10-4=6","9+8=17"
elif largo==7:
file=open('options/7.txt')
options = [line.strip() for line in file]
return options,"34-29=5","56-7=49"
elif largo==8:
file=open('options/8.txt')
options = [line.strip() for line in file]
return options,"12+36=48","11+5-9=7"
def get_games():
response = requests.get(f'{base_url}/api/games/')
games = response.json()['games']
game_len=[x['eq_length'] for x in games if x['eq_count']==1]
game_id=[x['id'] for x in games if x['eq_count']==1]
return game_len,game_id
#lo que tengo que hacer es verificar
def remove_bads(options,info,play,dic):
new_options = []
for i in range(len(info)):
dic[info[i]].add((play[i],i))
correct = [x[0] for x in dic['2']]
in_correct = [x[0] for x in dic['0']]
semi_correct = [x[0] for x in dic['1']]
if len(correct)>1 and len(in_correct)>1:
for eq in options:
not_in_eq = True
not_same_pos_1= True
not_same_pos_2= True
fixed_number = True
for key in dic:
if key=='0':
#Si estan no las quiero
for ch,pos in dic[key]:
if ch in correct or ch in semi_correct:
if eq[pos]==ch:
not_same_pos_2= False
elif ch in eq:
not_in_eq = False
elif key == '1':
for ch,pos in dic[key]:
if eq[pos] ==ch:
not_same_pos_1 = False
elif key=='2':
for ch,pos in dic[key]:
if eq[pos] != ch:
fixed_number = False
if not_in_eq and not_same_pos_1 and fixed_number and not_same_pos_2:
new_options.append(eq)
else:
continue
else:
for eq in options:
not_in_eq = True
not_same_pos_1= True
not_same_pos_2= True
fixed_number = True
for key in dic:
if key=='0':
#Si estan no las quiero
for ch,pos in dic[key]:
if ch in correct or ch in semi_correct:
if eq[pos]==ch:
not_same_pos_2= False
elif ch in eq:
not_in_eq = False
elif key == '1':
for ch,pos in dic[key]:
if eq[pos] ==ch:
not_same_pos_1 = False
elif key=='2':
for ch,pos in dic[key]:
if eq[pos] != ch:
fixed_number = False
if not_in_eq and not_same_pos_1 and fixed_number:
new_options.append(eq)
else:
continue
return new_options
g_lenghts,g_ids=get_games()
for j in range(len(g_lenghts)):
dic = {'2':set(),'1':set(),'0':set()}
game = g_ids[j]
options,equality1,equality2= load_possible_equations(g_lenghts[j])
r = send_data(game,player_key,equality1)
print("sended 1")
options = remove_bads(options,r['result'][0],equality1,dic)
r = send_data(game,player_key,equality2)
print("sended 2")
equality=equality2
i=2
print(f"resolviendo: {game}")
while(not r['finished']):
options = remove_bads(options,r['result'][0],equality,dic)
equality = options[0]
r = send_data(game,player_key,equality)
i+=1
print(f"-->Juego: {j+1} resuelto en {i} intentos")
print(f"Solucion: {equality}")
data = {
'game': game,
'key': player_key
}
r = requests.post(f'{base_url}/api/reset/', data=data)
print("fin")
# my key:MUNO206
# for finding where is the equal >>> re.search("is", String).start()