def run(self): k = self.kwargs.pop('k', 1) exist_card = HandCardUtils.find_even_three(self.hand_card_status, k=k) if self.primary_item is not None: exist_card = list( filter(lambda x: x > self.primary_item, exist_card)) if len(exist_card) == 0: logger.debug('Can not accept the card') return None, None, None rnd = random.randint(0, len(exist_card) - 1) one_card = exist_card[rnd] exist_card = [one_card - ix for ix in reversed(range(k))] remain_card = self.__flat_card(self.hand_card_status, exist_card) if len(remain_card) < k: logger.debug('Can not accept the card') return None, None, None other_card = sorted(random.sample(remain_card, k)) score = HandCardUtils.value_map(exist_card[-1], CardTypeEnum.CT_THREE_DOU, 3 * k + 2 * k) put_card = list(map(lambda x: [x] * 3, exist_card)) put_card = np.reshape(put_card, (1, -1)).tolist()[0] other_card = list(map(lambda x: [x] * 2, other_card)) other_card = np.reshape(other_card, (1, -1)).tolist()[0] put_card.extend(other_card) return put_card, score, exist_card[-1]
def run(self): qu_ja = [CardEnum.QU.value, CardEnum.JA.value] comm_bomb = list( map(lambda x: x[0], filter(lambda x: x[1] == 4, enumerate(self.hand_card_status)))) master_bomb = list( map( lambda x: x[0], filter(lambda x: x[0] in qu_ja and x[1] == 1, enumerate(self.hand_card_status)))) if self.primary_item: comm_bomb = list(filter(lambda x: x > self.primary_item, comm_bomb)) if len(comm_bomb) == 0 and len(master_bomb) < 2: logger.debug('Can not accept the card') return None, None, None comm_bomb.append('master') rnd = random.randint(0, len(comm_bomb) - 1) one_card = comm_bomb[rnd] if one_card == 'master': put_card = qu_ja score = HandCardUtils.value_map(put_card[-1], CardTypeEnum.CT_BOMB, 2) return put_card, score, put_card[-1] put_card = [one_card] * 4 score = HandCardUtils.value_map(put_card[-1], CardTypeEnum.CT_BOMB, 4) return put_card, score, put_card[-1]
def run(self): k = self.kwargs.pop('k', 5) exist_card = HandCardUtils.find_continues(self.hand_card_status, k=k) if self.primary_item is not None: exist_card = list(filter(lambda x:x > self.primary_item,exist_card)) if len(exist_card) == 0: logger.debug('Can not accept the card') return None, None, None rnd = random.randint(0,len(exist_card)-1) one_card = exist_card[rnd] put_card = [one_card - ix for ix in reversed(range(k))] score = HandCardUtils.value_map(put_card[-1], CardTypeEnum.CT_CONTINUE, k) return put_card, score, put_card[-1]
def run(self): k = self.kwargs.pop('k', 1) exist_card = HandCardUtils.find_even_three(self.hand_card_status, k=k) if self.primary_item is not None: exist_card = list(filter(lambda x:x > self.primary_item,exist_card)) if len(exist_card) == 0: logger.debug('Can not accept the card') return None, None, None rnd = random.randint(0,len(exist_card)-1) one_card = exist_card[rnd] exist_card = [one_card - ix for ix in reversed(range(k))] score = HandCardUtils.value_map(exist_card[-1], CardTypeEnum.CT_THREE, 6) put_card = list(map(lambda x:[x]*3, exist_card)) put_card = np.reshape(put_card, (1, -1)).tolist()[0] return put_card, score, exist_card[-1]
def __agent(self): # initialize three player lo = Player('player-01', role=PlayerRoleEnum.LAND_OWNER) ulo = Player('player-02', role=PlayerRoleEnum.UP_LAND_OWNER) llo = Player('player-03', role=PlayerRoleEnum.LOW_LAND_OWNER) lo_cards = lo.obtain_init_card() exclude_card = copy.deepcopy(lo_cards) ulo_cards = ulo.obtain_init_card(exclude_card=exclude_card) exclude_card.extend(ulo_cards) llo_cards = llo.obtain_init_card(exclude_card=exclude_card) lo_cards = list(map(lambda x: x[1], lo_cards)) ulo_cards = list(map(lambda x: x[1], ulo_cards)) llo_cards = list(map(lambda x: x[1], llo_cards)) logger.info(f'Land owner cards: {lo_cards}') logger.info(f'Upper land owner cards: {ulo_cards}') logger.info(f'Lower land owner cards: {llo_cards}') lo_card_status = HandCardUtils.obtain_hand_card_status(lo_cards) ulo_card_status = HandCardUtils.obtain_hand_card_status(ulo_cards) llo_card_status = HandCardUtils.obtain_hand_card_status(llo_cards) return lo_card_status, ulo_card_status, llo_card_status
def test_data(): player = Player('agent', role=PlayerRoleEnum.LAND_OWNER) player_cards = player.obtain_init_card() player_cards = list(map(lambda x: x[1], player_cards)) logger.info(f'player cards: {player_cards}') player_card_status = HandCardUtils.obtain_hand_card_status(player_cards) desk_card_status = [0] * 18 role_onehot = [1, 0, 0] state = [] state.extend(player_card_status) state.extend(desk_card_status) state.extend(role_onehot) pre_put_cards = None return state, pre_put_cards
def run(self): exist_card = list( map(lambda x: x[0], filter(lambda x: x[1] >= 1, enumerate(self.hand_card_status)))) if self.primary_item is not None: exist_card = list( filter(lambda x: x > self.primary_item, exist_card)) if len(exist_card) == 0: logger.debug('Can not accept the card') return None, None, None rnd = random.randint(0, len(exist_card) - 1) put_card = exist_card[rnd] score = HandCardUtils.value_map(put_card, CardTypeEnum.CT_ONE, 1) return [put_card], score, put_card
def __preprocess(self, pre_put_cards, hand_card_status): env = Env(hand_card_status, hand_card_status, hand_card_status) pre_action, pre_primary_item = None, None if pre_put_cards: pre_card_status = HandCardUtils.obtain_hand_card_status( pre_put_cards) for act in ALL_ACTIONS: is_valid, put_cards, pre_primary_item = env.check_action( pre_card_status, act) if is_valid and \ np.sum(np.equal(pre_put_cards, put_cards)) == len(pre_put_cards): pre_action = act break available_actions, available_put_cards = self.__obtain_actions( env, hand_card_status, pre_action, pre_primary_item) return available_actions, available_put_cards
def run(self): exist_card = list(map(lambda x:x[0], filter(lambda x: x[1] == 4, enumerate(self.hand_card_status)))) if self.primary_item is not None: exist_card = list(filter(lambda x:x > self.primary_item,exist_card)) if len(exist_card) == 0: logger.debug('Can not accept the card') return None, None, None rnd = random.randint(0,len(exist_card)-1) one_card = exist_card[rnd] remain_card = self.__flat_card(self.hand_card_status, [one_card]) if len(remain_card) <= 1: logger.debug('Can not accept the card') return None, None, None other_card = sorted(random.sample(remain_card, 2)) score = HandCardUtils.value_map(one_card, CardTypeEnum.CT_FOUR_ONE, 6) put_card = [one_card]*4 put_card.extend(other_card) return put_card, score, one_card