Пример #1
0
class FightingWithLandlordGame(object):
    def __init__(self):
        self.board_state = GameBoardData()
        self._landlord = None
        self._farmer_one = None
        self._farmer_two = None
        self._players = None

    def setup(self, game_parser):
        # todo: change --player to farmer2
        # todo: add evaluation functions
        print('Order of the game:')
        print(self.board_state.agent_order_pretty)
        # select player
        # player = random.choice([FARMER_ONE, FARMER_TWO, LANDLORD])
        LandlordAgents = getattr(landlord_agents, game_parser.landlord_agent)
        FarmerAgents = getattr(farmer_agents, game_parser.farmer_agent)
        evaluation = game_parser.evaluation
        rollout_policy = game_parser.rollout_policy
        # if player == FARMER_ONE:
        #     PlayerAgents = getattr(farmer_agents, game_parser.farmer_two_agent)
        #     print('You are farmer1!')
        #     self._landlord = LandlordAgents(LANDLORD, evaluation)
        #     self._farmer_one = PlayerAgents(FARMER_ONE, evaluation)
        #     self._farmer_two = FarmerAgents(FARMER_TWO, evaluation)
        # if player == FARMER_TWO:
        #     print('You are farmer2!')
        #     PlayerAgents = getattr(farmer_agents, game_parser.farmer_two_agent)
        #     self._landlord = LandlordAgents(LANDLORD, evaluation)
        #     self._farmer_one = FarmerAgents(FARMER_ONE, evaluation)
        #     self._farmer_two = PlayerAgents(FARMER_TWO, evaluation)
        # if player == LANDLORD:
        #     print('You are landlord!')
        # PlayerAgents = getattr(landlord_agents, game_parser.farmer_two_agent)
        self._landlord = LandlordAgents(LANDLORD, evaluation)
        self._farmer_one = FarmerAgents(FARMER_ONE, evaluation)
        self._farmer_two = FarmerAgents(FARMER_TWO, evaluation)
        print('landlord hand:{}'.format(sorted(self.board_state.get_hands(LANDLORD))))
        print('farmer1 hand:{}'.format(sorted(self.board_state.get_hands(FARMER_ONE))))
        print('farmer2 hand:{}'.format(sorted(self.board_state.get_hands(FARMER_TWO))))

    def start_game(self):
        print('***GAME START***')
        while not self.board_state.is_terminal:
            turn = self.board_state.turn
            action = None
            if turn == FARMER_ONE:
                action = self._farmer_one.get_action(self.board_state)
                print('farmer1 plays {0}'.format(action))
            if turn == FARMER_TWO:
                action = self._farmer_two.get_action(self.board_state)
                print('farmer2 plays {0}'.format(action))
            if turn == LANDLORD:
                action = self._landlord.get_action(self.board_state)
                print('landlord plays {0}'.format(action))
            self.board_state = self.board_state.next_state(action)
            # print('hands left landlord: {0}'.format(sorted(self.board_state.hands[LANDLORD])))
            # print('hands left farmer one: {0}'.format(sorted(self.board_state.hands[FARMER_ONE])))
            # print('hands left farmer two: {0}'.format(sorted(self.board_state.hands[FARMER_TWO])))
        print('*** GAME OVER, {0} WIN ***'.format(self.board_state.winner))
Пример #2
0
 def start_game(farmer_agent,
                landlord_agent,
                farmer_policy,
                landlord_policy,
                f,
                lunci,
                landlord_depth=None,
                farmer_depth=None):
     print('***GAME START***')
     board_state = GameBoardData()
     LandlordAgents = getattr(landlord_agents, landlord_agent)
     FarmerAgents = getattr(farmer_agents, farmer_agent)
     if landlord_agent == MCT_AGENT:
         landlord = LandlordAgents(LANDLORD, landlord_policy)
     else:
         landlord = LandlordAgents(LANDLORD,
                                   landlord_policy,
                                   depth=landlord_depth)
     if farmer_agent == MCT_AGENT:
         farmer_one = FarmerAgents(FARMER_ONE, farmer_policy)
         farmer_two = FarmerAgents(FARMER_TWO, farmer_policy)
     else:
         farmer_one = FarmerAgents(FARMER_ONE,
                                   farmer_policy,
                                   depth=farmer_depth)
         farmer_two = FarmerAgents(FARMER_TWO,
                                   farmer_policy,
                                   depth=farmer_depth)
     while not board_state.is_terminal:
         turn = board_state.turn
         action = None
         if turn == FARMER_ONE:
             action = farmer_one.get_action(board_state)
             print('farmer1 plays {0}'.format(action))
         if turn == FARMER_TWO:
             action = farmer_two.get_action(board_state)
             print('farmer2 plays {0}'.format(action))
         if turn == LANDLORD:
             action = landlord.get_action(board_state)
             print('landlord plays {0}'.format(action))
         board_state = board_state.next_state(action)
     #print('*** GAME {1} OVER, {0} WIN ***'.format(board_state.winner,lunci))
     print("\033[31;1m  *** GAME {1} OVER, {0} WIN ***  \033[0m".format(
         board_state.winner, lunci))
     winner = 'landlord'
     if board_state.winner in [FARMER_ONE, FARMER_TWO]:
         winner = 'farmer'
     f.write('[landlord]{0}-{1}-{2}::[farmer]{3}-{4}-{5}::[winner]{6}||\n'.
             format(landlord_agent, landlord_policy, landlord_depth,
                    farmer_agent, farmer_policy, farmer_depth, winner))
Пример #3
0
 def __init__(self):
     self.board_state = GameBoardData()
     self._landlord = None
     self._farmer_one = None
     self._farmer_two = None
     self._players = None