Skip to content

Commit 622e940

Browse files
committed
fixing stuff
1 parent 5186db2 commit 622e940

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

client.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def place(self, turn):
7676
if turn == 'O':
7777
turn_enum = 2
7878
packet = int.to_bytes(turn_enum, 4, NET_ORDER) + user_coords[0].encode("utf-8") + user_coords[1].encode("utf-8")
79-
self.server_conn.sendall(int.to_bytes(handlers["handle_get_winner"], 4, NET_ORDER))
79+
self.server_conn.sendall(int.to_bytes(7, 4, NET_ORDER))
8080
self.server_conn.sendall(packet) #send which player, and coordinates
8181

8282
#expects a response that is a 9 byte string representing the board
@@ -88,14 +88,14 @@ def read_board(self):
8888
#print the board //TODO convert ascii code from stuff
8989
print(' 0 1 2')
9090
print(f'0 {response[0]} | {response[1]} | {response[2]}')
91-
print(' ----------------')
91+
print(' --------------')
9292
print(f'1 {response[3]} | {response[4]} | {response[5]}')
93-
print(' ----------------')
93+
print(' --------------')
9494
print(f'2 {response[6]} | {response[7]} | {response[8]}')
9595

9696
#expects 4 bytes repr. winner, 0 = no one, 1 = X, 2 = O
9797
def get_winner(self):
98-
self.server_conn.sendall(int.to_bytes(handlers["handle_get_winner"], 4, NET_ORDER))
98+
self.server_conn.sendall(int.to_bytes(9, 4, NET_ORDER))
9999
response = self.read_response()
100100
return int.from_bytes(response, NET_ORDER)
101101

@@ -112,7 +112,7 @@ def play(connect_tuple):
112112
time.sleep(1)
113113
#gameplay
114114
turn = 'X'
115-
while game.get_winner == 0:
115+
while game.get_winner() == 0:
116116
print('Player %s\'s')
117117
game.place(game, turn)
118118
print('Good move. I think...')
@@ -121,8 +121,8 @@ def play(connect_tuple):
121121
turn = turn == 'X' if turn == 'Y' else 'Y'
122122

123123
#game ended
124-
name = names[random(0, len(names))] # fingers crossed
125-
print('CONGRATS %s YOU WIN!', name)
124+
name = random.choice(names) # fingers crossed
125+
print('CONGRATS %s YOU WIN!' % name)
126126

127127

128128
def main():

tictactoe.c

+9-4
Original file line numberDiff line numberDiff line change
@@ -66,26 +66,31 @@ bool handle_read_board(int client_fd, char* client_str) {
6666
bool handle_get_winner(int client_fd, char* client_str) {
6767
//implement a more effecient check if needed
6868

69+
printf("entered get winner\n");
70+
6971
enum Player winner = E;
70-
71-
for (int i = 0; i < __BOARD_SIZE__; i++) {
72+
73+
for (int i = 0; i < 3; i++) {
7274
//check vertical lines
7375
if ((board[i][0] != E) && (board[i][0] == board[i][1]) && (board[i][0] == board[i][2]))
7476
winner = board[i][0];
75-
7677
// check horizontal lines
7778
if ((board[0][i] != E) && (board[0][i] == board[1][i]) && (board[0][i] == board[2][i]))
7879
winner = board[0][i];
7980
}
81+
printf("sdfadafa\n");
82+
8083
// check diagonals
8184
if ((board[0][0] != E) && (board[0][0] == board[1][1]) && (board[0][0] == board[2][2]))
8285
winner = board[0][0];
86+
printf("sdfadafa\n");
8387

8488
if ((board[2][0] != E) && (board[2][0] == board[1][1]) && (board[0][0] == board[0][2]))
8589
winner = board[2][0];
8690

8791
//send winner to client
88-
respond_str_to_client(client_fd, (char*)winner);
92+
93+
respond_buff_to_client(client_fd, winner, sizeof(E));
8994

9095
return true;//what to return for status?
9196

0 commit comments

Comments
 (0)