-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.py
More file actions
77 lines (52 loc) · 1.13 KB
/
client.py
File metadata and controls
77 lines (52 loc) · 1.13 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
import socket
import sys
import os
def reference():
print 'Use board as reference. Enter position number for next move'
print "0|1|2"
print "3|4|5"
print "6|7|8\n"
def prettyprint(board):
curr = list(board)
for j in [0,3,6]:
for i in range(0,3):
if curr[i+j] is '0':
print ' ',
elif curr[i+j] is '1':
print 'x',
elif curr[i+j] is '2':
print 'o',
print '|',
print ''
def move(board):
prettyprint(board)
cur = list(board)
mymove = raw_input('Enter next move: ')
if mymove >=0 and mymove <=8:
if cur[int(mymove)] == '0':
cur[int(mymove)] = '1'
cur = ''.join(cur)
return cur
else:
print 'Invalid move'
move(board)
s = socket.socket()
try:
addr = ('192.168.1.133',8888)
s.connect(addr)
print 'Connected to Server'
except socket.error as msg:
print 'Error : ' + str(msg[0]) + ' Message ' + msg[1]
sys.exit()
board = '00000000000'
mymove = move(board)
s.sendall(mymove)
board = s.recv(50)
while 'END' not in board and 'WIN 1' not in board and 'WIN 2' :
os.system('clear')
reference()
mymove = move()
s.sendall(mymove)
board = s.recv(50)
if 'END' in board:
print board