@@ -41,6 +41,33 @@ def get_version(self):
41
41
self .server_conn .sendall (TicTacToe .GET_VERSION_PKT )
42
42
return self .read_response ()
43
43
44
+ #caller guarantees turn is a single char, X or O
45
+ def place (self , turn ):
46
+ user_coords = input ("Please enter the coordinates you want to mark, eg: 0 0" ).split ()
47
+ while len (user_coords ) != 2 :
48
+ input = ("You made me almost seg fault! Give me two coordinates!" )
49
+
50
+ packet = turn + user_coords [0 ] + user_coords [1 ]
51
+ self .server_conn .send (packet ) #send which player, and coordinates
52
+
53
+ #expects a response that is a 9 byte string representing the board
54
+ def read_board (self ):
55
+ response = self .read_response (self )
56
+
57
+ #print the board
58
+ print (' 0 1 2' )
59
+ print ('0 %s | %s | %s' , response [0 ], response [1 ], response [2 ])
60
+ print (' ----------------' )
61
+ print ('1 %s | %s | %s' , response [4 ], response [5 ], response [6 ])
62
+ print (' ----------------' )
63
+ print ('2 %s | %s | %s' , response [7 ], response [8 ], response [9 ])
64
+
65
+ #expects 4 bytes repr. winner
66
+ def get_winner (self ):
67
+ response = self .read_response (self )
68
+
69
+
70
+
44
71
def play (connect_tuple ):
45
72
game = TicTacToe (connect_tuple )
46
73
print ("connecting" )
@@ -49,7 +76,6 @@ def play(connect_tuple):
49
76
print (game .get_version ())
50
77
51
78
52
-
53
79
def main ():
54
80
if len (sys .argv ) != 3 :
55
81
print ("Need <tictactoe host ip> <tictactoe host port>" )
0 commit comments