Exemple #1
0
    def interpretPlayerPlacements(self, placementsDic, key):
        """
        Reads dictionary and interprets the placements and updates the game's board object with this information
        :param placementsDic: Gamestate dictionary at nested level ['gameState']['placements']
        :param key: The desired player whose placements are to be interpreted i.e. '1', '2', '3', '4'
        :return: None
        """
        assert isinstance(placementsDic, dict)
        assert isinstance(key, basestring)
        assert key in ['1', '2', '3', '4']

        self.game.board.setPlacements(playerNumber=int(key), \
                                   bottomRowCards=gameHandlerHelpers.convertCardsListToObj(placementsDic[key]['bottomRow']), \
                                   middleRowCards=gameHandlerHelpers.convertCardsListToObj(placementsDic[key]['middleRow']), \
                                   topRowCards=gameHandlerHelpers.convertCardsListToObj(placementsDic[key]['topRow']))
Exemple #2
0
 def interpretPlayerCards(self, gameState={}):
     """
     Interprets player cards from game state and updates game objects
     :param gameState: Game State dict
     :return: None
     """
     assert isinstance(gameState, dict)
     for i in range(1, self.playerCount+1):
         self.game.players[i-1].cards = gameHandlerHelpers.convertCardsListToObj(gameState['players'][str(i)]['cards'])
Exemple #3
0
    def updateGameState(self, game_state):
        """
        Updates this object's game state with new values from param game_state
        :param game_state: New game state
        :return: None
        """
        self.game.roundNumber = int(game_state['gameState']['roundNumber'])
        self.game.roundActionNumber = int(game_state['gameState']['roundActionNumber'])
        self.game.firstToAct = int(game_state['gameState']['firstToAct'])
        self.game.nextToAct = int(game_state['gameState']['nextToAct'])
        self.game.actingOrderPointer = int(game_state['gameState']['actingOrderPointer'])
        self.game.board.deck.currentPosition = int(game_state['gameState']['deckPointer'])

        for playerNumber in game_state['players'].keys():
            self.game.players[int(playerNumber)-1].cards = gameHandlerHelpers.convertCardsListToObj(game_state['players'][playerNumber]['cards'])
            self.game.players[int(playerNumber)-1].score = int(game_state['players'][playerNumber]['score'])
            self.game.board.placements[int(playerNumber)-1].bottomRow.cardPlacements = \
                gameHandlerHelpers.convertCardsListToObj(game_state['gameState']['placements'][playerNumber]['bottomRow'])
            self.game.board.placements[int(playerNumber)-1].middleRow.cardPlacements = \
                gameHandlerHelpers.convertCardsListToObj(game_state['gameState']['placements'][playerNumber]['middleRow'])
            self.game.board.placements[int(playerNumber)-1].topRow.cardPlacements = \
                gameHandlerHelpers.convertCardsListToObj(game_state['gameState']['placements'][playerNumber]['topRow'])

        return "Successfully updated game state!"