Advertisement
Korotkodul

server_new

Sep 18th, 2022 (edited)
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.74 KB | None | 0 0
  1. import socket
  2. sock = socket.socket()
  3. sock.bind(('192.168.1.171',9995))
  4. sock.listen(3)
  5. A, addrA = sock.accept()
  6. B, addrB = sock.accept()
  7. A.send(b"x")
  8. B.send(b"0")
  9.  
  10. mtr = []
  11. for i in range(3):
  12.     m = ['a'] * 3
  13.     mtr.append(m)
  14.  
  15. def check():
  16.     for i in range(3):
  17.         if mtr[i][0] == mtr[i][1] == mtr[i][2]:
  18.             if mtr[i][0] == 'x':
  19.                 return 'x'
  20.             elif mtr[i][0] == '0':
  21.                 return '0'
  22.  
  23.     for j in range(3):
  24.         if mtr[0][j] == mtr[1][j] == mtr[2][j]:
  25.             if mtr[0][j] == 'x':
  26.                 return 'x'
  27.             elif mtr[0][j] == '0':
  28.                 return '0'
  29.  
  30.     if mtr[0][0] == mtr[1][1] == mtr[2][2]:
  31.         if mtr[0][0] == 'x':
  32.             return 'x'
  33.         elif mtr[0][0] == '0':
  34.             return '0'
  35.  
  36.     if mtr[0][2] == mtr[1][1] == mtr[2][0]:
  37.         if mtr[0][2] == 'x':
  38.             return 'x'
  39.         elif mtr[0][2] == '0':
  40.             return '0'
  41.  
  42.     draw = True
  43.     for i in range(3):
  44.         for j in range(3):
  45.             if mtr[i][j] == 'a':
  46.                 draw = False
  47.     if draw:
  48.         return 'draw'
  49.  
  50.     return 'a'
  51.  
  52. cnt=-1
  53. while check() == 'a':
  54.     cnt = (cnt + 1) % 2
  55.     mover = A
  56.     waiter = B
  57.     if cnt == 1:
  58.         mover = B
  59.         waiter = A
  60.         print("mover = B")
  61.         print("waiter = A")
  62.     else:
  63.         print("mover = A")
  64.         print("waiter = B")
  65.  
  66.     mover.send(b"move")
  67.     coord = mover.recv(1024)
  68.     waiter.send(coord)
  69.     col, row = coord.decode('utf-8').split()
  70.     col = int(col)
  71.     row = int(row)
  72.     print("col row = ", col, row, type(col), type(row))
  73.     if mover == A:
  74.         mtr[col][row] = 'x'
  75.     else:
  76.         mtr[col][row] = '0'
  77.     #break
  78.  
  79.  
  80.  
  81.  
  82.  
  83. A.close()
  84. B.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement