GithubHelp home page GithubHelp logo

fighting-ants's Introduction

Fighting Ants

Full description of the task.

General implemntation idea

Basic notes taken during development.

Initial thoughts

  • want to use mappings to have quick lookups as well as O(1) add or removals at a specific index of Colonies or Ants
  • ants dont belong to colonies they just freeroam so dont need to assign them any information besides their current location
  • easiest to just use index number for ants id
  • ants also want O(1) removal at index
  • ants might get stranded on land and land might lose all of its neighbours this is ok
  • when removing a Colony after a war their will be a floating connection unless you clean up the ants previous locations
  • more than 1 ant can move to the same Colony (more of an assumption) but just going to assume there can also be more than 1 ant involved in a war

Steps;

  1. Construct world The world will contain a mapping from Colony -> ColonyState as well as a list of Ants
    type Colony = string

    type ColonyState = {
        north: string | undefined,
        south: string | undefined,
        east: string | undefined,
        west: string | undefined,
    }

    type Ant = {
        location: Colony
    }

    type World {
        state: Map<Colony, ColonyState>,
        ants: Ant[]
    }
  1. Each round will move the ants randomly. Available directions are non undefined values, as well truthy values for state.get(direction) (this avoids taking the path to a dangling Colony). Move an ant, when more than one ant is marked at a location we will remove that location from the World.state // no need to follow the paths back to the ants previous location since we can just remove once we get to it in cleanup / write stage // This approach has a worse time complexity since at the end I have to loop through M remaining colonies and clean them

  2. Continue step two until all the ants are dead or there have been 10k iterations

  3. Print out the remaining state of the world // remember to clean up the dangling Colonies if not done in step 2

TS Solution

// install packages
yarn install

// run simulation
yarn simulate <NUM_ANTS> <WORLD_FILE_PATH>

// eg
yarn simulate 100 ./worlds/hiveum_map_medium.txt

Remaining output of world gets sent to ./worlds/remainder.txt

RS Solution

cargo run --manifest-path="./rs/Cargo.toml" <NUM_ANTS> <WORLD_FILE_PATH>
// eg
cargo run --manifest-path=\"./rs/Cargo.toml\" 100 ./worlds/hiveum_map_small.txt

// or 
yarn simulate-rs <NUM_ANTS> <WORLD_FILE_PATH>
// eg
yarn simulate-rs 100 ./worlds/hiveum_map_small.txt

Assumptions

Input file

  • north/south/east/west are space seperated
  • no directions exist outside of north/south/east/west

World Generation

  • Ants are placed randomly amongst the colonies and can start in the same colony
  • More than one ant can start in the same place, they dont kill eachother straight away
  • There are no Ant teams, they fight for themselves, they have no loyalty
  • Isolated colonies are fine

fighting-ants's People

Contributors

dospore avatar

Watchers

 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.