예제 #1
0
 def test_check_winner_right_left_diag(self):
     winning_board = TicTacToeModel()
     winning_board.current_player = 0
     winning_board.num_moves = 6
     winning_board.board = [[0, None, 0], [1, 0, 1], [0, None, 1]]
     self.assertTrue(winning_board.check_winner((0, 2)))
     self.assertTrue(winning_board.check_winner((1, 1)))
     self.assertTrue(winning_board.check_winner((2, 0)))
예제 #2
0
 def test_check_winner_row_2(self):
     winning_board = TicTacToeModel()
     winning_board.current_player = 1
     winning_board.num_moves = 7
     winning_board.board = [[None, None, None], [1, 1, None], [0, 0, 0]]
     self.assertTrue(winning_board.check_winner((2, 0)))
     self.assertTrue(winning_board.check_winner((2, 1)))
     self.assertTrue(winning_board.check_winner((2, 2)))
예제 #3
0
 def test_check_winner_column_2(self):
     winning_board = TicTacToeModel()
     winning_board.current_player = 0
     winning_board.num_moves = 6
     winning_board.board = [[0, 0, 1], [None, 0, 1], [None, None, 1]]
     self.assertTrue(winning_board.check_winner((0, 2)))
     self.assertTrue(winning_board.check_winner((1, 2)))
     self.assertTrue(winning_board.check_winner((2, 2)))
예제 #4
0
 def test_check_winner_column_1(self):
     winning_board = TicTacToeModel()
     winning_board.current_player = 1
     winning_board.num_moves = 5
     winning_board.board = [[1, 0, 1], [None, 0, None], [None, 0, None]]
     self.assertTrue(winning_board.check_winner((0, 1)))
     self.assertTrue(winning_board.check_winner((1, 1)))
     self.assertTrue(winning_board.check_winner((2, 1)))
예제 #5
0
 def test_check_winner_column_0(self):
     winning_board = TicTacToeModel()
     winning_board.current_player = 0
     winning_board.num_moves = 8
     winning_board.board = [[1, None, 0], [1, 0, 0], [1, 0, 1]]
     self.assertTrue(winning_board.check_winner((0, 0)))
     self.assertTrue(winning_board.check_winner((1, 0)))
     self.assertTrue(winning_board.check_winner((2, 0)))
예제 #6
0
 def test_check_winner_right_left_diag_size_5(self):
     winning_board = TicTacToeModel(5)
     winning_board.current_player = 1
     winning_board.num_moves = 18
     winning_board.board = [[0, 0, 0, None, 1], [0, 0, 0, 1, 1],
                            [0, 0, 1, None, 1], [0, 1, None, None, 1],
                            [1, None, None, None, 1]]
     self.assertTrue(winning_board.check_winner((4, 0)))
     self.assertTrue(winning_board.check_winner((3, 1)))
     self.assertTrue(winning_board.check_winner((2, 2)))
     self.assertTrue(winning_board.check_winner((1, 3)))
     self.assertTrue(winning_board.check_winner((0, 4)))
예제 #7
0
 def test_check_winner_column_3_size_5(self):
     winning_board = TicTacToeModel(5)
     winning_board.current_player = 1
     winning_board.num_moves = 19
     winning_board.board = [[1, 0, 1, 0, None], [1, 0, 1, 0, None],
                            [1, 0, 1, 0, None], [1, 0, 1, 0, None],
                            [0, 1, None, 0, None]]
     self.assertTrue(winning_board.check_winner((0, 3)))
     self.assertTrue(winning_board.check_winner((1, 3)))
     self.assertTrue(winning_board.check_winner((2, 3)))
     self.assertTrue(winning_board.check_winner((3, 3)))
     self.assertTrue(winning_board.check_winner((4, 3)))
예제 #8
0
 def test_check_winner_column_2_size_5(self):
     winning_board = TicTacToeModel(5)
     winning_board.current_player = 0
     winning_board.num_moves = 9
     winning_board.board = [[0, 0, 1, None, None], [0, 0, 1, None, 1],
                            [0, 0, 1, 1, None], [0, None, 1, None, None],
                            [None, None, 1, None, None]]
     self.assertTrue(winning_board.check_winner((0, 2)))
     self.assertTrue(winning_board.check_winner((1, 2)))
     self.assertTrue(winning_board.check_winner((2, 2)))
     self.assertTrue(winning_board.check_winner((3, 2)))
     self.assertTrue(winning_board.check_winner((4, 2)))
예제 #9
0
 def test_check_winner_row_4_size_5(self):
     winning_board = TicTacToeModel(5)
     winning_board.current_player = 0
     winning_board.num_moves = 10
     winning_board.board = [[None, 0, 0, None, None],
                            [None, 0, 0, None, None],
                            [None, 0, None, None, None],
                            [None, None, None, None, None], [1, 1, 1, 1, 1]]
     self.assertTrue(winning_board.check_winner((4, 0)))
     self.assertTrue(winning_board.check_winner((4, 1)))
     self.assertTrue(winning_board.check_winner((4, 2)))
     self.assertTrue(winning_board.check_winner((4, 3)))
     self.assertTrue(winning_board.check_winner((4, 4)))
예제 #10
0
 def test_check_winner_column_4_size_5(self):
     winning_board = TicTacToeModel(5)
     winning_board.current_player = 0
     winning_board.num_moves = 10
     winning_board.board = [[None, 0, 0, None, 1], [None, 0, None, None, 1],
                            [None, 0, None, None, 1],
                            [None, 0, None, None, 1],
                            [None, None, None, None, 1]]
     self.assertTrue(winning_board.check_winner((0, 4)))
     self.assertTrue(winning_board.check_winner((1, 4)))
     self.assertTrue(winning_board.check_winner((2, 4)))
     self.assertTrue(winning_board.check_winner((3, 4)))
     self.assertTrue(winning_board.check_winner((4, 4)))
예제 #11
0
 def test_check_no_winner_size_5(self):
     not_winning_board = TicTacToeModel(5)
     not_winning_board.current_player = 0
     not_winning_board.num_moves = 16
     not_winning_board.board = [[1, None, 1, 0, 1], [1, 0, 0, None, None],
                                [1, 0, 0, None,
                                 None], [1, 0, 0, None, None],
                                [0, 1, 1, None, None]]
     self.assertFalse(not_winning_board.check_winner((0, 0)))
     self.assertFalse(not_winning_board.check_winner((1, 0)))
     self.assertFalse(not_winning_board.check_winner((4, 0)))
     self.assertFalse(not_winning_board.check_winner((2, 2)))
     self.assertFalse(not_winning_board.check_winner((4, 2)))
def move():
    board_size = int(request.form.get('board_size'))
    player = int(request.form.get('player'))
    num_moves = int(request.form.get('num_moves'))
    board = [[None for x in range(board_size)] for y in range(board_size)]
    remaining_moves = {(x, y)
                       for x in range(board_size) for y in range(board_size)}
    for x in range(board_size):
        for y in range(board_size):
            spot = request.form.get(str((x, y)), None)
            if spot is not None:
                board[x][y] = int(spot)
                remaining_moves.remove((x, y))

    model = TicTacToeModel(board_size)
    model.current_player = player
    model.num_moves = num_moves
    model.board = board
    model.remaining_moves = remaining_moves

    response = str(get_next_move(player, model))
    print(model)
    print(response)
    return response