def test_can_move(self): """Base case for moving a worker. * Worker at position (0,0) wants to move to the east * Worker at position (0,0) wants to move to the south """ self.assertTrue( rulechecker.can_move_build(self.board, self.workers[0], Direction.EAST)) self.assertTrue( rulechecker.can_move_build(self.board, self.workers[0], Direction.SOUTH))
def test_can_build_at_max_height(self): """Case for building onto a building that is already MAX_HEIGHT(4).""" board_copy = copy.copy(self.board) board_copy.build_floor(self.workers[3], Direction.EAST) self.assertFalse( rulechecker.can_move_build(board_copy, self.workers[3], Direction.NORTHEAST, Direction.SOUTH))
def next_turn(workers, board): """Creates a generator that yields the next possible turn given a list of workers and board :param list Worker workers: A list of workers belonging to the same player :param Board board: A game board :rtype Generator[(Worker, Direction, Direction), None None] """ for worker in workers: for move_dir in Direction: if (rulechecker.can_move_build(board, worker, move_dir)): yield (worker, move_dir, None) for move_dir, build_dir in product(Direction, Direction): if (rulechecker.can_move_build(board, worker, move_dir, build_dir)): yield (worker, move_dir, build_dir)
def test_can_move_high_building(self): """Testing that you cannot move two floors higher than current pos. * Worker at position (2,2) with height 0 wants to move to east to a building with height 2 """ self.assertFalse( rulechecker.can_move_build(self.board, self.workers[2], Direction.EAST))
def test_can_move_onto_worker(self): """Testing if you can move to a position occupied by another worker. * Worker at position (0,0) wants to move to the Worker on position (1, 1) """ self.assertFalse( rulechecker.can_move_build(self.board, self.workers[1], Direction.SOUTHEAST))
def test_can_move_offboard(self): """Case for testing if you can move to a position off the board. * Worker at position (0,0) wants to move to the north * Worker at position (0,0) wants to move to the northwest * Worker at position (0,0) wants to move to the west * Worker at position (0,0) wants to move to the southwest """ self.assertFalse( rulechecker.can_move_build(self.board, self.workers[0], Direction.NORTH)) self.assertFalse( rulechecker.can_move_build(self.board, self.workers[0], Direction.NORTHWEST)) self.assertFalse( rulechecker.can_move_build(self.board, self.workers[0], Direction.WEST)) self.assertFalse( rulechecker.can_move_build(self.board, self.workers[0], Direction.SOUTHWEST))
def _valid_turn(self, turn, board): """Checks whether a given turn is valid :param Turn turn: the Turn to validate :param Board board: the board to validate against """ if all(element is None for element in turn): return worker, move_dir, build_dir = turn can_move_build = rulechecker.can_move_build(copy.deepcopy(board), worker, move_dir, build_dir) if not can_move_build: raise PlayerInvalidTurn("")
def test_can_move_down_2_floors(self): """Case for testing if you can move from two floors down. * Worker at position (2,2) wants to move to the north, which has a building with height 1 * Worker at position (1,2) wants to move to the southwest, which has a building of height 2 * Worker at position (2,3) wants to move to the west, which has no building (i.e height 0) """ board_copy = copy.copy(self.board) board_copy.move_worker(self.workers[2], Direction.NORTH) board_copy.move_worker(self.workers[2], Direction.SOUTHWEST) self.assertTrue( rulechecker.can_move_build(board_copy, self.workers[2], Direction.WEST))
def test_can_move_build_on_same_pos(self): """Check that a Worker can build on the spot they just moved from.""" board = Board(workers={self.workers[0]: (0, 0)}) self.assertTrue( rulechecker.can_move_build(board, self.workers[0], Direction.SOUTH, Direction.NORTH))
def test_can_build_no_move(self): """Case for building a building on the worker location.""" board_copy = copy.copy(self.board) self.assertFalse( rulechecker.can_move_build(board_copy, self.workers[2], Direction.WEST, Direction.STAY))
def test_can_build_another_worker(self): """Case for building onto a position that contains another worker.""" self.assertFalse( rulechecker.can_move_build(self.board, self.workers[1], Direction.EAST, Direction.SOUTH))
def test_can_build_off_board(self): """Case for building off of the board.""" self.assertFalse( rulechecker.can_move_build(self.board, self.workers[0], Direction.EAST, Direction.NORTH))
def test_can_build(self): """Base case for can_build.""" self.assertTrue( rulechecker.can_move_build(self.board, self.workers[0], Direction.EAST, Direction.EAST))
def test_can_no_move(self): """Case for testing if you can not have a movement.""" self.assertFalse( rulechecker.can_move_build(self.board, self.workers[0], Direction.STAY))