Code Monkey home page Code Monkey logo

gridworld-visualizer's Introduction

gridworld-visualizer

This is a small library for visualizing gridworlds by generating svgs styled and animated by css. The api of gridworld-visualizer centers around the gridworld function.

gridworld(n=10, actions=None, tile2classes=None, extra_css="") -> SVG

which takes in the dimension of the gridworld (currently assumed to be a square n x n), the sequence of actions (currently support moving in the cardinal directions), and a function

tile2classes(x: int, y: int) -> str

which given a grid cell (x, y) returns a string for its type. Currently, the default styling supports, "water", "recharge", "dry", "lava", and "normal". As these types just correspond to css classes, one can add additional styling using the extra_css option.

Example

Below we generate the gridworld from at the top of the page, (originally from Vazquez-Chanlatte, Marcell, et al. "Learning Task Specifications from Demonstrations.").

import gridworld_visualizer as gv


def tile2classes(x, y):
    if (3 <= x <= 4) and (2 <= y <= 5):
        return "water"
    elif (x in (0, 7)) and (y in (0, 7)):
        return "recharge"
    elif (2 <= x <= 5) and y in (0, 7):
        return "dry"
    elif x in (1, 6) and (y in (4, 5) or y <= 1):
        return "lava"
    elif (x in (0, 7)) and (y in (1, 4, 5)):
        return "lava"

    return "normal"

actions = [gv.E, gv.N, gv.N, gv.N, gv.N, gv.W, gv.W, gv.W]
svg = gv.gridworld(n=8, tile2classes=tile2classes, actions=actions)
svg.saveas("example.svg", pretty=True)

gridworld-visualizer's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  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.