Esempio n. 1
0
    def test_is_vertical_wall_undo_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

                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)
                board.undo_wall(False, coord)

                self.assertTrue(
                    left1.neighbors[Ti.WEST] == neighbors_left1[Ti.WEST])
                self.assertTrue(
                    left2.neighbors[Ti.WEST] == neighbors_left2[Ti.WEST])
                self.assertTrue(
                    right1.neighbors[Ti.EAST] == neighbors_right1[Ti.EAST])
                self.assertTrue(
                    right2.neighbors[Ti.EAST] == neighbors_right2[Ti.EAST])
Esempio n. 2
0
    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)
Esempio n. 3
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)