Пример #1
0
    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)
Пример #2
0
    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)
Пример #3
0
    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)))