GithubHelp home page GithubHelp logo

gym-cribbage's Introduction

gym-cribbage

An environment for playing Cribbage in OpenAI gym (2-4 players).

setup

The gym environment can be installed using python setup.py install.

development

Run pip install -e ..

usage

The environment can be imported after install via:

from gym_cribbage.envs.cribbage_env import CribbageEnv
env = CribbageEnv(n_players=2, verbose=False)

Where n_players can be between 2-4 and verbose can be set to True for (copius) debug information.

The environment can be initalized via:

state, reward, done, debug = env.reset()

Which starts a new game. The environment can be interacted with as a standard openAI gym environment, I.e., env.step(), env.render() and env.reset().

The state returned by the environment contains a State() object with the following fields:

  • State.hand -- the current player's playable cards. Non-playable cards are never returned in the hand.
  • State.hand_id -- the ID of the current player.
  • State.reward_id -- the ID of the player who recieves the reward returned by the environment.
  • State.phase -- the current phase of the game. 0 == 'the Deal', 1 == 'the Play', 2 = 'the Show'.
  • State.player_score -- the current score (out of 121) of the current player.
  • State.opponent_score -- a list of all opponent scores (out of 121).

The cribbage environment cycles through hands an accumulates scores until one player reaches 121, whereby the environment immediately returns done==True and the game is over. A new game can be started via state, reward, done, debug = env.reset().

Actions taken during steps have different meaning during each phase of the game.

  • During 'the Deal' (State.phase == 0), cards submitted via env.step(Card) are discarded to the crib. Cards must be taken from the player's hand State.hand[i].
  • During 'the Play' (State.phase == 1), cards submitted via env.step(Card) are played to the table to earn points. Again, the must be taken from the player's hand State.hand[i].
  • During 'the Show' (State.phase == 2), nothing submitted is used by the environment. Therefore it is convienient to pass a 'dummy card' to the environment state, reward, done, debug = env.step(Card(99, SUITS[0])), which can be easily done if one imports some utility classes from cribbage_env: from gym_cribbage.envs.cribbage_env import Card, SUITS. The purpose of these steps is to return the appropriate points to each agent for Show (in sequence, following the rules of Cribbage).

Rules

https://en.wikipedia.org/wiki/Cribbage

gym-cribbage's People

Contributors

gbmarc1 avatar josephdviviano avatar atremblay avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.