Beispiel #1
0
    def __init__(self, stage_data, player_data):
        logger.info("StageController is Created")

        # Stage Data
        self.start_stage_time = datetime.datetime.now()
        self.stage_data = stage_data
        self.player_data = player_data
        self.game_state = GameState(self.player_data)
        self.user_sprite = UserSprite(self.stage_data, self.player_data,
                                      self.game_state.user_state.user_id)
        self.finish_wave = True

        # controllers
        self.sprite_controller = SpriteController(self.stage_data.background,
                                                  self.user_sprite)
        self.player_controller = PlayerController(self.user_sprite,
                                                  self.game_state)
        self.collision_controller = CollisionController(self.sprite_controller)

        # views
        self.user_info_view = UserInfoView(USER_INFO_SIZE, self.player_data)
        self.stage_headline = StageHeadline(self.stage_data.stage_name)

        # events
        dispatcher.connect(self.handle_collision_event,
                           signal=SignalMapper.COLLISION_UPDATE,
                           sender=dispatcher.Any)
        dispatcher.connect(self.handle_combo_event,
                           signal=SignalMapper.COMBO_ATTACK,
                           sender=dispatcher.Any)
Beispiel #2
0
    def __init__(self):
        self.__current_state = GameState()
        self.__past_moves = []
        self.__all_possible_moves = {}

        self.__moves_getter = MovesGetter()
        self.__state_verifier = StateVerifier()

        self.__predict_filter = PredictiveFilter()

        self.__current_move_color = PieceColor.WHITE
Beispiel #3
0
    def try_make_move(self, move):
        moves = self.get_possible_moves(move.start_cell)

        if move in moves:
            self.castling_unavailable(move)

            new_state = GameState(self.__current_state, move)
            self.change_game_state(new_state, move)
            self.__current_move_color = PieceColor.invert(
                self.__current_move_color)
            return True

        return False
Beispiel #4
0
def get_game_state_for_forcing_the_issue_puzzle() -> GameState:
  """
  Generates a game view for the scenario described here:
  http://psellos.com/schnapsen/blog/2012/05/013-forcing.html

  The game state is the following:
    * cards_in_hand: [X♠, Q♥, X♣, A♦, K♦] [X♥, K♥, X♦, Q♦, J♦]
    * trump: ♥
    * trump_card: J♥
    * talon: [A♣], closed
    * next_player: PlayerId.ONE
    * won_tricks: [(K♠, Q♠), (A♥, A♠)], [(J♠, K♣), (J♣, Q♣)]
    * marriage_suits: [], [♣]
    * trick_points: (29, 31)
    * current_trick: (None, J♦)
    * player_that_closed_the_talon: PlayerId.TWO
    * opponent_points_when_talon_was_closed: 29
  """
  cards_in_hand = PlayerPair(
    one=[Card(Suit.SPADES, CardValue.TEN),
         Card(Suit.HEARTS, CardValue.QUEEN),
         Card(Suit.CLUBS, CardValue.TEN),
         Card(Suit.DIAMONDS, CardValue.ACE),
         Card(Suit.DIAMONDS, CardValue.KING)],
    two=[Card(Suit.HEARTS, CardValue.TEN),
         Card(Suit.HEARTS, CardValue.KING),
         Card(Suit.DIAMONDS, CardValue.TEN),
         Card(Suit.DIAMONDS, CardValue.QUEEN),
         Card(Suit.DIAMONDS, CardValue.JACK)])
  trump_card = Card(Suit.HEARTS, CardValue.JACK)
  talon = [Card(Suit.CLUBS, CardValue.ACE)]
  won_tricks = PlayerPair(
    one=[PlayerPair(Card(Suit.SPADES, CardValue.KING),
                    Card(Suit.SPADES, CardValue.QUEEN)),
         PlayerPair(Card(Suit.HEARTS, CardValue.ACE),
                    Card(Suit.SPADES, CardValue.ACE))],
    two=[PlayerPair(Card(Suit.SPADES, CardValue.JACK),
                    Card(Suit.CLUBS, CardValue.KING)),
         PlayerPair(Card(Suit.CLUBS, CardValue.JACK),
                    Card(Suit.CLUBS, CardValue.QUEEN))])
  marriage_suits = PlayerPair(one=[], two=[Suit.CLUBS])
  trick_points = PlayerPair(one=29, two=31)
  game_state = GameState(cards_in_hand=cards_in_hand, trump=trump_card.suit,
                         trump_card=trump_card, talon=talon,
                         won_tricks=won_tricks, trick_points=trick_points,
                         marriage_suits=marriage_suits,
                         next_player=PlayerId.TWO)
  game_state.close_talon()
  game_state.current_trick.two = Card(Suit.DIAMONDS, CardValue.JACK)
  game_state.next_player = PlayerId.ONE
  return game_state
Beispiel #5
0
def get_game_state_for_know_your_opponent_puzzle() -> GameState:
  """
  Generates a game state for the scenario described here:
  http://psellos.com/schnapsen/blog/2020/09/147-know.html

  The game state is the following:
    * cards_in_hand: [K♠, J♠, K♥, A♣, K♣] [A♠, Q♠, A♥, X♣, Q♣]
    * trump: ♥
    * trump_card: Q♥
    * talon: [J♣], closed
    * next_player: PlayerId.ONE
    * won_tricks: [(X♥, X♦), (J♥, J♦)], [(Q♦, X♠), (K♦, A♦)]
    * marriage_suits: [], []
    * trick_points: (24, 28)
    * current_trick: (None, A♥)
    * player_that_closed_the_talon: PlayerId.TWO
    * opponent_points_when_talon_was_closed: 24
  """
  cards_in_hand = PlayerPair(
    one=[Card(Suit.SPADES, CardValue.KING),
         Card(Suit.SPADES, CardValue.JACK),
         Card(Suit.HEARTS, CardValue.KING),
         Card(Suit.CLUBS, CardValue.ACE),
         Card(Suit.CLUBS, CardValue.KING)],
    two=[Card(Suit.SPADES, CardValue.ACE),
         Card(Suit.SPADES, CardValue.QUEEN),
         Card(Suit.HEARTS, CardValue.ACE),
         Card(Suit.CLUBS, CardValue.TEN),
         Card(Suit.CLUBS, CardValue.QUEEN)])
  trump_card = Card(Suit.HEARTS, CardValue.QUEEN)
  talon = [Card(Suit.CLUBS, CardValue.JACK)]
  won_tricks = PlayerPair(
    one=[PlayerPair(Card(Suit.HEARTS, CardValue.TEN),
                    Card(Suit.DIAMONDS, CardValue.TEN)),
         PlayerPair(Card(Suit.HEARTS, CardValue.JACK),
                    Card(Suit.DIAMONDS, CardValue.JACK))],
    two=[PlayerPair(Card(Suit.DIAMONDS, CardValue.QUEEN),
                    Card(Suit.SPADES, CardValue.TEN)),
         PlayerPair(Card(Suit.DIAMONDS, CardValue.KING),
                    Card(Suit.DIAMONDS, CardValue.ACE))])
  trick_points = PlayerPair(one=24, two=28)
  game_state = GameState(cards_in_hand=cards_in_hand, trump=trump_card.suit,
                         trump_card=trump_card, talon=talon,
                         won_tricks=won_tricks, trick_points=trick_points,
                         next_player=PlayerId.TWO)
  game_state.close_talon()
  game_state.current_trick.two = Card(Suit.HEARTS, CardValue.ACE)
  game_state.next_player = PlayerId.ONE
  return game_state
Beispiel #6
0
def get_game_state_with_empty_talon_for_tests() -> GameState:
  """
  Generates a valid game state in which more than five tricks have been played
  and the talon is empty. This is meant to be used as a starting point for
  tests.

  The game state is the following:
    * cards_in_hand: [A♣, K♥, X♥, X♠], [J♦, K♣, J♣, Q♣]
    * trump: ♣
    * trump_card: None
    * talon: []
    * next_player: PlayerId.ONE
    * won_tricks: [(K♠, Q♠), (A♦, K♦), (A♠, J♠)],
                  [(J♥, A♥), (X♦, X♣), (Q♥, Q♦)]
    * marriage_suits: [], [♦]
    * trick_points: (35, 59)
    * current_trick: (None, None)
  """
  cards_in_hand = PlayerPair(
    one=[Card(Suit.CLUBS, CardValue.ACE),
         Card(Suit.HEARTS, CardValue.KING),
         Card(Suit.HEARTS, CardValue.TEN),
         Card(Suit.SPADES, CardValue.TEN)],
    two=[Card(Suit.DIAMONDS, CardValue.JACK),
         Card(Suit.CLUBS, CardValue.KING),
         Card(Suit.CLUBS, CardValue.JACK),
         Card(Suit.CLUBS, CardValue.QUEEN)])
  talon = []
  won_tricks = PlayerPair(
    one=[PlayerPair(Card(Suit.SPADES, CardValue.KING),
                    Card(Suit.SPADES, CardValue.QUEEN)),
         PlayerPair(Card(Suit.DIAMONDS, CardValue.ACE),
                    Card(Suit.DIAMONDS, CardValue.KING)),
         PlayerPair(Card(Suit.SPADES, CardValue.ACE),
                    Card(Suit.SPADES, CardValue.JACK))],
    two=[PlayerPair(Card(Suit.HEARTS, CardValue.JACK),
                    Card(Suit.HEARTS, CardValue.ACE)),
         PlayerPair(Card(Suit.DIAMONDS, CardValue.TEN),
                    Card(Suit.CLUBS, CardValue.TEN)),
         PlayerPair(Card(Suit.HEARTS, CardValue.QUEEN),
                    Card(Suit.DIAMONDS, CardValue.QUEEN))])
  marriage_suits = PlayerPair(one=[], two=[Suit.DIAMONDS])
  trick_points = PlayerPair(one=35, two=59)
  current_trick = PlayerPair(None, None)
  return GameState(cards_in_hand=cards_in_hand, trump=Suit.CLUBS,
                   trump_card=None, talon=talon, won_tricks=won_tricks,
                   marriage_suits=marriage_suits, trick_points=trick_points,
                   current_trick=current_trick)
Beispiel #7
0
def get_game_state_with_all_tricks_played() -> GameState:
  """
  Generates a valid game state in which all the tricks were played and no player
  could reach 66 points.

  The game state is the following:
    * cards_in_hand: [], []
    * trump: ♣
    * trump_card: None
    * talon: []
    * next_player: PlayerId.ONE
    * won_tricks: [(K♠, Q♠), (A♠, X♥), (K♣, Q♣), (A♣, X♣), (J♣, J♠)],
                  [(Q♥, K♥), (X♥, A♥), (Q♦, K♦), (X♦, A♦), (J♥, J♦)]
    * marriage_suits: [], []
    * trick_points: (60, 60)
    * current_trick: (None, None)
  """
  cards_in_hand = PlayerPair([], [])
  talon = []
  won_tricks = PlayerPair(
    one=[PlayerPair(Card(Suit.SPADES, CardValue.KING),
                    Card(Suit.SPADES, CardValue.QUEEN)),
         PlayerPair(Card(Suit.SPADES, CardValue.ACE),
                    Card(Suit.SPADES, CardValue.TEN)),
         PlayerPair(Card(Suit.CLUBS, CardValue.KING),
                    Card(Suit.CLUBS, CardValue.QUEEN)),
         PlayerPair(Card(Suit.CLUBS, CardValue.ACE),
                    Card(Suit.CLUBS, CardValue.TEN)),
         PlayerPair(Card(Suit.CLUBS, CardValue.JACK),
                    Card(Suit.SPADES, CardValue.JACK))],
    two=[PlayerPair(Card(Suit.HEARTS, CardValue.QUEEN),
                    Card(Suit.HEARTS, CardValue.KING)),
         PlayerPair(Card(Suit.HEARTS, CardValue.TEN),
                    Card(Suit.HEARTS, CardValue.ACE)),
         PlayerPair(Card(Suit.DIAMONDS, CardValue.QUEEN),
                    Card(Suit.DIAMONDS, CardValue.KING)),
         PlayerPair(Card(Suit.DIAMONDS, CardValue.TEN),
                    Card(Suit.DIAMONDS, CardValue.ACE)),
         PlayerPair(Card(Suit.DIAMONDS, CardValue.JACK),
                    Card(Suit.HEARTS, CardValue.JACK))])
  marriage_suits = PlayerPair([], [])
  trick_points = PlayerPair(one=60, two=60)
  current_trick = PlayerPair(None, None)
  return GameState(cards_in_hand=cards_in_hand, trump=Suit.CLUBS,
                   trump_card=None, talon=talon, won_tricks=won_tricks,
                   marriage_suits=marriage_suits, trick_points=trick_points,
                   current_trick=current_trick)
Beispiel #8
0
def get_game_view_for_duck_puzzle() -> GameState:
  """
  Generates a game view for the scenario described here:
  http://psellos.com/schnapsen/blog/2012/03/003-duck.html

  The game state is the following:
    * cards_in_hand: [A♠, X♠, A♥, Q♥, K♦], [K♠, Q♠, None, None, None]
    * unseen_cards: K♥, X♥, X♦, Q♦
    * trump: ♦
    * trump_card: J♦
    * talon: [None]
    * next_player: PlayerId.ONE
    * won_tricks: [(A♦, A♣), (K♣, J♣)], [(Q♣, X♣), (J♥, J♠)]
    * marriage_suits: [], []
    * trick_points: (28, 17)
    * current_trick: (None, Q♠)
  """
  cards_in_hand = PlayerPair(
    one=[Card(Suit.SPADES, CardValue.ACE),
         Card(Suit.SPADES, CardValue.TEN),
         Card(Suit.HEARTS, CardValue.ACE),
         Card(Suit.HEARTS, CardValue.QUEEN),
         Card(Suit.DIAMONDS, CardValue.KING)],
    two=[Card(Suit.SPADES, CardValue.KING),
         Card(Suit.SPADES, CardValue.QUEEN),
         None, None, None])
  trump_card = Card(Suit.DIAMONDS, CardValue.JACK)
  won_tricks = PlayerPair(
    one=[PlayerPair(Card(Suit.DIAMONDS, CardValue.ACE),
                    Card(Suit.CLUBS, CardValue.ACE)),
         PlayerPair(Card(Suit.CLUBS, CardValue.KING),
                    Card(Suit.CLUBS, CardValue.JACK))],
    two=[PlayerPair(Card(Suit.CLUBS, CardValue.QUEEN),
                    Card(Suit.CLUBS, CardValue.TEN)),
         PlayerPair(Card(Suit.HEARTS, CardValue.JACK),
                    Card(Suit.SPADES, CardValue.JACK))])
  trick_points = PlayerPair(one=28, two=37)
  marriage_suits = PlayerPair(one=[], two=[Suit.SPADES])
  # noinspection PyTypeChecker
  current_trick = PlayerPair(None, Card(Suit.SPADES, CardValue.QUEEN))
  return GameState(cards_in_hand=cards_in_hand, trump=trump_card.suit,
                   trump_card=trump_card, talon=[None], won_tricks=won_tricks,
                   trick_points=trick_points, marriage_suits=marriage_suits,
                   current_trick=current_trick)
Beispiel #9
0
def get_game_state_for_tests() -> GameState:
  """
  Generates a valid game state that could be used as a starting point in tests.

  The game state is the following:
    * cards_in_hand: [Q♥, K♥, X♥, X♠, A♠], [Q♦, K♣, J♣, J♠, Q♣]
    * trump: ♣
    * trump_card: A♣
    * talon: [J♦]
    * next_player: PlayerId.ONE
    * won_tricks: [(K♠, Q♠), (A♦, K♦)], [(J♥, A♥), (X♦, X♣)]
    * marriage_suits: [], [♦]
    * trick_points: (22, 53)
    * current_trick: (None, None)
  """
  cards_in_hand = PlayerPair(
    one=[Card(Suit.HEARTS, CardValue.QUEEN),
         Card(Suit.HEARTS, CardValue.KING),
         Card(Suit.HEARTS, CardValue.TEN),
         Card(Suit.SPADES, CardValue.TEN),
         Card(Suit.SPADES, CardValue.ACE)],
    two=[Card(Suit.DIAMONDS, CardValue.QUEEN),
         Card(Suit.CLUBS, CardValue.KING),
         Card(Suit.CLUBS, CardValue.JACK),
         Card(Suit.SPADES, CardValue.JACK),
         Card(Suit.CLUBS, CardValue.QUEEN)])
  trump_card = Card(Suit.CLUBS, CardValue.ACE)
  talon = [Card(Suit.DIAMONDS, CardValue.JACK)]
  won_tricks = PlayerPair(
    one=[PlayerPair(Card(Suit.SPADES, CardValue.KING),
                    Card(Suit.SPADES, CardValue.QUEEN)),
         PlayerPair(Card(Suit.DIAMONDS, CardValue.ACE),
                    Card(Suit.DIAMONDS, CardValue.KING))],
    two=[PlayerPair(Card(Suit.HEARTS, CardValue.JACK),
                    Card(Suit.HEARTS, CardValue.ACE)),
         PlayerPair(Card(Suit.DIAMONDS, CardValue.TEN),
                    Card(Suit.CLUBS, CardValue.TEN))])
  marriage_suits = PlayerPair(one=[], two=[Suit.DIAMONDS])
  trick_points = PlayerPair(one=22, two=53)
  current_trick = PlayerPair(None, None)
  return GameState(cards_in_hand=cards_in_hand, trump=trump_card.suit,
                   trump_card=trump_card, talon=talon, won_tricks=won_tricks,
                   marriage_suits=marriage_suits, trick_points=trick_points,
                   current_trick=current_trick)
Beispiel #10
0
def get_game_state_for_who_laughs_last_puzzle() -> GameState:
  """
  Generates a game state for the scenario described here:
  http://psellos.com/schnapsen/blog/2012/03/004-last.html

  The game state is the following:
    * cards_in_hand: [K♥, Q♥, A♣, X♦, Q♦], [X♠, A♠, X♥, X♣, K♦]
    * trump: ♥
    * trump_card: J♥
    * talon: [A♦]
    * next_player: PlayerId.ONE
    * won_tricks: [(Q♠, J♦)], [(Q♣, K♣), (J♣, J♠), (K♠, A♥)]
    * marriage_suits: [], []
    * trick_points: (5, 26)
    * current_trick: (None, X♠)
  """
  cards_in_hand = PlayerPair(
    one=[Card(Suit.HEARTS, CardValue.KING),
         Card(Suit.HEARTS, CardValue.QUEEN),
         Card(Suit.CLUBS, CardValue.ACE),
         Card(Suit.DIAMONDS, CardValue.TEN),
         Card(Suit.DIAMONDS, CardValue.QUEEN)],
    two=[Card(Suit.SPADES, CardValue.TEN),
         Card(Suit.SPADES, CardValue.ACE),
         Card(Suit.HEARTS, CardValue.TEN),
         Card(Suit.CLUBS, CardValue.TEN),
         Card(Suit.DIAMONDS, CardValue.KING)])
  trump_card = Card(Suit.HEARTS, CardValue.JACK)
  talon = [Card(Suit.DIAMONDS, CardValue.ACE)]
  won_tricks = PlayerPair(
    one=[PlayerPair(Card(Suit.SPADES, CardValue.QUEEN),
                    Card(Suit.DIAMONDS, CardValue.JACK))],
    two=[PlayerPair(Card(Suit.CLUBS, CardValue.QUEEN),
                    Card(Suit.CLUBS, CardValue.KING)),
         PlayerPair(Card(Suit.CLUBS, CardValue.JACK),
                    Card(Suit.SPADES, CardValue.JACK)),
         PlayerPair(Card(Suit.SPADES, CardValue.KING),
                    Card(Suit.HEARTS, CardValue.ACE))])
  trick_points = PlayerPair(one=5, two=26)
  # noinspection PyTypeChecker
  current_trick = PlayerPair(None, Card(Suit.SPADES, CardValue.TEN))
  return GameState(cards_in_hand=cards_in_hand, trump=trump_card.suit,
                   trump_card=trump_card, talon=talon, won_tricks=won_tricks,
                   trick_points=trick_points, current_trick=current_trick)
Beispiel #11
0
def get_game_state_for_you_first_no_you_first_puzzle() -> GameState:
  """
  Generates a game state for the scenario described here:
  http://psellos.com/schnapsen/blog/2012/03/005-first.html

  The game state is the following:
    * cards_in_hand: [K♠, Q♥, A♥, Q♣, J♣], [X♥, J♥, A♦, Q♦, J♦]
    * trump: ♦
    * trump_card: None
    * talon: []
    * next_player: PlayerId.ONE
    * won_tricks: [(K♣, Q♠), (K♦, A♣), (A♠, X♠)], [(J♠, K♥), (X♣, X♦)]
    * marriage_suits: [], []
    * trick_points: (43, 26)
    * current_trick: (None, None)
  """
  cards_in_hand = PlayerPair(
    one=[Card(Suit.SPADES, CardValue.KING),
         Card(Suit.HEARTS, CardValue.QUEEN),
         Card(Suit.HEARTS, CardValue.ACE),
         Card(Suit.CLUBS, CardValue.QUEEN),
         Card(Suit.CLUBS, CardValue.JACK)],
    two=[Card(Suit.HEARTS, CardValue.TEN),
         Card(Suit.HEARTS, CardValue.JACK),
         Card(Suit.DIAMONDS, CardValue.ACE),
         Card(Suit.DIAMONDS, CardValue.QUEEN),
         Card(Suit.DIAMONDS, CardValue.JACK)])
  won_tricks = PlayerPair(
    one=[PlayerPair(Card(Suit.CLUBS, CardValue.KING),
                    Card(Suit.SPADES, CardValue.QUEEN)),
         PlayerPair(Card(Suit.DIAMONDS, CardValue.KING),
                    Card(Suit.CLUBS, CardValue.ACE)),
         PlayerPair(Card(Suit.SPADES, CardValue.ACE),
                    Card(Suit.SPADES, CardValue.TEN))],
    two=[PlayerPair(Card(Suit.SPADES, CardValue.JACK),
                    Card(Suit.HEARTS, CardValue.KING)),
         PlayerPair(Card(Suit.CLUBS, CardValue.TEN),
                    Card(Suit.DIAMONDS, CardValue.TEN))])
  trick_points = PlayerPair(one=43, two=26)
  current_trick = PlayerPair(None, None)
  return GameState(cards_in_hand=cards_in_hand, trump=Suit.DIAMONDS,
                   trump_card=None, talon=[], won_tricks=won_tricks,
                   trick_points=trick_points, current_trick=current_trick)
Beispiel #12
0
def get_game_state_for_playing_to_win_the_last_trick_puzzle() -> GameState:
  """
  Generates a game state for the scenario described here:
  http://psellos.com/schnapsen/blog/2019/12/144-last.html

  The game state is the following:
    * cards_in_hand: [K♠, X♥, K♣, X♦, Q♦], [J♥, J♣, A♦, K♦, J♦]
    * trump: ♣
    * trump_card: None
    * talon: []
    * next_player: PlayerId.ONE
    * won_tricks: [(A♥, Q♠), (A♣, A♠)], [(J♠, X♠), (Q♥, X♣), (K♥, Q♣)]
    * marriage_suits: [], []
    * trick_points: (36, 32)
    * current_trick: (None, None)
  """
  cards_in_hand = PlayerPair(
    one=[Card(Suit.SPADES, CardValue.KING),
         Card(Suit.HEARTS, CardValue.TEN),
         Card(Suit.CLUBS, CardValue.KING),
         Card(Suit.DIAMONDS, CardValue.TEN),
         Card(Suit.DIAMONDS, CardValue.QUEEN)],
    two=[Card(Suit.HEARTS, CardValue.JACK),
         Card(Suit.CLUBS, CardValue.JACK),
         Card(Suit.DIAMONDS, CardValue.ACE),
         Card(Suit.DIAMONDS, CardValue.KING),
         Card(Suit.DIAMONDS, CardValue.JACK)])
  won_tricks = PlayerPair(
    one=[PlayerPair(Card(Suit.HEARTS, CardValue.ACE),
                    Card(Suit.SPADES, CardValue.QUEEN)),
         PlayerPair(Card(Suit.CLUBS, CardValue.ACE),
                    Card(Suit.SPADES, CardValue.ACE))],
    two=[PlayerPair(Card(Suit.SPADES, CardValue.JACK),
                    Card(Suit.SPADES, CardValue.TEN)),
         PlayerPair(Card(Suit.HEARTS, CardValue.QUEEN),
                    Card(Suit.CLUBS, CardValue.TEN)),
         PlayerPair(Card(Suit.HEARTS, CardValue.KING),
                    Card(Suit.CLUBS, CardValue.QUEEN))])
  trick_points = PlayerPair(one=36, two=32)
  current_trick = PlayerPair(None, None)
  return GameState(cards_in_hand=cards_in_hand, trump=Suit.CLUBS,
                   trump_card=None, talon=[], won_tricks=won_tricks,
                   trick_points=trick_points, current_trick=current_trick)
Beispiel #13
0
def get_game_state_for_tempo_puzzle() -> GameState:
  """
  Generates a game state for the scenario described here:
  http://psellos.com/schnapsen/blog/2012/08/027-tempo.html

  The game state is the following:
    * cards_in_hand: [J♠, Q♥, A♣, K♣, J♣], [A♠, A♥, K♥, J♥, Q♣]
    * trump: ♠
    * trump_card: None
    * talon: []
    * next_player: PlayerId.ONE
    * won_tricks: [(X♠, Q♠), (X♣, X♦), (Q♦, J♦)], [(K♦, A♦), (X♥, K♠)]
    * marriage_suits: [], []
    * trick_points: (38, 29)
    * current_trick: (None, None)
  """
  cards_in_hand = PlayerPair(
    one=[Card(Suit.SPADES, CardValue.JACK),
         Card(Suit.HEARTS, CardValue.QUEEN),
         Card(Suit.CLUBS, CardValue.ACE),
         Card(Suit.CLUBS, CardValue.KING),
         Card(Suit.CLUBS, CardValue.JACK)],
    two=[Card(Suit.SPADES, CardValue.ACE),
         Card(Suit.HEARTS, CardValue.ACE),
         Card(Suit.HEARTS, CardValue.KING),
         Card(Suit.HEARTS, CardValue.JACK),
         Card(Suit.CLUBS, CardValue.QUEEN)])
  won_tricks = PlayerPair(
    one=[PlayerPair(Card(Suit.SPADES, CardValue.TEN),
                    Card(Suit.SPADES, CardValue.QUEEN)),
         PlayerPair(Card(Suit.CLUBS, CardValue.TEN),
                    Card(Suit.DIAMONDS, CardValue.TEN)),
         PlayerPair(Card(Suit.DIAMONDS, CardValue.QUEEN),
                    Card(Suit.DIAMONDS, CardValue.JACK))],
    two=[PlayerPair(Card(Suit.DIAMONDS, CardValue.KING),
                    Card(Suit.DIAMONDS, CardValue.ACE)),
         PlayerPair(Card(Suit.HEARTS, CardValue.TEN),
                    Card(Suit.SPADES, CardValue.KING))])
  trick_points = PlayerPair(one=38, two=29)
  current_trick = PlayerPair(None, None)
  return GameState(cards_in_hand=cards_in_hand, trump=Suit.SPADES,
                   trump_card=None, talon=[], won_tricks=won_tricks,
                   trick_points=trick_points, current_trick=current_trick)
Beispiel #14
0
def get_game_view_for_the_last_trump_puzzle() -> GameState:
  """
  Generates a game view for the scenario described here:
  http://psellos.com/schnapsen/blog/2020/06/145-trump.html

  The game state is the following:
    * cards_in_hand: [X♠, X♥, A♣, K♣, J♣] [Q♦, None, None, None, None]
    * unseen_cards: K♠, A♥, Q♣, X♣, J♦
    * trump: ♠
    * trump_card: J♠
    * talon: [None]
    * next_player: PlayerId.ONE
    * won_tricks: [(A♠, A♦), (Q♠, Q♥)], [(J♥, K♦), (K♥, X♦)]
    * marriage_suits: [], [♦]
    * trick_points: (28, 40)
    * current_trick: (None, Q♦)
  """
  cards_in_hand = PlayerPair(
    one=[Card(Suit.SPADES, CardValue.TEN),
         Card(Suit.HEARTS, CardValue.TEN),
         Card(Suit.CLUBS, CardValue.ACE),
         Card(Suit.CLUBS, CardValue.KING),
         Card(Suit.CLUBS, CardValue.JACK)],
    two=[Card(Suit.DIAMONDS, CardValue.QUEEN), None, None, None, None])
  trump_card = Card(Suit.SPADES, CardValue.JACK)
  won_tricks = PlayerPair(
    one=[PlayerPair(Card(Suit.SPADES, CardValue.ACE),
                    Card(Suit.DIAMONDS, CardValue.ACE)),
         PlayerPair(Card(Suit.SPADES, CardValue.QUEEN),
                    Card(Suit.HEARTS, CardValue.QUEEN))],
    two=[PlayerPair(Card(Suit.HEARTS, CardValue.JACK),
                    Card(Suit.DIAMONDS, CardValue.KING)),
         PlayerPair(Card(Suit.HEARTS, CardValue.KING),
                    Card(Suit.DIAMONDS, CardValue.TEN))])
  trick_points = PlayerPair(one=28, two=40)
  marriage_suits = PlayerPair(one=[], two=[Suit.DIAMONDS])
  # noinspection PyTypeChecker
  current_trick = PlayerPair(None, Card(Suit.DIAMONDS, CardValue.QUEEN))
  return GameState(cards_in_hand=cards_in_hand, trump=trump_card.suit,
                   trump_card=trump_card, talon=[None], won_tricks=won_tricks,
                   trick_points=trick_points, marriage_suits=marriage_suits,
                   current_trick=current_trick)
Beispiel #15
0
def get_game_view_for_grab_the_brass_ring_puzzle() -> GameState:
  """
  Generates a game view for the scenario described here:
  http://psellos.com/schnapsen/blog/2020/07/146-grab.html

  The game state is the following:
    * cards_in_hand: [K♠, J♠, Q♥, A♣, Q♦] [J♣, None, None, None, None]
    * unseen_cards: A♠, Q♠, A♥, X♥, K♥
    * trump: ♦
    * trump_card: J♦
    * talon: [None]
    * next_player: PlayerId.ONE
    * won_tricks: [(A♦, X♣), (K♣, Q♣), (K♦, J♥)], [(X♠, X♦)]
    * marriage_suits: [], []
    * trick_points: (34, 20)
    * current_trick: (None, J♣)
  """
  cards_in_hand = PlayerPair(
    one=[Card(Suit.SPADES, CardValue.KING),
         Card(Suit.SPADES, CardValue.JACK),
         Card(Suit.HEARTS, CardValue.QUEEN),
         Card(Suit.CLUBS, CardValue.ACE),
         Card(Suit.DIAMONDS, CardValue.QUEEN)],
    two=[Card(Suit.CLUBS, CardValue.JACK), None, None, None, None])
  trump_card = Card(Suit.DIAMONDS, CardValue.JACK)
  won_tricks = PlayerPair(
    one=[PlayerPair(Card(Suit.DIAMONDS, CardValue.ACE),
                    Card(Suit.CLUBS, CardValue.TEN)),
         PlayerPair(Card(Suit.CLUBS, CardValue.KING),
                    Card(Suit.CLUBS, CardValue.QUEEN)),
         PlayerPair(Card(Suit.DIAMONDS, CardValue.KING),
                    Card(Suit.HEARTS, CardValue.JACK))],
    two=[PlayerPair(Card(Suit.SPADES, CardValue.TEN),
                    Card(Suit.DIAMONDS, CardValue.TEN))])
  trick_points = PlayerPair(one=34, two=20)
  # noinspection PyTypeChecker
  current_trick = PlayerPair(None, Card(Suit.CLUBS, CardValue.JACK))
  return GameState(cards_in_hand=cards_in_hand, trump=trump_card.suit,
                   trump_card=trump_card, talon=[None], won_tricks=won_tricks,
                   trick_points=trick_points, current_trick=current_trick)
Beispiel #16
0
def _game_view_from_dict(fields: Dict[str, Any]) -> GameState:
  cards_in_hand = fields["cards_in_hand"]
  fields["cards_in_hand"] = PlayerPair(card_list_from_string(cards_in_hand[0]),
                                       card_list_from_string(cards_in_hand[1]))
  trump_card = fields.get("trump_card", None)
  fields["trump_card"] = \
    Card.from_string(trump_card) if trump_card is not None else None
  fields["talon"] = card_list_from_string(fields.get("talon", []))
  won_tricks = fields.get("won_tricks", ([], []))
  fields["won_tricks"] = PlayerPair(
    [_trick_from_string_tuple(str_tuple) for str_tuple in won_tricks[0]],
    [_trick_from_string_tuple(str_tuple) for str_tuple in won_tricks[1]])
  marriage_suits = fields.get("marriage_suits", None)
  if marriage_suits is not None:
    fields["marriage_suits"] = PlayerPair(*marriage_suits)
  trick_points = fields.get("trick_points", None)
  if trick_points is not None:
    fields["trick_points"] = PlayerPair(*trick_points)
  else:
    trick_points = PlayerPair(0, 0)
    for player in PlayerId:
      if len(fields["won_tricks"][player]) > 0 and \
          fields.get("marriage_suits", None) is not None:
        for suit in fields["marriage_suits"][player]:
          trick_points[player] += 40 if suit == fields["trump"] else 20
      for trick in fields["won_tricks"][player]:
        trick_points[player] += trick.one.card_value + trick.two.card_value
    fields["trick_points"] = trick_points
  trick = fields.get("current_trick", None)
  if trick is not None:
    fields["current_trick"] = PlayerPair(
      Card.from_string(trick[0]) if trick[0] is not None else None,
      Card.from_string(trick[1]) if trick[1] is not None else None)
  game_view = GameState(**fields)
  logging.debug("HeuristicPlayerTest: Using game view: %s",
                pprint.pformat(str(game_view)))
  return game_view
Beispiel #17
0
 def reset(self):
     self.gameState = GameState(empty_board(), 1, (6, 4))
     self.currentPlayer = 1
     return self.gameState
Beispiel #18
0
 def __init__(self):
     self.currentPlayer = 1
     self.gameState = GameState(empty_board(), 1, (6, 4))
     self.grid_shape = (48, 8)
     self.input_shape = (2, 48, 8)
     self.name = 'paper_soccer'
Beispiel #19
0
 def will_correct_state_after_move(self, move):
     game_state = GameState(self.__current_state, move)
     return self.__state_verifier.verify(game_state, move)