def test_is_eq_correct(self): neighbors1 = [Coordinate(1, 2), None, None, None] tile1 = Tile(coordinate=Coordinate(1, 2)) tile2 = Tile(coordinate=Coordinate(1, 2)) tile3 = Tile(coordinate=Coordinate(1, 3)) tile4 = Tile(coordinate=Coordinate(1, 2), neighbors=neighbors1) self.assertTrue(tile1 == tile2) self.assertFalse(tile1 == tile3) self.assertFalse(tile3 == tile4)
def test_is_end_occupancy_correct(self): coord = Coordinate(1, 2) tile1 = Tile(coordinate=coord) tile1.occupant = 1 Tile.end_occupancy(tile1) self.assertTrue(tile1.occupant == -1)
def test_is_occupant_correct(self): coord = Coordinate(1, 2) tile1 = Tile(coordinate=coord) self.assertTrue(tile1.occupant == -1)
def test_is_neighbors_correct_input2(self): coord = Coordinate(1, 2) neighbors2 = [coord, None, None, None] tile1 = Tile(coordinate=coord) tile2 = Tile(coordinate=coord, neighbors=neighbors2) self.assertTrue(tile2.neighbors[0] == tile1.coordinate)
def test_is_neighbors_correct_input1(self): coord = Coordinate(1, 2) neighbors = [None, None, None, None] tile1 = Tile(coordinate=coord) self.assertTrue(tile1.neighbors == neighbors) self.assertTrue(tile1.coordinate == coord)
def test_is_coordinate_correct(self): coord = Coordinate(1, 2) tile1 = Tile(coordinate=coord) self.assertTrue(tile1.coordinate == coord)
def test_is_remove_neighbors_correct(): coord = Coordinate(1, 2) neighbors1 = [coord, None, None, None] tile1 = Tile(coordinate=coord, neighbors=neighbors1) Tile.remove_neighbor(tile1, 0)
def __init_tile(self, coord): tile = Tile(coord) tile.init_draw(self.dimensions) row = coord.row col = coord.column if row - 1 >= 0: Tile.add_neighbor(tile, NORTH, Coordinate(row - 1, col)) if row + 1 < self._dimensions: Tile.add_neighbor(tile, SOUTH, Coordinate(row + 1, col)) if col - 1 >= 0: Tile.add_neighbor(tile, EAST, Coordinate(row, col - 1)) if col + 1 < self._dimensions: Tile.add_neighbor(tile, WEST, Coordinate(row, col + 1)) return tile
def undo_wall(self, is_horizontal, coord_start): if not self._compute_static_valid_wall(is_horizontal, coord_start): raise ValueError("No wall to undo out of bounds.") else: if is_horizontal: top1 = self.board[coord_start.row - 1][coord_start.column] bottom1 = self.board[coord_start.row][coord_start.column] Tile.add_neighbor(top1, SOUTH, bottom1.coordinate) Tile.add_neighbor(bottom1, NORTH, top1.coordinate) top2 = self.board[coord_start.row - 1][coord_start.column + 1] bottom2 = self.board[coord_start.row][coord_start.column + 1] Tile.add_neighbor(top2, SOUTH, bottom2.coordinate) Tile.add_neighbor(bottom2, NORTH, top2.coordinate) else: left1 = self.board[coord_start.row][coord_start.column - 1] right1 = self.board[coord_start.row][coord_start.column] Tile.add_neighbor(left1, WEST, right1.coordinate) Tile.add_neighbor(right1, EAST, left1.coordinate) left2 = self.board[coord_start.row + 1][coord_start.column - 1] right2 = self.board[coord_start.row + 1][coord_start.column] Tile.add_neighbor(left2, WEST, right2.coordinate) Tile.add_neighbor(right2, EAST, left2.coordinate)
def place_wall(self, is_horizontal, coord_start): if not self._compute_static_valid_wall(is_horizontal, coord_start): raise ValueError("Wall placed out of bounds.") elif not self._compute_dynamic_valid_wall(is_horizontal, coord_start): raise ValueError("Wall placed on another wall.") else: if is_horizontal and coord_start.column != self.dimensions - 1: top1 = self.board[coord_start.row - 1][coord_start.column] bottom1 = self.board[coord_start.row][coord_start.column] Tile.remove_neighbor(top1, SOUTH) Tile.remove_neighbor(bottom1, NORTH) top2 = self.board[coord_start.row - 1][coord_start.column + 1] bottom2 = self.board[coord_start.row][coord_start.column + 1] Tile.remove_neighbor(top2, SOUTH) Tile.remove_neighbor(bottom2, NORTH) else: left1 = self.board[coord_start.row][coord_start.column - 1] right1 = self.board[coord_start.row][coord_start.column] Tile.remove_neighbor(left1, WEST) Tile.remove_neighbor(right1, EAST) left2 = self.board[coord_start.row + 1][coord_start.column - 1] right2 = self.board[coord_start.row + 1][coord_start.column] Tile.remove_neighbor(left2, WEST) Tile.remove_neighbor(right2, EAST)