Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import socket
- sock = socket.socket()
- sock.bind(('192.168.1.171',9995))
- sock.listen(3)
- A, addrA = sock.accept()
- B, addrB = sock.accept()
- A.send(b"x")
- B.send(b"0")
- mtr = []
- for i in range(3):
- m = ['a'] * 3
- mtr.append(m)
- def check():
- for i in range(3):
- if mtr[i][0] == mtr[i][1] == mtr[i][2]:
- if mtr[i][0] == 'x':
- return 'x'
- elif mtr[i][0] == '0':
- return '0'
- for j in range(3):
- if mtr[0][j] == mtr[1][j] == mtr[2][j]:
- if mtr[0][j] == 'x':
- return 'x'
- elif mtr[0][j] == '0':
- return '0'
- if mtr[0][0] == mtr[1][1] == mtr[2][2]:
- if mtr[0][0] == 'x':
- return 'x'
- elif mtr[0][0] == '0':
- return '0'
- if mtr[0][2] == mtr[1][1] == mtr[2][0]:
- if mtr[0][2] == 'x':
- return 'x'
- elif mtr[0][2] == '0':
- return '0'
- draw = True
- for i in range(3):
- for j in range(3):
- if mtr[i][j] == 'a':
- draw = False
- if draw:
- return 'draw'
- return 'a'
- cnt=-1
- while check() == 'a':
- cnt = (cnt + 1) % 2
- mover = A
- waiter = B
- if cnt == 1:
- mover = B
- waiter = A
- print("mover = B")
- print("waiter = A")
- else:
- print("mover = A")
- print("waiter = B")
- mover.send(b"move")
- coord = mover.recv(1024)
- waiter.send(coord)
- col, row = coord.decode('utf-8').split()
- col = int(col)
- row = int(row)
- print("col row = ", col, row, type(col), type(row))
- if mover == A:
- mtr[col][row] = 'x'
- else:
- mtr[col][row] = '0'
- #break
- A.close()
- B.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement