A command line util created to simulate an alien invasion described in the task

Alien Invasion Simulation

A command line util created to simulate an alien invasion described in the task.

Requirements

  • Go 1.17
  • Graphviz (optional)

Usage

Build

$ go build -o alien-invasion main.go

Test

$ go test -v -cover ./...

Generate a map

The process of the generation is following:

  1. A grid of size height x width is created.
  2. Provided number of cities is randomly placed on the grid.
  3. If two cities are in the same row (west or east from each other) or column (north or south from each other) and there are no other cities between them, a road is created.

Additionally a dot format graph can be generated to visualize a map.

$ ./alien-invasion generate -h
Generate a world map

Usage:
  alien-invasion generate [output map file] [flags]

Flags:
  -c, --cities int   cities count (default 20)
  -d, --dot string   output dot file (graphviz format)
      --height int   grid height (default 5)
  -h, --help         help for generate
      --width int    grid width (default 5)

Run a simulation

Simulation uses a generated map. The first step is to pick random a random location for each alien. More than one alien can be placed in a city. If such situation occurs, the city is destroyed along with the aliens before they start to move. In every iteration all aliens move to a new location by following links (if not trapped in a city) at the same time. Simulation rules are enforced as a next step. The simulation is finished after a specified iteration limit or when there are not aliens or cities left.

$ ./alien-invasion run -h
Run simulation

Usage:
  alien-invasion run [input map file] [flags]

Flags:
  -a, --aliens int       aliens count (default 50)
  -h, --help             help for run
  -i, --iterations int   iterations limit (default 10000)
  -o, --output string    output world map file (printed to STDOUT by default)

Analyze the simulation result

The simulation result can be visualized by Graphviz. Analyze command can be used to generate a graph with destroyed cities marked red. It is done by compering the initial map to the result maps and adjusting the initial dot graph.

$ ./alien-invasion analyze -h
Generate a graph in dot format from the simulation result with destroyed cities marked red.

Usage:
  alien-invasion analyze [initial map file] [result map file] [initial dot file] [output dot file] [flags]

Flags:
  -h, --help   help for analyze

Complete example

The first step is to generate a map. Additionally the generate command can create a graph in dot format, which can be visualized using Graphviz. This step can be accomplished by running:

./alien-invasion generate world.map --dot world.dot --height 4 --width 4 --cities 12

Content of world.map file will be similar to:

$ cat world.map
Anvik south=Fabens east=Martinsburg
Hatch south=Jacobson west=Martinsburg
Keystone south=Pinson east=Steprock west=Fabens
Steprock north=Martinsburg south=Clifton east=Jacobson west=Keystone
Jacobson north=Hatch south=Talihina west=Steprock
Martinsburg south=Steprock east=Hatch west=Anvik
Fabens north=Anvik south=Hardtner east=Keystone
Hardtner north=Fabens south=Amchitka east=Pinson
Pinson north=Keystone east=Talihina west=Hardtner
Talihina north=Jacobson west=Pinson
Amchitka north=Hardtner east=Clifton
Clifton north=Steprock west=Amchitka

Optionally the map can be visualized by Graphviz by running:

$ dot -Tpng world.dot > world.png

Generated world.png will look similar to: title

The next step is to run the actual simulation:

$ ./alien-invasion run world.map --aliens 24 --output result.map
Alien invasion started!
Fabens has been destroyed by Gokvor-Wicqu Rubwe, Piiz'Roof Qaafhus and Boygu-Zuk Kol!
Jacobson has been destroyed by Veemza'Coogku Wiizzaq and Pujqi Rucbuv Kaqji!
Martinsburg has been destroyed by Maauwef'Kuun Tiiklum and Yeefdov-Liifge Wiimrux!
Clifton has been destroyed by Ham-Wefqon Xuqqek and Raadzuc-Yiikheu Voow!
Anvik has been destroyed by Diuse'Uoclu Bulvi and Palbu'Bir Paxra!
Pinson has been destroyed by Seemfas-Caaltih Seem, Uel'Puknof Rog, Xad'Fecye Kodva and Siijuu'Boomnaq Peen!
Talihina has been destroyed by Diuse-Likwo Javda and Pecgad'Niqbej Livqic!
Hatch has been destroyed by Zaance Vooqfe Ueehmuv and Gibpof'Tut Ronxuj!
Keystone has been destroyed by Pucva'Vim Yac and Qiix Yiix Neezva!
Alien invasion finished!

Content of result.map file represents a partially destroyed world map after running the simulation:

$ cat result.map 
Hardtner south=Amchitka
Amchitka north=Hardtner
Steprock

Optionaly the partially destroyed world map can be visualized by Graphviz by running:

$ ./alien-invasion analyze world.map result.map world.dot result.dot \
    && dot -Tpng result.dot > result.png

Generated result.png will look similar to: title

Notes

  • A predefined set of 10000 city names is used by the map generator (source).
  • City names in the input maps cannot contain whitespaces.
  • A predefined set of 75 alien names in used by the simulation (source). For a greater count aliens are named Alien 1, Alien 2 etc.
  • A full validation of the user input is missing.
  • Test were created to outline the approach and only cover fraction of simulation functionality. generate and analyze commands do not have tests (functionality not in the scope of task).
  • Unix nano timestamp is used as a random seed. In order to be able to precisely execute advanced test scenarios of the simulation, random number generation should be injected as a dependency (mock used in tests).
Similar Resources

Go cmd util that prints cmd-line args with their index

echoidx This is an exercise of the book The Go Programming Language, by Alan A.

Dec 18, 2021

Task Timer (tt) is a dead simple TUI task timer

Task Timer (tt) is a dead simple TUI task timer

tasktimer Task Timer (tt) is a dead simple TUI task timer Usage To get started, just run tt: tt You'll be presented with something like this: You can

Dec 21, 2022

GTA(Go Task Async) is a lightweight reliable asynchronous task and transaction message library for Golang

GTA (Go Task Async) is a lightweight and reliable asynchronous task and transaction message library for by golang.

Jun 4, 2022

tasq is a simple HTTP-based task queue. Each task is represented as a string

tasq tasq is a simple HTTP-based task queue. Each task is represented as a string (it could be anything). Tasks are pushed to the queue via an HTTP en

Nov 3, 2022

Gotask - A simple task queue is stripped when the program is written to achieve the task delivery function

Gotask - A simple task queue is stripped when the program is written to achieve the task delivery function

gotask The simple task queue is stripped when the program is written to achieve

Feb 14, 2022

The Todo List / Task Manager for Geeks in command line

The Todo List / Task Manager for Geeks in command line

The CLI To-Do List / Task Manager for Geeks πŸ§‘β€πŸ’» Developer / DevOps / Sysadmin? A command line hero? πŸ’» Live with the dark terminal? πŸ“ Think in Mark

Dec 15, 2022

Run vscode task in command line

vstask Run vscode task in command line install go install "github.com/ttttmr/vstask" usage NAME: vstask - Run vscode task in command line USAGE:

Jul 1, 2022

An open-source GitLab command line tool bringing GitLab's cool features to your command line

An open-source GitLab command line tool bringing GitLab's cool features to your command line

GLab is an open source GitLab CLI tool bringing GitLab to your terminal next to where you are already working with git and your code without switching

Dec 30, 2022

A command line tool that builds and (re)starts your web application everytime you save a Go or template fileA command line tool that builds and (re)starts your web application everytime you save a Go or template file

# Fresh Fresh is a command line tool that builds and (re)starts your web application everytime you save a Go or template file. If the web framework yo

Nov 22, 2021

A command line tool to prompt for a value to be included in another command line.

readval is a command line tool which is designed for one specific purposeβ€”to prompt for a value to be included in another command line. readval prints

Dec 22, 2021

Simulate network link speed

linkio linkio provides an io.Reader and io.Writer that simulate a network connection of a certain speed, e.g. to simulate a mobile connection. Quick s

Sep 27, 2022

:alarm_clock: :fire: A TCP proxy to simulate network and system conditions for chaos and resiliency testing

:alarm_clock: :fire: A TCP proxy to simulate network and system conditions for chaos and resiliency testing

Toxiproxy Toxiproxy is a framework for simulating network conditions. It's made specifically to work in testing, CI and development environments, supp

Jan 7, 2023

godesim Simulate complex systems with a simple API.

godesim Simulate complex systems with a simple API. Wrangle non-linear differential equations while writing maintainable, simple code. Why Godesim?

Jan 5, 2023

Go package to simulate bandwidth, latency and packet loss for net.PacketConn and net.Conn interfaces

lossy Go package to simulate bandwidth, latency and packet loss for net.PacketConn and net.Conn interfaces. Its main usage is to test robustness of ap

Oct 14, 2022

simulate linkstate algorithm for routing

for final project of computer-network course in SBU university (spring 2021) we implemented a Link-state simulation in go.

Sep 20, 2022

edotool: simulate keyboard input and mouse activity

edotool: simulate keyboard input and mouse activity

edotool Simulate keystrokes. Like xdotool (well, kind of), with support for both X11 and Wayland. edotool Screengrab Using edotool keystrokes can be s

Oct 27, 2022

πŸ“‘ mock is a simple, cross-platform, cli app to simulate HTTP-based APIs.

 πŸ“‘ mock is a simple, cross-platform, cli app to simulate HTTP-based APIs.

mock πŸ“‘ mock is a simple, cross-platform, cli app to simulate HTTP-based APIs. About mock Mock allows you to spin up a local http server based of a .m

May 6, 2022

Toxiproxy - A TCP proxy to simulate network and system conditions for chaos and resiliency testing

Toxiproxy - A TCP proxy to simulate network and system conditions for chaos and resiliency testing

Toxiproxy is a framework for simulating network conditions. It's made specifically to work in testing, CI and development environments, supp

Nov 3, 2021

An API to simulate banking transactions in Golang

BASIC BANKING TRANSACTION IN GO This project is an API to simulate banking transactions in Golang. Functionalities POST /accounts = Create a new acco

Nov 11, 2021
periodic table on the command line
periodic table on the command line

element The periodic table on the command line Installation β€’ Usage Installation Go get it! go get -u -v github.com/gennaro-tedesco/element Usage Usi

Dec 24, 2022
watch for file changes (matching a suffix whitelist) in a directory tree and run a command when they change

watchspawn what is it? Watches for file creates and writes in and below the current directory and when any of them (matching a suffix list) change, ru

Jan 16, 2022
This project implements a simple Alien Invasion simulator CLI

Alien Invasion Simulator This project implements a simple Alien Invasion simulat

Feb 6, 2022
Json-match - Command line util for matching values in a JSON input

json-match Match JSON input by specifying key and value > json-match -json '{\"p

Jan 12, 2022
expose controller, when deployment created service and ingress will be created

expose-controller expose controller, when deployment created service and ingress will be created How to test git clone repository cd expose-controller

Dec 23, 2021
Package arp implements the ARP protocol, as described in RFC 826. MIT Licensed.

arp Package arp implements the ARP protocol, as described in RFC 826. MIT Licensed. Portions of this code are taken from the Go standard library. The

Dec 20, 2022
Package dhcp6 implements a DHCPv6 server, as described in RFC 3315. MIT Licensed.

dhcp6 Package dhcp6 implements a DHCPv6 server, as described in IETF RFC 3315. MIT Licensed. At this time, the API is not stable, and may change over

Sep 27, 2022
A Go library for performing Unicode Text Segmentation as described in Unicode Standard Annex #29

segment A Go library for performing Unicode Text Segmentation as described in Unicode Standard Annex #29 Features Currently only segmentation at Word

Dec 19, 2022
It syncronizes the configuration described in a YAML file against your GitHub Organization

It syncronizes the configuration described in a YAML file against your GitHub Organization. Combined with a CI system, it can be used to implement GitOps for GitHub.

Jul 19, 2021
Golang implementation of ECVRF-EDWARDS25519-SHA512-TAI, a verifiable random function described in draft-irtf-cfrg-vrf-10.

Go-ECVRF Go-ECVRF is a library that implements ECVRF-EDWARDS25519-SHA512-TAI, a verifiable random function described in draft-irtf-cfrg-vrf-10. By des

Aug 10, 2022