1
1
import sys
2
2
import socket
3
+ import time
4
+ import random
5
+
6
+ names = ['Mav' , 'Adam' , 'Teddy' , 'Ari' , 'Donovan' , 'Diana' ,
7
+ 'Eduardo' , 'Emanuel' , 'Nourya' , 'Ron' , 'Tobias' , 'Vrushank' ]
3
8
4
9
def client_error_wrapper (error_msg ):
5
10
print ("*" * len (str (error_msg )))
@@ -47,12 +52,15 @@ def place(self, turn):
47
52
while len (user_coords ) != 2 :
48
53
input = ("You made me almost seg fault! Give me two coordinates!" )
49
54
50
- packet = turn + user_coords [0 ] + user_coords [1 ]
51
- self .server_conn .send (packet ) #send which player, and coordinates
55
+ turn_enum = 1
56
+ if turn == 'O' :
57
+ turn_enum = 2
58
+ packet = turn .encode ("utf-8" ) + user_coords [0 ].encode ("utf-8" ) + user_coords [1 ].encode ("utf-8" )
59
+ self .server_conn .sendall (packet ) #send which player, and coordinates
52
60
53
61
#expects a response that is a 9 byte string representing the board
54
62
def read_board (self ):
55
- response = self .read_response (self )
63
+ response = self .read_response ()
56
64
57
65
#print the board
58
66
print (' 0 1 2' )
@@ -64,10 +72,8 @@ def read_board(self):
64
72
65
73
#expects 4 bytes repr. winner, 0 = no one, 1 = X, 2 = O
66
74
def get_winner (self ):
67
- response = self .read_response (self )
68
- return int .from_bytes (response ) == 0
69
-
70
-
75
+ response = self .read_response ()
76
+ return int .from_bytes (response , NET_ORDER )
71
77
72
78
def play (connect_tuple ):
73
79
game = TicTacToe (connect_tuple )
@@ -76,6 +82,23 @@ def play(connect_tuple):
76
82
print ("connected" )
77
83
print (game .get_version ())
78
84
85
+ print ("WELCOME TO ZERO TICTACTOE. 100% VULNERABILITY-FREE CODE GUARANTEED" )
86
+ game .read_board ()
87
+
88
+ #gameplay
89
+ turn = 'X'
90
+ while game .get_winner == 0 :
91
+ print ('Player %s\' s' )
92
+ game .place (game , turn )
93
+ print ('Good move. I think...' )
94
+ time .sleep (1 )
95
+ game .read_board ()
96
+ turn = turn == 'X' if turn == 'Y' else 'Y'
97
+
98
+ #game ended
99
+ name = names [random (0 , len (names ))] # fingers crossed
100
+ print ('CONGRATS %s YOU WIN!' , name )
101
+
79
102
80
103
def main ():
81
104
if len (sys .argv ) != 3 :
0 commit comments