Files
pyDefis/Balade sur un échiquier.py
Francois JUMELLE 20526d93c8 Initial release
2021-05-03 22:32:40 +02:00

49 lines
1.1 KiB
Python

import requests
GET = "https://pydefis.callicode.fr/defis/BaladeEchiquier/get/Cavogrenier/4e9be"
POST = "https://pydefis.callicode.fr/defis/BaladeEchiquier/post/Cavogrenier/4e9be"
res = requests.get(GET)
contents = res.text.splitlines()
print(res.text)
print("***")
sig = contents[0]
input = contents[1]
direction = 0 #0 = N, E = 1, S = 2, O = 3
cases = {"A1":""}
pos = (1,1)
for c in input:
print(c, end=" ==> ")
if c == "A":
if direction == 0:
pos = (pos[0], pos[1]+1)
elif direction == 1:
pos = (pos[0]+1, pos[1])
elif direction == 2:
pos = (pos[0], pos[1]-1)
else:
pos = (pos[0]-1, pos[1])
elif c == "D":
direction = (direction+1)%4
elif c == "G":
direction = (direction-1)%4
else:
raise ValueError("incorect char in input")
print(chr(pos[0]+ord('A')-1)+str(pos[1]))
cases[chr(pos[0]+ord('A')-1)+str(pos[1])] = ""
solution = str(len(cases))+chr(pos[0]+ord('A')-1)+str(pos[1])
print("solution:", solution)
param = {'sig':sig, 'rep':solution}
res = requests.post(POST, verify=False, data=param)
print(res)
print(res.text)