Giter Site home page Giter Site logo

conway's Introduction

Conway's Game of Life

This is a typescript implementation transpiled to JS using Parcel (https://parceljs.org).

Install

Install Parcel with:

yarn global add parcel-bundler

and install requirements with:

yarn install

Run

To run the code:

parcel index.html

Tests:

yarn test

Implementation

Each Point object is aware of:

  • its coordinates
  • wheather or not it is selected
  • its neighbor's coordinates

CachedPoints holds a lookup Object who's keys are the coordinates of the Points & values are the Points themselves.

index.ts is the entry point for the application, bridging (and creating) the DOM with the cache logic:

  • addPoint adds a point with initial state to the cache.
  • syncUi updates the DOM's representation of the current state of the Universe. Every 500 frames the application pauses to allow for examination.
  • perform implements the rules of the game & is recursively called as quickly as possible using a setTimeout with no delay.

*_spec.ts hold some basic tests run with karma and karma-jasmine

Benchmarking History

  • 500 frames, 62839ms
  • optimization 1 (use raw list in perform method)
  • 500 frames, 59633ms
  • optimization 2 remove a lookup
  • 500 frames, 60305ms
  • optimization 3 don't serialize json on every frame
  • 500 frames, 57464ms
  • Moved to the hash lookup
  • 500 frames, 9750ms
  • Leave items in lookup hash, smarter about when to query for DOM nodes
  • 500 frames, 7073ms

Performance Profile

conway's People

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.