This project implements a simple Alien Invasion simulator CLI

Alien Invasion Simulator

Go Go Report Card GoDoc

This project implements a simple Alien Invasion simulator CLI.



Principle

The principle of the simulation is:

  • a world describes a list of cities and their possible links to other cities
  • a link can be set in any direction of this set: {North, East, South, West}
  • some aliens are spawned randomly in the world
  • the aliens move randomly from one city to another existing link
  • when two aliens meet in a city they fight so that:
    • city gets destroyed (so do the links to this city)
    • the aliens are trapped (so that they are not able to move anymore)
  • the simulation ends when:
    • all the cities are destroyed
    • all the aliens are trapped
    • a maximum number of steps is reached

Assumptions

The following assumptions have been made :

  • the city names don't include any space (which should be replaced by any other character). For example, use New-York instead of New York.
  • aliens are spawned once at the beginning of the simulation
  • the validity off the links is not checked (meaning that a city may be linked to the same city through several directions)

Parameters

The following parameters are available :

  • aliens (shorthanded to n) the number of aliens spawned at startup (defaults to 5)
  • steps (shorthanded to s) the number of maximum steps allowed (defaults to 10,000)
  • file (shorthanded to m) the path of the world map file (defaults to map.txt)

Install

From Source

Step 1: Install Golang

  • Install a correctly configured Go toolchain (version 1.17+).
  • Make sure that your GOPATH and GOBIN environment variables are properly set up.

Step 2: Get source code

#Download sources from github
git clone https://github.com/jpraynaud/alien-invasion-simulator

# Go to sources directory
cd alien-invasion-simulator

# Checkout master branch
git checkout master

Step 3 : Build binary

# Build
go build -o bin/alien-invasion cmd/cli/main.go

Step 4 : Verify

# Verify
./bin/alien-invasion --help

# or Build and Run
go run cmd/cli/main.go --help

That should output something like:

An alien invasion simulator.
More informations available at: https://github.com/jpraynaud/alien-invasion-simulator

Usage:
  alien-invasion [flags]

Flags:
  -n, --aliens uint   total number of aliens (default 5)
  -m, --file string   world map file path (default "map.txt")
  -h, --help          help for alien-invasion
  -s, --steps uint    maximum number of steps (default 10000)

Run

# Run
./bin/alien-invasion

# or
go run cmd/cli/main.go

That should output something like:

London has been destroyed by Alien #3 and Alien #1
Warsaw has been destroyed by Alien #4 and Alien #2

Roma north=Geneva west=Barcelona
Athens
Stockholm
Geneva
Paris north=Brussels south=Barcelona east=Berlin
Brussels
Berlin north=Stockholm
Barcelona north=Paris east=Roma

Examples

  • Set number of spawned aliens:
# Run
./bin/alien-invasion -n 100

# or
go run cmd/cli/main.go --aliens 100
  • Set maximum number of steps:
# Run
./bin/alien-invasion -s 5

# or
go run cmd/cli/main.go --steps 5
  • Set map file path:
# Run
./bin/alien-invasion -m ../maps-directory/other-map.txt

# or
go run cmd/cli/main.go --file ../maps-directory/other-map.txt
  • Combine options:
# Run
./bin/alien-invasion -n 4 -s 10

# or
go run cmd/cli/main.go --aliens 4 --steps 10

Tests

Run unit tests:

# Test with code coverage
go test -cover ./...
# Test with verbose output
go test -cover -v ./...

Help

Get help:

# Help with executable
./bin/alien-invasion -h

# or
go run cmd/cli/main.go --help

Documentation

GoDoc

Similar Resources

A general purpose project template for golang CLI applications

golang-cli-template A general purpose project template for golang CLI applications golang-cli-template Features Project Layout How to use this templat

Jan 15, 2022

Adventure is a CLI game, which is a project of the OOP course of ZJU

Adventure is a CLI game, which is a project of the OOP course of ZJU. This is the go version of ZJU-OOP-Adventure.

Jan 25, 2022

Elegant CLI wrapper for kubeseal CLI

Overview This is a wrapper CLI ofkubeseal CLI, specifically the raw mode. If you just need to encrypt your secret on RAW mode, this CLI will be the ea

Jan 8, 2022

CLI to run a docker image with R. CLI built using cobra library in go.

CLI  to run a docker image with R. CLI built using cobra library in go.

BlueBeak Installation Guide Task 1: Building the CLI The directory structure looks like Fastest process: 1)cd into bbtools 2)cd into bbtools/bin 3)I h

Dec 20, 2021

A wrapper of aliyun-cli subcommand alidns, run aliyun-cli in Declarative mode.

aliyun-dns A wrapper of aliyun-cli subcommand alidns, run aliyun-cli in Declarative mode. Installation Install aliyun-cli. Usage $ aliyun-dns -h A wra

Dec 21, 2021

Symfony-cli - The Symfony CLI tool For Golang

Symfony CLI Install To install Symfony CLI, please download the appropriate vers

Dec 28, 2022

Go-file-downloader-ftctl - A file downloader cli built using golang. Makes use of cobra for building the cli and go concurrent feature to download files.

ftctl This is a file downloader cli written in Golang which uses the concurrent feature of go to download files. The cli is built using cobra. How to

Jan 2, 2022

Cli-algorithm - A cli program with A&DS in go!

cli-algorithm Objectives The objective of this cli is to implement 4 basic algorithms to sort arrays been Merge Sort Insertion Sort Bubble Sort Quick

Jan 2, 2022
Typo - Terminal input simulator for demos
Typo - Terminal input simulator for demos

typo Somehow, whenever I need to give a presentation or demo, my typing skills d

Mar 19, 2022
monoctl implements the cli for Monoskope.
monoctl implements the cli for Monoskope.

monoctl monoctl implements the cli for Monoskope. Documentation Getting started Build executable with: make go-build-monoctl. This will build an execu

Nov 3, 2022
News-parser-cli - Simple CLI which allows you to receive news depending on the parameters passed to it
News-parser-cli - Simple CLI which allows you to receive news depending on the parameters passed to it

news-parser-cli Simple CLI which allows you to receive news depending on the par

Jan 4, 2022
Package varflag implements command-line flag parsing into vars.Variables for easy type handling with additional flag types.

varflag Package flag implements command-line flag parsing into vars.Variables for easy type handling with additional flag types. varflag Flags String

Aug 2, 2022
Project-2 - Create a project that calls service created above, pass text and prints JSON output returned from the service

Project Assignment Steps to run the project: First Download the repo present her

Jan 27, 2022
Moldy CLI the best project starter and manager of the world
Moldy CLI the best project starter and manager of the world

You don't know how to start your project ... you want to help other people know your tool or language. Use Moldy! the best helper to start your project

Oct 17, 2022
✨ Create a new production-ready project with backend, frontend and deploy automation by running one CLI command!
✨ Create a new production-ready project with backend, frontend and deploy automation by running one CLI command!

✨ Create a new production-ready project with backend, frontend and deploy automation by running one CLI command!

Dec 31, 2022
A project templating CLI tool.

Clonr Project Templating CLI About Installation Homebrew Go install npm Quick start for developers Configuring a project. Basic Example Example With G

Nov 21, 2022
Show Languages In Code. A fast and lightweight CLI to generate stats on the languages inside your project
Show Languages In Code. A fast and lightweight CLI to generate stats on the languages inside your project

slic Show Languages In Code. Usage Run it with an -h flag to list all commands. -d flag can be used to specify the directory of search -i flag can be

Dec 25, 2021
This project is used to get familiar with GoLang cli apps, along with cobra generator.

SecretCTL SecretCTL About the project Status Getting started Layout Notes About the project This project is used to get familiar with GoLang cli apps,

Jan 11, 2022