コード例 #1
0
    def test_apply_move_on_taken_field(self):
        size = 3
        board = clean_board(size)
        position = (0, 0)

        apply_move_inplace(board, position, 1)
        self.assertRaises(ValueError, apply_move, board, position, -1)
コード例 #2
0
    def test_apply_move_inplace_on_empty_field(self):
        size = 3
        board = clean_board(size)
        position = (0, 0)

        apply_move_inplace(board, position, 1)

        self.assertEqual(board[position], 1)
コード例 #3
0
    def test_available_moves(self):
        size = 3
        board = clean_board(size)

        self.assertEqual(len(available_moves(board)), 9)

        apply_move_inplace(board, (0, 0), 1)
        self.assertEqual(len(available_moves(board)), 8)

        board = np.ones((size, size), dtype=np.int)
        self.assertEqual(len(available_moves(board)), 0)
コード例 #4
0
    def test_determine_board_winner_on_winning_diagonal(self):
        size = 3
        winning_length = 3
        board = clean_board(size)
        side = -1

        apply_move_inplace(board, (0, 0), side)
        apply_move_inplace(board, (1, 1), side)
        apply_move_inplace(board, (2, 2), side)

        self.assertEqual(determine_board_winner(board, winning_length), side)
コード例 #5
0
    def test_is_line_winning_on_winning_line(self):
        size = 3
        winning_length = 3
        board = clean_board(size)
        side = -1

        apply_move_inplace(board, (0, 0), side)
        apply_move_inplace(board, (0, 1), side)
        apply_move_inplace(board, (0, 2), side)

        self.assertTrue(determine_line_winner(board[0, :], winning_length))
        self.assertEqual(determine_line_winner(board[0, :], winning_length),
                         side)
コード例 #6
0
    def test_is_diagonal_winning_on_winning_diagonal(self):
        size = 3
        winning_length = 3
        board = clean_board(size)
        side = -1

        apply_move_inplace(board, (0, 0), side)
        apply_move_inplace(board, (1, 1), side)
        apply_move_inplace(board, (2, 2), side)
        diagonals = diagonals_of_the_board_longer_equals_winning_length(
            board, 3)

        self.assertTrue(determine_line_winner(diagonals[1], winning_length))
        self.assertEqual(determine_line_winner(diagonals[1], winning_length),
                         side)