Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Snake

The game of snake. Made with Phaser.

Observations are the pixels of the game of default size [640, 480, 3];

Game code adapted from https://labs.phaser.io/view.html?src=src\games\snake\part7.js

example
import {Snake} from "gym-js";
const env = new Snake();

console.log(env.action_space.toString());
>
console.log(env.observation_space.toString());
>

let action = env.action_space.sample();
let [obs, rew, done, info] = env.step(action);

Hierarchy

  • any
    • Snake

Implements

Index

Constructors

constructor

  • new Snake(config: any): Snake
  • Parameters

    • config: any

      A configuration object, detailing the game settings. See the default config below.

    Returns Snake

Properties

Private _checkDone

_checkDone: any

Private _getObs

_getObs: any

Private _getReward

_getReward: any

Private _setAction

_setAction: any

action_space

action_space: Space

Possible Actions:

  1. left
  2. up
  3. right
  4. down The snake is not able to move opposite its current direction.

done

done: boolean

info

info: __type

observation_space

observation_space: Space

The pixel values of the game (640x480).

renderDisplay

renderDisplay: boolean

reward_range

reward_range: Space

The value of eating the food:

  • +1 for eating food
  • -1 for crashing into itself
  • 0 else

verbose

verbose: boolean

Methods

close

  • close(removeCanvas?: boolean): void
  • Parameters

    • Optional removeCanvas: boolean

    Returns void

render

  • render(value?: boolean): void
  • Parameters

    • Optional value: boolean

    Returns void

reset

  • reset(): tf.Tensor
  • Returns tf.Tensor

seed

  • seed(seed: number): void
  • Parameters

    • seed: number

    Returns void

step

  • step(action: number): [tf.Tensor, number, boolean, __type]
  • step(time: number, delta: number, action: number): [tf.Tensor, number, boolean, __type]
  • Parameters

    • action: number

    Returns [tf.Tensor, number, boolean, __type]

  • Parameters

    • time: number
    • delta: number
    • action: number

    Returns [tf.Tensor, number, boolean, __type]

Generated using TypeDoc