https://github.com/technicallyty/invaders
challenge
https://github.com/technicallyty/invaders
Last synced: over 1 year ago
JSON representation
challenge
- Host: GitHub
- URL: https://github.com/technicallyty/invaders
- Owner: technicallyty
- Created: 2021-06-25T03:44:25.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2021-06-25T13:35:39.000Z (about 5 years ago)
- Last Synced: 2024-10-29T07:41:38.653Z (over 1 year ago)
- Language: Go
- Size: 5.86 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# Invasion
built with Go version 1.16.5
### Running the binary
run the command `make build` in project directory
run the binary with this command:
`./main -map YOUR_FILE.txt -n 5`
you can run the sample file with:
`./main -map map.txt -n 5`
#### Flags:
`-map (your_textFile)` - see below on how to form a well formed text input file
`-n (number)` - the number of aliens to spawn on the map. Note: at most can be 2*number of cities (in the maximum case, the game ends instantly)
the program will end by printing the cities and their paths left in the game, same format as input file.
### Running the tests
`make test`
### Assumptions
The project describes an example input file that has cities in its path not defined. I'm assuming that any city found
in a text file will have its own line describing its own paths. Each city will have at least 1 path. There are no sinks (in the beginning at least).
I assume the input file will be formed as such:
```
foo north=bar south=baz
bar south=foo
baz north=foo
```
### Notes
Initially, `MoveAlien` was `MoveAliens`, which would move all aliens at the same time.
Upon running the program, I noticed this could cause ping-pong behavior where two aliens could continuously swap positions.
Because of this, it only moves one alien at a time, and then checks for battle conditions
`SuperEpicAlienBattle` used to loop over all cities, however this felt like a waste of resources. Instead, since the above change
made aliens move one at a time, I decided to simply execute a check if they moved into a city with 1 alien, and execute
a fight after moving the 2nd alien in.