Skip to content

Commit

Permalink
Register doudizhu model and fix perfect information game
Browse files Browse the repository at this point in the history
Former-commit-id: 776a169
  • Loading branch information
daochenzha committed May 11, 2020
1 parent 21ea714 commit 2467280
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion rlcard/envs/doudizhu.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,6 @@ def get_perfect_information(self):
state['hand_cards'] = [cards2str(player.current_hand) for player in self.game.players]
state['landlord'] = self.game.state['landlord']
state['trace'] = self.game.state['trace']
state['curent_player'] = self.game.round.current_player
state['current_player'] = self.game.round.current_player
state['legal_actions'] = self.game.state['actions']
return state
2 changes: 1 addition & 1 deletion rlcard/envs/simpledoudizhu.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,6 @@ def get_perfect_information(self):
state['hand_cards'] = [cards2str(player.current_hand) for player in self.game.players]
state['landlord'] = self.game.state['landlord']
state['trace'] = self.game.state['trace']
state['curent_player'] = self.game.round.current_player
state['current_player'] = self.game.round.current_player
state['legal_actions'] = self.game.state['actions']
return state
4 changes: 4 additions & 0 deletions rlcard/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
model_id = 'limit-holdem-rule-v1',
entry_point='rlcard.models.limitholdem_rule_models:LimitholdemRuleModelV1')

register(
model_id = 'doudizhu-rule-v1',
entry_point='rlcard.models.doudizhu_rule_models:DouDizhuRuleModelV1')

register(
model_id='gin-rummy-novice-rule',
entry_point='rlcard.models.gin_rummy_rule_models:GinRummyNoviceRuleModel')
4 changes: 4 additions & 0 deletions tests/envs/test_doudizhu_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,9 @@ def test_decode_action(self):
decoded = env._decode_action(29)
self.assertEqual(decoded, '444')

def test_get_perfect_information(self):
env = rlcard.make('doudizhu')
_, player_id = env.reset()
self.assertEqual(player_id, env.get_perfect_information()['current_player'])
if __name__ == '__main__':
unittest.main()
4 changes: 4 additions & 0 deletions tests/envs/test_simpledoudizhu_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,9 @@ def test_decode_action(self):
decoded = env._decode_action(14)
self.assertEqual(decoded, '888')

def test_get_perfect_information(self):
env = rlcard.make('simple-doudizhu')
_, player_id = env.reset()
self.assertEqual(player_id, env.get_perfect_information()['current_player'])
if __name__ == '__main__':
unittest.main()
4 changes: 4 additions & 0 deletions tests/envs/test_uno_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,9 @@ def test_single_agent_mode(self):
for _ in range(100):
state, _, _ = env.step(np.random.choice(state['legal_actions']))

def test_get_perfect_information(self):
env = rlcard.make('uno')
_, player_id = env.reset()
self.assertEqual(player_id, env.get_perfect_information()['current_player'])
if __name__ == '__main__':
unittest.main()

0 comments on commit 2467280

Please sign in to comment.