Add suit in doudizhu replay
This commit is contained in:
parent
2a045c3fb2
commit
4d3e087c33
|
@ -72,15 +72,19 @@ def doudizhu_tournament(game, agents, names, num):
|
|||
state, player_id = env.reset()
|
||||
perfect = env.get_perfect_information()
|
||||
data['initHands'] = perfect['hand_cards_with_suit']
|
||||
current_hand_cards = perfect['hand_cards_with_suit'].copy()
|
||||
for i in range(len(current_hand_cards)):
|
||||
current_hand_cards[i] = current_hand_cards[i].split()
|
||||
data['moveHistory'] = []
|
||||
while not env.is_over():
|
||||
action, probs = env.agents[player_id].eval_step(state)
|
||||
history = {}
|
||||
history['playerIdx'] = player_id
|
||||
if env.agents[player_id].use_raw:
|
||||
history['move'] = action
|
||||
_action = action
|
||||
else:
|
||||
history['move'] = env._decode_action(action)
|
||||
_action = env._decode_action(action)
|
||||
history['move'] = _calculate_doudizhu_move(_action, player_id, current_hand_cards)
|
||||
|
||||
data['moveHistory'].append(history)
|
||||
state, player_id = env.step(action, env.agents[player_id].use_raw)
|
||||
|
@ -94,6 +98,23 @@ def doudizhu_tournament(game, agents, names, num):
|
|||
payoffs.append(env.get_payoffs()[0])
|
||||
return json_data, payoffs, wins
|
||||
|
||||
def _calculate_doudizhu_move(action, player_id, current_hand_cards):
|
||||
if action == 'pass':
|
||||
return action
|
||||
trans = {'B': 'BJ', 'R': 'RJ'}
|
||||
cards_with_suit = []
|
||||
for card in action:
|
||||
if card in trans:
|
||||
cards_with_suit.append(trans[card])
|
||||
current_hand_cards[player_id].remove(trans[card])
|
||||
else:
|
||||
for hand_card in current_hand_cards[player_id]:
|
||||
if hand_card[1] == card:
|
||||
cards_with_suit.append(hand_card)
|
||||
current_hand_cards[player_id].remove(hand_card)
|
||||
break
|
||||
return ' '.join(cards_with_suit)
|
||||
|
||||
def leduc_holdem_tournament(game, agents, num):
|
||||
env = rlcard.make(game, config={'allow_raw_data': True})
|
||||
env.set_agents(agents)
|
||||
|
@ -147,6 +168,7 @@ def leduc_holdem_tournament(game, agents, num):
|
|||
payoffs.append(env.get_payoffs()[0])
|
||||
return json_data, payoffs, wins
|
||||
|
||||
|
||||
if __name__=='__main__':
|
||||
game = 'leduc-holdem'
|
||||
model_ids = ['leduc-holdem-random', 'leduc-holdem-rule-v1', 'leduc-holdem-cfr']
|
||||
|
|
Loading…
Reference in New Issue