def test_retrieve_num_fish(self): model = FishBoard(num_rows=4, num_cols=3) self.assertEqual(model.board[0][0].num_fish, 0) model = model.add_fish(0, 0) model = model.add_fish(0, 0) model = model.add_fish(0, 0) self.assertEqual(model.board[0][0].num_fish, 3)
def test_is_equal_false_different_num_fish(self): board1 = FishBoard(num_rows=4, num_cols=3) board2 = FishBoard(num_rows=4, num_cols=3) board1 = board1.add_fish(row=0, col=0) board2 = board2.add_fish(row=1, col=0) self.assertFalse(board1.is_equal(board2))
def test_is_equal(self): board1 = FishBoard(num_rows=4, num_cols=3) board2 = FishBoard(num_rows=4, num_cols=3) board1 = board1.add_fish(row=0, col=0) board2 = board2.add_fish(row=0, col=0) board1 = board1.create_hole(row=1, col=0) board2 = board2.create_hole(row=1, col=0) self.assertTrue(board1.is_equal(board2))
def test_max_fish(self): model = FishBoard(num_rows=4, num_cols=3) self.assertEqual(model.board[0][0].num_fish, 0) model = model.add_fish(0, 0) model = model.add_fish(0, 0) model = model.add_fish(0, 0) model = model.add_fish(0, 0) model = model.add_fish(0, 0) self.assertEqual(model.board[0][0].num_fish, 5) with self.assertRaises(ValueError): model = model.add_fish(0, 0)
def Demo2(n_fish_per_tile=1) -> FishGameController: """ Randomly Generated Holes with 1 Fish on all tiles... :return: A controller to be execute in main. """ hexgrid = HexGridView() board = FishBoard(num_rows=HEXES_ROWS, num_cols=HEXES_COLUMNS) for row in range(board.num_rows): for col in range(board.num_cols): if board.retrieve_num_fish( row=row, col=col) == 0 and board.is_tile(row=row, col=col): for i in range(n_fish_per_tile): board = board.add_fish(row=row, col=col) player_1 = Player("red", 0, 0, []) state = FishGameState(board=board, num_players=1, players=[player_1], current_player=player_1) behavior = FishGameBehavior(state=state, view=hexgrid) controller = FishGameController(behavior=behavior, view=hexgrid, state=state) return controller
def Demo3(holes: List[Coordinate]) -> FishGameController: """ Given the list of holes, render a board with holes at those cooridates and 1 fish at every non-hole tile. :param holes: List of hole Coordinates :return: A controller to be execute in main. """ hexgrid = HexGridView() board = FishBoard(num_rows=HEXES_ROWS, num_cols=HEXES_COLUMNS) for hole in holes: board = board.create_hole(row=hole.row, col=hole.col) for row in range(board.num_rows): for col in range(board.num_cols): if board.retrieve_num_fish( row=row, col=col) == 0 and board.is_tile(row=row, col=col): board = board.add_fish(row=row, col=col) player_1 = Player("red", 0, 0, []) state = FishGameState(board=board, num_players=1, players=[player_1], current_player=player_1) behavior = FishGameBehavior(state=state, view=hexgrid) controller = FishGameController(behavior=behavior, view=hexgrid, state=state) return controller
def RandomlyGenerateFish(board: FishBoard, total_num_fish=10): for _ in range(total_num_fish): not_added = True while not_added: random_row = randint(0, HEXES_ROWS - 1) random_col = randint(0, HEXES_COLUMNS - 1) if board.retrieve_num_fish( random_row, random_col) < MAX_NUM_FISH and board.is_tile( random_row, random_col): board = board.add_fish(row=random_row, col=random_col) not_added = False return board