def test_play_match(self): server = Server() server.start(False) client1 = Client('localhost', 8081) client2 = Client('localhost', 8081) client1_moves = [(1, 1), (2, 2), (3, 3)] client2_moves = [(3, 1), (3, 2)] client1.on_move_required = lambda ct: (client1_moves if ct else client2_moves).pop(0) client1.on_game_over = lambda winner: self.assertTrue(winner) client2.on_move_required = lambda ct: (client1_moves if ct else client2_moves).pop(0) client2.on_game_over = lambda winner: self.assertTrue(winner) client1.start(False) client2.start(False) client1.wait() client2.wait() server.stop()
for i in range(len(field)): for j in range(len(field)): if field[i][j] is None: valid.append((j + 1, i + 1)) print(field, 'field') print(valid, 'valid') move = random.choice(valid) return move def make_move(crosses_turn): global field move = get_next_move(field) logging.info(move) return move def game_over(crosses_won): if crosses_won is None: print('Draw') else: print('Winner:', 'crosses' if crosses_won else 'noughts') client = Client(args.host, args.port) client.on_field_received = save_field client.on_move_required = make_move client.on_game_over = game_over client.start()