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

Overview

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).
Owner
Artur Mruk
Artur Mruk
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

Gennaro Tedesco 44 Nov 18, 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

Matt Layher 266 Nov 25, 2021
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

Matt Layher 71 Nov 8, 2021
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

bleve 68 Dec 5, 2021
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.

Carlos Tadeu Panato Junior 6 Jul 19, 2021
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

Carlos Alexandro Becker 119 Nov 29, 2021
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.

Kevin Su 6 Jul 15, 2021
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

Anis uddin Ahmad 315 Nov 25, 2021
Rolling writer is an IO util for auto rolling write in go.

RollingWriter RollingWriter is an auto rotate io.Writer implementation. It can works well with logger. Awesome Go popular log helper New Version v2.0

Arthur Lee 180 Nov 16, 2021
FSManager - Tree view Simple util to displays the directory structure of a path or of the disk in a drive graphically.

FSManager - Tree view Simple util to displays the directory structure of a path or of the disk in a drive graphically. If you don't specify a drive or

Kostiantyn Denysov 1 Oct 9, 2021
redis-util business-friendly encapsulation of redis operations, such as the common cache set get operation

redis-util 方便业务使用的redis操作封装,比如常见的缓存set get操作, 一行代码搞定,不像开源库需要写好多行 使用方法

connor 1 Oct 22, 2021
Magic util that "bridges" Wireguard with OpenVPN without a TUN/TAP interface

wg-ovpn Magic util that "bridges" Wireguard with OpenVPN without a TUN/TAP interface Warning: really ugly and unstable code! Building Obtain latest so

Patrycja 5 Nov 18, 2021
A great util to format you git commit message!

A great util to format you git commit message!

常乐村喵蕉君 0 Nov 5, 2021
Simple CLI util for running OCR on images through PERO OCR API

pero_ocr Simple CLI util for running OCR on images through PERO OCR API Usage: Usage of batch_pero_ocr: -c string cancel request with given

Moravian Library in Brno 2 Dec 1, 2021
A comprehensive, efficient, and reusable util function library of go.

Lancet Lancet is a comprehensive, efficient, and reusable util function library of go. Inspired by the java apache common package and lodash.js. Engli

Beyond 0 Nov 28, 2021
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

Clement Sam 1.6k Dec 4, 2021
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

null 0 Nov 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

Ian Kent 49 Apr 20, 2021
: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

Shopify 7.4k Nov 27, 2021
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?

Patricio Whittingslow 16 Nov 27, 2021
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

Cevat Barış Yılmaz 293 Nov 16, 2021
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.

Roozbeh Sharifnasab 5 Nov 22, 2021
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

null 4 Nov 22, 2021
📡 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

Bruno Schaatsbergen 2 Nov 14, 2021
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

Shopify 6.7k 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

Everton Lima Aleixo 0 Nov 11, 2021
Simple gc using integer vectors to simulate

gcint Simple gc using integer vectors to simulate Iterate primarily over what should be the shorter vector (readers) removing unused references in fro

Matt Rutkowski 0 Nov 24, 2021
Simulate which EC2 instances applied reserved instance.

Go - Reserved Instance Simulator (gori-simulator) Usage $ env AWS_PROFILE=YOUR_PROFILE ./gori-simulator Notices Convertible only (not Standard) Regio

Kazuki Ueki 0 Dec 3, 2021
Go package to make lightweight ASCII line graph ╭┈╯ in command line apps with no other dependencies.

asciigraph Go package to make lightweight ASCII line graphs ╭┈╯. Installation go get github.com/guptarohit/asciigraph Usage Basic graph package main

Rohit Gupta 1.8k Dec 1, 2021