gym-hearts

OpenAI Gym Hearts Environment for Reinforcement Learning


License
MIT
Install
pip install gym-hearts==0.0.3

Documentation

Gym Hearts

This is an experimental library for hearts poker game and reinforment learning. I implement the library and run it at ubuntu and mac by python3. If you encounter any problem, feel free to create new issue on this project 😄

Implemented Rules

  1. All heart cards ( 2♥, 3♥, …., Q♥, K♥, A♥ ) cost 1 score
  2. Qâ™  costs 13 score
  3. This trick’s looser will be next trick’s first player
  4. Shooting the moon
  5. The player holding 2♣ must lead it to begin the first trick
  6. Hearts cannot be led until they have been "broken"

Installation

pip3 install gym-hearts

Hello World

import gym
from gymhearts import env as hearts_env
from gymhearts import strategy


class HelloStrategy(strategy.IStrategy):

    def move(self, observation):
        action = observation['valid_hand_cards'][0]
        return action


env = hearts_env.HeartsEnv()
env.enable_shooting_the_moon()
env.add_player(HelloStrategy())
env.add_player(HelloStrategy())
env.add_player(HelloStrategy())
env.add_player(HelloStrategy())
env.start()
env.render()
observation = env.get_observation()
done = False
while not done:
    action = env.move()
    observation, reward, done, info = env.step(action)
    env.render()

Observation

{
  "trick": 12, 
  "round": 9, 
  "number_of_players": 4, 
  "scores": [50, 104, 40, 40], 
  "playing_cards": [69634, 2102541, 541447], 
  "playing_ids": [3, 0, 1], 
  "hand_cards": [529159], 
  "current_player_id": 2, 
  "valid_hand_cards": [529159], 
  "number_of_hand_cards_for_all_players": [0, 0, 1, 0]
 }

Render

--------GAME-------
round: 9
trick: 11
heart broken: True
-------PLAYER------
player 0
[7â™ ]
score: 50
player 1
[5♦]
score: 104
player 2
[5â™ ] [Tâ™ ]
score: 40
player 3
[2â™ ]
score: 40
--------BOARD-------
[9♠] [3♦] [] [8♦]
--------------------