-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmiddle.py
64 lines (53 loc) · 1.49 KB
/
middle.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
import requests
last1x, last1y = 1, 1
last2x, last2y = 15, 15
def mov(m, p):
global last1x, last1y, last2x, last2y
for i in range(15):
for j in range(15):
if (((last1x == i) and (last1y == j)) or ((last2x == i) and (last2y == j))):
continue
else:
board[i][j] = board[i][j].lower()
x, y = m.split('|')
x = int(x) -1
y = int(y) -1
if p == 'O':
last1x, last1y = x, y
elif p == 'J':
last2x, last2y = x, y
board[x][y] = p
def printboard(board):
for row in board:
for square in row:
print(square, end=' ')
print('')
player1 = 'http://127.0.0.1:9000/'
player2 = 'http://127.0.0.1:3000/'
board = [['_' for i in range(15)] for j in range(15)]
print("player1 pinged", requests.get(player1 + 'ping').json())
print("player2 pinged", requests.get(player2 + 'ping').json())
print("player1 start", requests.get(player1 + 'start?y=1|1&o=15|15&g=15').json())
print("player2 start", requests.get(player2 + 'start?y=15|15&o=1|1&g=15').json())
mov("1|1", 'O')
move = "15|15"
while(True):
print("player2", move)
mov(move, 'J')
printboard(board)
if(last1x == last2x) and (last1y == last2y):
print("player 2 wins")
break
# send move to player1
move = requests.get(player1 + 'play?m=' + move).json()["m"]
print("player1", move)
mov(move, 'O')
printboard(board)
if(last1x == last2x) and (last1y == last2y):
print("player 1 wins")
break
# send move to player2
move = requests.get(player2 + 'play?m=' + move).json()["m"]
#response = requests.get(url)
#data = response.json()
#print(data)