Giter VIP home page Giter VIP logo

hive-rushes-gol's Introduction

hive-rushes-gol

Small Game of Life challenge.

This was a 48h timed project at Hive coding school, in June 2022. Unfortunately I couldn't participate at the time, but wanted to check it out anyways.

Goal

Write working version of Game of Life and then try to optimize it as much as possible.

In the end there should be at least two versions of the binary present, one optimized and one not, to prove the difference.

Project description

Instructions

  • any language
  • no third party libraries
  • we assume input file to be valid
  • usage ./life initial_state iterations (binary name can vary)
  • print out state after iterations from the given initial_state
  • printout identical to initial_state

File format

  • text file
  • one or more lines
  • every line is same length (at least 1) and ends with \n
  • lines contain only . for dead cell and X for live cell

Boundaries

  • output is the same size as input
  • each cell outside boundaries is dead and remains dead

Bonuses

  • GUI (can use 3rd party libs)
  • Infinite world
  • Rulestring

My implementations

The most basic implementation with no designed optimizations to complete the project according to instructions.

Only optimizations involved were in standard cargo build --release compilation settings.

According to flamegraph the simple version spent 93% of the time in neighbours_count()[line 25]. So this version tries to iprove that.

The improvement was achieved by padding the board with always false "frame" and using 2D array (1D would work too, but the benefits are doubtful. Maybe for future version). This way we can ommit boundary checking and simply unroll the 'neighbours_count()' loop. Additionally, the field representation was changed to u8 per cell from bool in order to save on some casting (this change is speculative whether it brought any improvements).

Double buffer version that seemed to make little to no difference on my machine.

Implementation created by exrok and included here only for educational purposes. So blazing fast! Bitboards and bit twiddling like this is increadibly smart.

hive-rushes-gol's People

Contributors

jiricodes avatar

Watchers

James Cloos 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.