def execute(self): player_position = self.game.players_position[self.player] assert player_position in self.game.cabin_boy_slots if player_position in Positions.jr_positions(): if self.payload.from_hold == TreasureHoldTeams.britain: if self.game.chests_position.jr_en <= 0: raise AssertionError("no chests here") self.game.chests_position.jr_en -= 1 self.game.chests_position.jr_fr += 1 else: if self.game.chests_position.jr_fr <= 0: raise AssertionError("no chests here") self.game.chests_position.jr_fr -= 1 self.game.chests_position.jr_en += 1 elif player_position in Positions.fd_positions(): if self.payload.from_hold == TreasureHoldTeams.britain: if self.game.chests_position.fd_en <= 0: raise AssertionError("no chests here") self.game.chests_position.fd_en -= 1 self.game.chests_position.fd_fr += 1 else: if self.game.chests_position.fd_fr <= 0: raise AssertionError("no chests here") self.game.chests_position.fd_fr -= 1 self.game.chests_position.fd_en += 1 else: raise AssertionError("You are not a cabin boy.") self.game.last_action = Action( action_type=Action.ActionType.MOVE_TREASURE, action_data=MoveTreasureActionData( cabin_boy=self.player, from_hold=self.payload.from_hold, to_hold=self.where_is_treasure_going())) self.game.next_turn()
def execute(self): assert ( self.game.players_info.get(self.player).chests > 0 ) team: PutChestPayload.Team = self.payload.which_team player_pos: Positions = self.game.players_position.get( self.player ) if self.game.last_action and ( self.game.last_action.action_type == Action.ActionType.CALL_FOR_AN_ATTACK and self.game.last_action.action_data.which_captain.username == self.player ): self.remove_other_chest_if_call_for_attack(player_pos) self.game.next_turn() if team == PutChestPayload.Team.britain: if player_pos in Positions.fd_positions(): self.game.chests_position.fd_en += 1 elif player_pos in Positions.jr_positions(): self.game.chests_position.jr_en += 1 elif team == PutChestPayload.Team.france: if player_pos in Positions.fd_positions(): self.game.chests_position.fd_fr += 1 elif player_pos in Positions.jr_positions(): self.game.chests_position.jr_fr += 1 self.game.players_info.get(self.player).chests -= 1
def available_move(self) -> Optional[Positions]: if self.game.get_position(self.player) in Positions.jr_positions(): return Positions.FD elif self.game.get_position(self.player) in Positions.fd_positions(): return Positions.JR else: return None
def on_same_ship(self, player1: str, player2: str): ship_slots_positions = [ Positions.jr_positions(), Positions.fd_positions() ] return any( self.players_position.get(player1) in ship and self.players_position.get(player2) in ship for ship in ship_slots_positions)
def cabin_boy_slots(self) -> List[Positions]: jr_cabin_boy = None fd_cabin_boy = None for p in Positions.jr_positions(): if p not in self.players_position.values(): break jr_cabin_boy = p for p in Positions.fd_positions(): if p not in self.players_position.values(): break fd_cabin_boy = p return [jr_cabin_boy, fd_cabin_boy]
def remove_other_chest_if_call_for_attack(self, player_pos): if not self.game.last_action.action_data.from_other_ship: self.game.chests_position.sg_nt -= 1 else: if player_pos in Positions.fd_positions(): if self.payload.from_which_team == PutChestPayload.Team.france: self.game.chests_position.jr_fr -= 1 elif self.payload.from_which_team == PutChestPayload.Team.britain: self.game.chests_position.jr_en -= 1 elif player_pos in Positions.jr_positions(): if self.payload.from_which_team == PutChestPayload.Team.france: self.game.chests_position.fd_fr -= 1 elif self.payload.from_which_team == PutChestPayload.Team.britain: self.game.chests_position.fd_en -= 1
def test_two_players_with_albatross(self, game: Game): game.event_cards = ["albatross", "albatross"] player1 = game.turn self._reveal_event_card_action(player1, 0) self._keep_event_card_action(player1) while game.get_position(game.turn) not in Positions.jr_positions(): game.next_turn() player2 = game.turn self._reveal_event_card_action(player2, 0) self._keep_event_card_action(player2) response = self._get_my_game(player2).json() assert (response["gameStatus"]["playersPosition"][player1] in Positions.tr_positions()) assert (response["gameStatus"]["playersPosition"][player2] in Positions.tr_positions())
def test_player_move_from_boat_to_tortuga(self): player_to_move = self.game.get_jr_caption() self.game.players_position[player_to_move] = Positions.JR_B self._move_action(player_to_move, Positions.TR) assert self.game.players_position[ player_to_move] in Positions.tr_positions()
def options(self) -> List: positions = [Positions.JR_B, Positions.FD_B, *Positions.tr_positions()] options = [] for player in self.game.players: if self.game.players_position[player] in positions: options.append(f"{player} to jolly roger") options.append(f"{player} to flying dutchman ship") return options
def test_use_event_card_after_reveal(self, game: Game): event_card_slug = "letter-of-marque" game.event_cards = ["letter-of-marque"] player = game.turn game.players_position[player] = Positions.JR_B self._reveal_event_card_action(player, 0) self.use_event_card_action(player, event_card_slug, 0) assert game.players_position[player] in Positions.jr_positions()
def test_keep_atlantis_card(self, game): player = game.turn game.event_cards = ["atlantis"] self._reveal_event_card_action(player, 0) self._keep_event_card_action(player) assert game.turn != player self.use_event_card_action(player, "atlantis") assert game.players_position[player] in Positions.fd_positions()
def execute(self): move_where = self.payload.move_where player_position = self.game.players_position.get(self.player) assert self.game.is_empty(move_where) if player_position in Positions.jr_positions(): assert move_where == Positions.JR_B elif player_position in Positions.fd_positions(): assert move_where == Positions.FD_B elif player_position in Positions.tr_positions(): assert move_where in [Positions.FD_B, Positions.JR_B] elif player_position == Positions.JR_B: assert move_where in [Positions.TR, Positions.JR] elif player_position == Positions.FD_B: assert move_where in [Positions.FD, Positions.TR] self.game.set_position(self.player, move_where) self.game.next_turn() self.game.last_action = Action(action_type=Action.ActionType.MOVE, )
def reveal(self) -> None: if self.game.get_position(self.player) in Positions.jr_positions(): treasures = (self.game.chests_position.jr_en + self.game.chests_position.jr_fr) self.game.chests_position.jr_en = 0 self.game.chests_position.jr_fr = 0 elif self.game.get_position(self.player) in Positions.fd_positions(): treasures = (self.game.chests_position.fd_en + self.game.chests_position.fd_fr) self.game.chests_position.fd_fr = 0 self.game.chests_position.fd_en = 0 elif self.game.get_position(self.player) in Positions.tr_positions(): self.game.chests_position.tr_fr = 1 self.game.chests_position.tr_en = 1 return else: return self.game.chests_position.sg_nt += treasures
def test_player_reveal_after_forced(self, game): game.event_cards = ["spanish-armada", "letter-of-marque", "black-spot"] player = game.turn other_player = game.players[1] event_cards_to_choose = [0, 2] self.force_another_player_to_choose_card(other_player, player, event_cards_to_choose) self._reveal_event_card_action(other_player, 1) assert game.players_position[other_player] in Positions.tr_positions()
def options_operations(self): positions = [Positions.JR_B, Positions.FD_B, *Positions.tr_positions()] options = [] for player in self.game.players: if self.game.players_position[player] in positions: options.extend([ Operation(player, Positions.JR), Operation(player, Positions.FD) ]) return options
def test_reveal_pistol_card(self, game: Game): game.event_cards = ["pistol"] player = game.turn self._reveal_event_card_action(player, 0) game_response = self._get_my_game(player).json() assert (game_response["gameStatus"]["lastAction"]["actionType"] == "reveal one event card") assert len(game_response["gameStatus"]["lastAction"]["actionData"] ["eventCardOptions"]) == 3 self.use_event_card_action(player, "pistol", 0) assert list( game.players_position.values())[1] in Positions.tr_positions()
def affected_positions(self) -> Optional[List[Positions]]: if self.game.get_position(self.player) in Positions.jr_positions(): positions = Positions.jr_positions() elif self.game.get_position(self.player) in Positions.fd_positions(): positions = Positions.fd_positions() elif self.game.get_position(self.player) in Positions.tr_positions(): positions = Positions.tr_positions() else: return None return positions
def fill_empty_position(self, position: Positions): if position in Positions.jr_positions(): positions = Positions.jr_positions() move_to = Positions.JR elif position in Positions.fd_positions(): positions = Positions.fd_positions() move_to = Positions.FD elif position in Positions.tr_positions(): positions = Positions.tr_positions() move_to = Positions.TR else: return move_from = None for front, back in zip(positions[0:], positions[1:]): if (front not in self.players_position.values() and back in self.players_position.values()): move_from = back break if move_from: for player, position in self.players_position.items(): if position == move_from: self.set_position(player, move_to)
def can_use(self) -> bool: if self.game.turn != self.player: return False positions = [Positions.JR_B, Positions.FD_B, *Positions.tr_positions()] return any(self.game.players_position[player] in positions for player in self.game.players)
def affected_positions(self): positions = [Positions.JR_B, Positions.FD_B, *Positions.jr_positions()] positions.extend(Positions.fd_positions()) return positions
def test_reveal_black_spot(self, game): player = game.turn game.event_cards = ["black-spot"] self._reveal_event_card_action(player, 0) assert game.players_position[player] in Positions.tr_positions() assert game.turn != player
def jr_ship_first_empty_slot(self): jr_positions = Positions.jr_positions().copy() return self.get_first_empty_slot(jr_positions)
def fd_ship_first_empty_slot(self): fd_positions = Positions.fd_positions().copy() return self.get_first_empty_slot(fd_positions)
def tortuga_first_empty_slot(self): tg_positions = Positions.tr_positions().copy() return self.get_first_empty_slot(tg_positions)