-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathPlay.py
More file actions
74 lines (62 loc) · 2.07 KB
/
Play.py
File metadata and controls
74 lines (62 loc) · 2.07 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
68
69
70
71
72
73
import requests
import json
import OthelloAction
import AuthCheck
import OthelloLogic
base_url = "http://tdu-othello.xyz/api/"
headers = AuthCheck.auth_check(base_url)
r = requests.post(base_url + "where", headers=headers)
if(r.status_code == 422):
message = r.json()
print(message['message'])
exit()
if(r.status_code != requests.codes.ok):
print('エラーが発生しました。')
exit()
data = r.json()
roomid = data['id']
player = data['player']
board = []
payload = {}
if(player == 1):
payload = {'player':player}
r = requests.post(base_url + "wait_for_player/" + roomid, data=payload,headers=headers)
data = r.json()
OthelloLogic.printBoard(json.loads(data['board']))
board = json.loads(data['board'])
moves = json.loads(data['moves'])
else:
OthelloLogic.printBoard(json.loads(data['board']))
rev_board = json.loads(data['board'])
board = json.loads(data['board'])
for x in range(len(rev_board)):
for y in range(len(rev_board)):
board[x][y] = rev_board[x][y] * -1
moves = json.loads(data['moves'])
action = json.dumps(OthelloAction.getAction(board,moves))
payload = {'action' : action,'player':player}
while(True):
print("打った場所は" + action)
r = requests.post(base_url + "room/" + roomid, data=payload,headers=headers)
if(r.status_code == 401):
print('認証エラーが起きました。')
exit()
if(r.status_code != requests.codes.ok):
print('エラーが発生しました。')
exit()
data = r.json()
if(data['finish_flag']):
print('処理が終了しました。')
exit()
OthelloLogic.printBoard(json.loads(data['board']))
if(player == -1):
rev_board = json.loads(data['board'])
board = json.loads(data['board'])
for x in range(len(rev_board)):
for y in range(len(rev_board)):
board[x][y] = rev_board[x][y] * -1
else:
board = json.loads(data['board'])
moves = json.loads(data['moves'])
action = json.dumps(OthelloAction.getAction(board,moves))
payload = {'action' : action,'player':player}