コード例 #1
0
ファイル: EngineTester.py プロジェクト: IO141/QuorridorBot
 def test_sanity_is_board_tile_obj_identical(self):
     board = Board(10)
     tile = board.tile_at_coord(1, 2)
     self.assertEqual(tile, board.board[1][2])
     tile.occupant = 1
     self.assertEqual(tile, board.board[1][2])
     self.assertTrue(tile.occupant == board.board[1][2].occupant)
コード例 #2
0
ファイル: EngineTester.py プロジェクト: IO141/QuorridorBot
 def test_is_tile_coord_correct(self):
     board = Board(BoardTestCase.std_dim)
     coord = Coordinate(1, 2)
     tile12 = board.tile_at_coord(1, 2)
     self.assertTrue(isinstance(tile12, Tile))
     self.assertTrue(coord.row == tile12.coordinate.row
                     and coord.column == tile12.coordinate.column)
コード例 #3
0
ファイル: EngineTester.py プロジェクト: IO141/QuorridorBot
 def test_is_homes_correct(self):
     board = Board(BoardTestCase.std_dim)
     homes = board._compute_player_homes()
     check = [
         Coordinate(0, BoardTestCase.std_dim // 2),
         Coordinate(BoardTestCase.std_dim - 1, BoardTestCase.std_dim // 2),
         Coordinate(BoardTestCase.std_dim // 2, 0),
         Coordinate(BoardTestCase.std_dim // 2, BoardTestCase.std_dim - 1)
     ]
     self.assertTrue(homes == check)
コード例 #4
0
ファイル: EngineTester.py プロジェクト: IO141/QuorridorBot
    def test_is_vertical_wall_place_correct(self):
        board = Board(BoardTestCase.std_dim)
        self.assertRaises(ValueError, board.place_wall, False,
                          Coordinate(1, 0))  # Bad coord except check

        for i in range(board.dimensions):
            for j in range(board.dimensions):
                coord = Coordinate(i, j)

                if not board._compute_static_valid_wall(False, coord):
                    continue

                self.assertTrue(board._compute_dynamic_valid_wall(
                    False, coord))

                left1 = board.board[coord.row][coord.column - 1]
                left2 = board.board[coord.row + 1][coord.column - 1]
                right1 = board.board[coord.row][coord.column]
                right2 = board.board[coord.row + 1][coord.column]

                neighbors_left1 = copy.deepcopy(left1.neighbors)
                neighbors_left2 = copy.deepcopy(left2.neighbors)
                neighbors_right1 = copy.deepcopy(right1.neighbors)
                neighbors_right2 = copy.deepcopy(right2.neighbors)

                board.place_wall(False, coord)

                self.assertTrue(left1.neighbors[Ti.WEST] is None)
                self.assertTrue(
                    left1.neighbors[Ti.EAST] == neighbors_left1[Ti.EAST])
                self.assertTrue(
                    left1.neighbors[Ti.NORTH] == neighbors_left1[Ti.NORTH])
                self.assertTrue(
                    left1.neighbors[Ti.SOUTH] == neighbors_left1[Ti.SOUTH])

                self.assertTrue(left2.neighbors[Ti.WEST] is None)
                self.assertTrue(
                    left2.neighbors[Ti.EAST] == neighbors_left2[Ti.EAST])
                self.assertTrue(
                    left2.neighbors[Ti.NORTH] == neighbors_left2[Ti.NORTH])
                self.assertTrue(
                    left2.neighbors[Ti.SOUTH] == neighbors_left2[Ti.SOUTH])

                self.assertTrue(right1.neighbors[Ti.EAST] is None)
                self.assertTrue(
                    right1.neighbors[Ti.WEST] == neighbors_right1[Ti.WEST])
                self.assertTrue(
                    right1.neighbors[Ti.NORTH] == neighbors_right1[Ti.NORTH])
                self.assertTrue(
                    right1.neighbors[Ti.SOUTH] == neighbors_right1[Ti.SOUTH])

                self.assertTrue(right2.neighbors[Ti.EAST] is None)
                self.assertTrue(
                    right2.neighbors[Ti.WEST] == neighbors_right2[Ti.WEST])
                self.assertTrue(
                    right2.neighbors[Ti.NORTH] == neighbors_right2[Ti.NORTH])
                self.assertTrue(
                    right2.neighbors[Ti.SOUTH] == neighbors_right2[Ti.SOUTH])

                board.undo_wall(False, coord)
コード例 #5
0
ファイル: EngineTester.py プロジェクト: IO141/QuorridorBot
    def test_is_horizontal_wall_place_correct(self):
        board = Board(BoardTestCase.std_dim)
        self.assertRaises(ValueError, board.place_wall, True,
                          Coordinate(0, 2))  # Bad coord except check

        for i in range(board.dimensions):
            for j in range(board.dimensions):
                coord = Coordinate(i, j)

                if not board._compute_static_valid_wall(True, coord):
                    continue

                self.assertTrue(board._compute_dynamic_valid_wall(True, coord))

                top1 = board.board[coord.row - 1][coord.column]
                top2 = board.board[coord.row - 1][coord.column + 1]
                bottom1 = board.board[coord.row][coord.column]
                bottom2 = board.board[coord.row][coord.column + 1]

                neighbors_top1 = copy.deepcopy(top1.neighbors)
                neighbors_top2 = copy.deepcopy(top2.neighbors)
                neighbors_bottom1 = copy.deepcopy(bottom1.neighbors)
                neighbors_bottom2 = copy.deepcopy(bottom2.neighbors)

                board.place_wall(True, coord)

                self.assertTrue(top1.neighbors[Ti.SOUTH] is None)
                self.assertTrue(
                    top1.neighbors[Ti.NORTH] == neighbors_top1[Ti.NORTH])
                self.assertTrue(
                    top1.neighbors[Ti.EAST] == neighbors_top1[Ti.EAST])
                self.assertTrue(
                    top1.neighbors[Ti.WEST] == neighbors_top1[Ti.WEST])

                self.assertTrue(top2.neighbors[Ti.SOUTH] is None)
                self.assertTrue(
                    top2.neighbors[Ti.NORTH] == neighbors_top2[Ti.NORTH])
                self.assertTrue(
                    top2.neighbors[Ti.EAST] == neighbors_top2[Ti.EAST])
                self.assertTrue(
                    top2.neighbors[Ti.WEST] == neighbors_top2[Ti.WEST])

                self.assertTrue(bottom1.neighbors[Ti.NORTH] is None)
                self.assertTrue(
                    bottom1.neighbors[Ti.SOUTH] == neighbors_bottom1[Ti.SOUTH])
                self.assertTrue(
                    bottom1.neighbors[Ti.EAST] == neighbors_bottom1[Ti.EAST])
                self.assertTrue(
                    bottom1.neighbors[Ti.WEST] == neighbors_bottom1[Ti.WEST])

                self.assertTrue(bottom2.neighbors[Ti.NORTH] is None)
                self.assertTrue(
                    bottom2.neighbors[Ti.SOUTH] == neighbors_bottom2[Ti.SOUTH])
                self.assertTrue(
                    bottom2.neighbors[Ti.EAST] == neighbors_bottom2[Ti.EAST])
                self.assertTrue(
                    bottom2.neighbors[Ti.WEST] == neighbors_bottom2[Ti.WEST])

                board.undo_wall(True, coord)
コード例 #6
0
ファイル: EngineTester.py プロジェクト: IO141/QuorridorBot
 def test_is_board_tiles_init(self):
     board = Board(BoardTestCase.std_dim)
     self.assertTrue(board._dimensions == BoardTestCase.std_dim)
     self.assertTrue(
         sum(len(t) for t in board.board) == BoardTestCase.std_dim**2)
     self.assertTrue(
         all([(isinstance(t.coordinate, Coordinate) or t.coordinate is None)
              for t in tc] for tc in board.board))
コード例 #7
0
ファイル: EngineTester.py プロジェクト: IO141/QuorridorBot
 def test_is_players_home_correct(self):
     board = Board(BoardTestCase.std_dim)
     homes = [
         Coordinate(0, BoardTestCase.std_dim // 2),
         Coordinate(BoardTestCase.std_dim - 1, BoardTestCase.std_dim // 2),
         Coordinate(BoardTestCase.std_dim // 2, 0),
         Coordinate(BoardTestCase.std_dim // 2, BoardTestCase.std_dim - 1)
     ]
     self.assertTrue(homes == board.players)
コード例 #8
0
ファイル: EngineTester.py プロジェクト: IO141/QuorridorBot
    def test_is_dim_correct(self):
        # dim should correct to 10
        dim = 9
        board = Board(dim)
        self.assertFalse(board.dimensions == dim)
        self.assertTrue(board.dimensions == 10)

        # dim should correct to 10
        dim = 5
        board = Board(dim)
        self.assertFalse(board.dimensions == dim)
        self.assertTrue(board.dimensions == 10)

        # dim should correct to 12
        dim = 11
        board = Board(dim)
        self.assertFalse(board.dimensions == dim)
        self.assertTrue(board.dimensions == 12)

        # dim should stay at 14
        dim = 14
        board = Board(dim)
        self.assertTrue(board.dimensions == dim)
コード例 #9
0
ファイル: EngineTester.py プロジェクト: IO141/QuorridorBot
    def test_is_dynamic_valid_walls_correct(self):
        board = Board(BoardTestCase.std_dim)

        self.assertTrue(
            board._compute_dynamic_valid_wall(True, Coordinate(2, 2)))
        self.assertTrue(
            board._compute_dynamic_valid_wall(False, Coordinate(5, 5)))

        board.place_wall(True, Coordinate(2, 2))
        self.assertFalse(
            board._compute_dynamic_valid_wall(True, Coordinate(2, 2)))
        self.assertFalse(
            board._compute_dynamic_valid_wall(True, Coordinate(2, 3)))
        self.assertFalse(
            board._compute_dynamic_valid_wall(True, Coordinate(2, 1)))
        self.assertTrue(
            board._compute_dynamic_valid_wall(True, Coordinate(2, 0)))
        self.assertTrue(
            board._compute_dynamic_valid_wall(True, Coordinate(2, 4)))

        board.place_wall(False, Coordinate(5, 5))
        self.assertFalse(
            board._compute_dynamic_valid_wall(False, Coordinate(5, 5)))
        self.assertFalse(
            board._compute_dynamic_valid_wall(False, Coordinate(6, 5)))
        self.assertFalse(
            board._compute_dynamic_valid_wall(False, Coordinate(4, 5)))
        self.assertTrue(
            board._compute_dynamic_valid_wall(False, Coordinate(3, 5)))
        self.assertTrue(
            board._compute_dynamic_valid_wall(False, Coordinate(7, 5)))
コード例 #10
0
ファイル: EngineTester.py プロジェクト: IO141/QuorridorBot
    def test_is_static_valid_walls_correct(self):
        board = Board(BoardTestCase.std_dim)

        # Horizontal checks
        self.assertFalse(
            board._compute_static_valid_wall(True,
                                             Coordinate(0,
                                                        2)))  # Bad lower row
        self.assertFalse(
            board._compute_static_valid_wall(True, Coordinate(
                2, -1)))  # Bad lower column
        self.assertFalse(
            board._compute_static_valid_wall(
                True, Coordinate(BoardTestCase.std_dim - 1,
                                 2)))  # Bad upper row
        self.assertFalse(
            board._compute_static_valid_wall(
                True,
                Coordinate(2, BoardTestCase.std_dim - 2)))  # Bad upper column

        self.assertTrue(
            board._compute_static_valid_wall(True,
                                             Coordinate(1,
                                                        2)))  # Good lower row
        self.assertTrue(
            board._compute_static_valid_wall(True, Coordinate(
                2, 0)))  # Good lower column
        self.assertTrue(
            board._compute_static_valid_wall(
                True, Coordinate(BoardTestCase.std_dim - 2,
                                 2)))  # Good upper row
        self.assertTrue(
            board._compute_static_valid_wall(
                True,
                Coordinate(2, BoardTestCase.std_dim - 3)))  # Good upper column

        # Vertical checks
        self.assertFalse(
            board._compute_static_valid_wall(False,
                                             Coordinate(-1,
                                                        1)))  # Bad lower row
        self.assertFalse(
            board._compute_static_valid_wall(False, Coordinate(
                1, 0)))  # Bad lower column
        self.assertFalse(
            board._compute_static_valid_wall(
                False, Coordinate(BoardTestCase.std_dim - 2,
                                  3)))  # Bad upper row
        self.assertFalse(
            board._compute_static_valid_wall(
                False,
                Coordinate(3, BoardTestCase.std_dim - 1)))  # Bad upper column

        self.assertTrue(
            board._compute_static_valid_wall(False,
                                             Coordinate(0,
                                                        1)))  # Good lower row
        self.assertTrue(
            board._compute_static_valid_wall(False, Coordinate(
                1, 1)))  # Good lower column
        self.assertTrue(
            board._compute_static_valid_wall(
                False, Coordinate(BoardTestCase.std_dim - 3,
                                  3)))  # Good upper row
        self.assertTrue(
            board._compute_static_valid_wall(
                False,
                Coordinate(3, BoardTestCase.std_dim - 2)))  # Good upper column
コード例 #11
0
ファイル: EngineTester.py プロジェクト: IO141/QuorridorBot
    def test_board_equality(self):
        board1 = Board(10)
        board2 = Board(10)

        self.assertTrue(board1 == board2)

        board2._dimensions = 3
        self.assertFalse(board1 == board2)
        board2._dimensions = board1._dimensions
        self.assertTrue(board1 == board2)

        board2._homes[0] = None
        self.assertFalse(board1 == board2)
        board2._homes[0] = board1._homes[0]
        self.assertTrue(board1 == board2)

        board2._players[0] = None
        self.assertFalse(board1 == board2)
        board2._players[0] = board1._players[0]
        self.assertTrue(board1 == board2)

        board2.place_wall(True, Coordinate(5, 5))
        self.assertFalse(board1 == board2)
        board2.undo_wall(True, Coordinate(5, 5))
        self.assertTrue(board1 == board2)