Ejemplo n.º 1
0
    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
Ejemplo n.º 2
0
 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
Ejemplo n.º 3
0
 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 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()
Ejemplo n.º 5
0
 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()
Ejemplo n.º 6
0
 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)
Ejemplo n.º 7
0
 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]
Ejemplo n.º 8
0
    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)
Ejemplo n.º 9
0
 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
Ejemplo n.º 10
0
 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())
Ejemplo n.º 11
0
    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, )
Ejemplo n.º 12
0
 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
Ejemplo n.º 13
0
 def test_player_move_from_boat_to_ship(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.JR)
     assert self.game.players_position[
         player_to_move] in Positions.jr_positions()
Ejemplo n.º 14
0
 def jr_ship_first_empty_slot(self):
     jr_positions = Positions.jr_positions().copy()
     return self.get_first_empty_slot(jr_positions)
Ejemplo n.º 15
0
 def affected_positions(self):
     positions = [Positions.JR_B, Positions.FD_B, *Positions.jr_positions()]
     positions.extend(Positions.fd_positions())
     return positions