Ejemplo n.º 1
0
    def step(self, state, player_id):

        cardstr, one_last, two_last, three_last, legal_card = numpytostr(state)

        curreny_hand = rltorh(cardstr)
        one_last_hand = rltorh(one_last)
        two_last_hand = rltorh(two_last)
        three_last = rltorh(three_last)

        upcard = []

        if self.num == 0:
            if len(two_last_hand) == 0:
                upcard = three_last
            else:
                upcard = two_last_hand
        else:
            if len(one_last_hand) != 0:
                upcard = one_last_hand
            elif len(one_last_hand) == 0 and len(two_last_hand) != 0:
                upcard = two_last_hand

        putcard = to_char(
            CEnv.step_auto_static(Card.char2color(curreny_hand),
                                  to_value(upcard)))
        putcard = rhtorl(putcard)
        #print("player:", player_id, "手牌 is:", cardstr, "上一局:", upcard,"出牌:",putcard)
        self.num = self.num + 1
        return putcard
Ejemplo n.º 2
0
    def step(self,state,player_id):
        s = np.array(state['obs'])

        cardstr, one_last, two_last, three_last, legal_card = numpytostr(state)

        curreny_hand = rltorh(cardstr)

        values = CEnv.get_cards_ass(Card.char2color(curreny_hand))

        type,mymax,num = values[0],values[1],values[2]

        actionzong = cardcouple(type,mymax,num)

        for ca in actionzong:
            print("组合牌面::::",ACTION_ID_TO_STR[ca])

        hou_legal_action  = []
        if 308 in  state["legal_actions"]:
            hou_legal_action.append(308)
            for a in actionzong:
                if a in state["legal_actions"]:
                    hou_legal_action.append(a)
        else:
            hou_legal_action = actionzong

        hou_legal_action = sorted(hou_legal_action)

        #action = self.anet.choose_action(np.expand_dims(s, 0),hou_legal_action)

        action = hou_legal_action[0]

        print("---玩家:#", player_id, "#手牌是:", cardstr)
        print("---出牌:", ACTION_ID_TO_STR[action], "id:", action)
        return int(action)
Ejemplo n.º 3
0
    def step(self, state, player_id):

        s = np.array(state['obs'])
        action = self.lnet.choose_action(np.expand_dims(s, 0),
                                         state["legal_actions"], 0)[0]
        cardstr, one_last, two_last, three_last, legal_card = numpytostr(state)
        print("player:", player_id, "手牌 is:", cardstr)
        #print("出牌:",ACTION_ID_TO_STR[action],"id":action)
        return int(action)
Ejemplo n.º 4
0
    def step(state, player_id):
        cardstr, one_last, two_last, three_last, legal_card = numpytostr(state)
        #print("player:", player_id, "手牌 is:", cardstr)
        ''' Predict the action given the curent state in gerenerating training data.

        Args:
            state (numpy.array): an numpy array that represents the current state

        Returns:
            action (int): the action predicted (randomly chosen) by the random agent
        '''
        return int(np.min(state['legal_actions']))
Ejemplo n.º 5
0
    def step(self, state, player_id):

        s = np.array(state['obs'])

        zhuaction = self.lnet.choose_action(
            np.expand_dims(self.normalizer.normalize(s), 0),
            state["legal_actions"])

        cardstr, one_last, two_last, three_last, legal_card = numpytostr(state)
        print("player:", player_id, "手牌 is:", cardstr)
        print("出牌:", ACTION_ID_TO_STR[zhuaction], "id:", zhuaction)

        return int(zhuaction)
Ejemplo n.º 6
0
    def step(state, player_id):
        cardstr, one_last, two_last, three_last, legal_card = numpytostr(state)
        #print("player:", player_id, "手牌 is:", cardstr)
        ''' Predict the action given the curent state in gerenerating training data.

        Args:
            state (numpy.array): an numpy array that represents the current state

        Returns:
            action (int): the action predicted (randomly chosen) by the random agent
        '''

        action = np.min(state['legal_actions'])

        print("---玩家:#", player_id, "#手牌是:", cardstr)
        print("---出牌:", ACTION_ID_TO_STR[action], "id:", action)
        return int(action)