{"id":23554770,"url":"https://github.com/alejoacosta74/alien-invasion-simulation","last_synced_at":"2025-05-15T20:08:48.015Z","repository":{"id":128687163,"uuid":"491324307","full_name":"alejoacosta74/alien-invasion-simulation","owner":"alejoacosta74","description":"Golang based app that simulates an earth invasion of mad aliens from outerspace","archived":false,"fork":false,"pushed_at":"2022-05-15T00:26:59.000Z","size":3315,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-17T13:28:37.789Z","etag":null,"topics":["aliens","concurrency-patterns","golang"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alejoacosta74.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-05-12T01:28:41.000Z","updated_at":"2022-05-12T01:36:46.000Z","dependencies_parsed_at":"2023-03-30T06:08:16.263Z","dependency_job_id":null,"html_url":"https://github.com/alejoacosta74/alien-invasion-simulation","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alejoacosta74%2Falien-invasion-simulation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alejoacosta74%2Falien-invasion-simulation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alejoacosta74%2Falien-invasion-simulation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alejoacosta74%2Falien-invasion-simulation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alejoacosta74","download_url":"https://codeload.github.com/alejoacosta74/alien-invasion-simulation/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254414501,"owners_count":22067272,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aliens","concurrency-patterns","golang"],"created_at":"2024-12-26T12:25:18.150Z","updated_at":"2025-05-15T20:08:42.986Z","avatar_url":"https://github.com/alejoacosta74.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# Alien invasion\n\n\u003chtml\u003e\u003cimg src=\"./aliens.png\" height=\"300px\"/\u003e\u003c/html\u003e\n\n## Description\n\nGolang based app that simulates an earth invasion of mad aliens from outerspace.\n\nThese aliens start out at random places on the given world map, and wander around randomly, following links (directions). \n\nIn each iteration, the aliens can travel in any of the directions leading out of a city.\n\nWhen two aliens end up in the same place, they fight, and in the process kill each other and destroy the city. When a city is destroyed, it is removed from the map, and so are any roads that lead into or out of it.\n\nThe program runs until all the aliens have been destroyed, or each alien has moved at least 10,000 times. \n\nWhen two aliens fight, the program prints out a message like:\n\n`City Bee destroyed by Aliens 2 and 4 `\n\n## Features\n- Concurrency model based on `channel` type (no `mutex` used)\n- Debug mode available\n- Progress bar that shows execution progress when program is waiting for iterations to complete:\n```\n1 alien left. Waiting for it to exit or iterations to complete...  94% [=============\u003e ]  [5s:0s]\n```\n\n- Sample maps provided in `data` folder:\n  \n  `world_sample.txt` (5 cities)\n\n  `world_big.txt` (13 cities)\n\n- Command line options\n```bash\nusage: main --file=FILE [\u003cflags\u003e]\n\nFlags:\n      --help              Show context-sensitive help (also try --help-long and --help-man).\n  -a, --aliens=12         Number of aliens. Defaults to system's number of CPUs.\n  -i, --iterations=10000  Number of iterations. Defaults to 10.000.\n  -d, --debug             debug mode\n  -f, --file=FILE         input source file\n      --version           Show application version.\n```\n- Test suite available\n  \n## Assumptions\n\n- If an alien wants to \"land\" but no cities are available (all cities have already been destroyed), it will \"die\" (i.e. exit) automatically\n- Cities can only have a maximun of 1 neighbor city *per* direction (i.e, north, south, east, west)\n- At the moment, the `world` is only supported as a `map` data structure\n- When a city is destroyed, the worldmap is updated without bridging (i.e. connecting) remaining cities. This behaviour could potentially lead to cities being isolated\n- Input file format: The city and each of the pairs should be separated by a single space, and the directions are separated from their respective cities with an equals (=) sign, i.e:\n\n`world_sample.txt`\n```\nFoo north=Bar west=Baz south=Qu-ux\nBar south=Foo west=Bee\n```\n  \n\n## Usage examples\n\n### Example 1\n\n- Input:\n  \n  `aliens` = 4\n\n  `iterations` = 500\n\n  `file` = ./data/world_sample.txt\n\n```bash\n❯ go run main.go -a 4 -i 500  -f ./data/world_sample.txt\n```\n\n- Reference ouput\n```bash\nINFO[0000] World loaded from file                       \n\nPrinting world:\n----------------------------------------\nNumber of cities:  5\n        City:  Bee\n                Neighbor:  Bar  -\u003e  East\n        City:  Foo\n                Neighbor:  Bazz  -\u003e  West\n                Neighbor:  Bar  -\u003e  North\n                Neighbor:  Qu-ux  -\u003e  South\n        City:  Bar\n                Neighbor:  Foo  -\u003e  South\n                Neighbor:  Bee  -\u003e  West\n        City:  Qu-ux\n                Neighbor:  Foo  -\u003e  North\n        City:  Bazz\n                Neighbor:  Foo  -\u003e  East\n----------------------------------------\n\nINFO[0000] Alien invasion started with 4 aliens and 500 iterations \nWARN[0000] City Bee destroyed by Aliens 2 and 4          alien=Alien2 id=2\nWARN[0000] City Qu-ux destroyed by Aliens 3 and 1        alien=Alien3 id=3\n\nINFO[0000] Invasion terminated ...                      \n\nPrinting world:\n----------------------------------------\nNumber of cities:  3\n        City:  Foo\n                Neighbor:  Bazz  -\u003e  West\n                Neighbor:  Bar  -\u003e  North\n        City:  Bar\n                Neighbor:  Foo  -\u003e  South\n        City:  Bazz\n                Neighbor:  Foo  -\u003e  East\n----------------------------------------\n\nINFO[0000] Program finished  \n```\n\n### Example 2\n\n- Input:\n  \n  `aliens` = 11\n\n  `iterations` = 5000\n\n  `file` = ./data/world_big.txt\n\n```bash\n❯ go run main.go -a 11 -i 5000  -f ./data/world_big.txt\n```\n\n- Reference ouput\n\n```bash\nINFO[0000] World loaded from file                       \n\nPrinting world:\n----------------------------------------\nNumber of cities:  13\n        City:  City1\n                Neighbor:  City2  -\u003e  North\n                Neighbor:  City4  -\u003e  East\n                Neighbor:  City6  -\u003e  South\n                Neighbor:  City8  -\u003e  West\n        City:  City10\n                Neighbor:  City2  -\u003e  South\n        City:  City9\n                Neighbor:  City2  -\u003e  East\n                Neighbor:  City8  -\u003e  South\n        City:  City12\n                Neighbor:  City6  -\u003e  North\n        City:  City13\n                Neighbor:  City8  -\u003e  East\n        City:  City7\n                Neighbor:  City6  -\u003e  East\n                Neighbor:  City8  -\u003e  North\n        City:  City11\n                Neighbor:  City4  -\u003e  West\n        City:  City2\n                Neighbor:  City10  -\u003e  North\n                Neighbor:  City3  -\u003e  East\n                Neighbor:  City9  -\u003e  West\n                Neighbor:  City1  -\u003e  South\n        City:  City4\n                Neighbor:  City1  -\u003e  West\n                Neighbor:  City3  -\u003e  North\n                Neighbor:  City11  -\u003e  East\n                Neighbor:  City5  -\u003e  South\n        City:  City6\n                Neighbor:  City1  -\u003e  North\n                Neighbor:  City5  -\u003e  East\n                Neighbor:  City12  -\u003e  South\n                Neighbor:  City7  -\u003e  West\n        City:  City8\n                Neighbor:  City13  -\u003e  West\n                Neighbor:  City1  -\u003e  East\n                Neighbor:  City9  -\u003e  North\n                Neighbor:  City7  -\u003e  South\n        City:  City3\n                Neighbor:  City2  -\u003e  West\n                Neighbor:  City4  -\u003e  South\n        City:  City5\n                Neighbor:  City6  -\u003e  West\n                Neighbor:  City4  -\u003e  North\n----------------------------------------\n\nINFO[0000] Alien invasion started with 11 aliens and 5000 iterations \nWARN[0000] City City12 destroyed by Aliens 5 and 4       alien=Alien5 id=5\nWARN[0000] City City1 destroyed by Aliens 3 and 9        alien=Alien3 id=3\nWARN[0000] City City4 destroyed by Aliens 8 and 10       alien=Alien8 id=8\nWARN[0000] City City6 destroyed by Aliens 11 and 1       alien=Alien11 id=11\nWARN[0000] City City2 destroyed by Aliens 7 and 2        alien=Alien7 id=7\n 1 alien left. Waiting for it to exit or iterations to complete...  99% [=============\u003e ]  [27s:0s] \nINFO[0027] Killing remaining 1 aliens after 5000 iterations \nINFO[0027] Invasion terminated ...                      \n\nPrinting world:\n----------------------------------------\nNumber of cities:  8\n        City:  City8\n                Neighbor:  City9  -\u003e  North\n                Neighbor:  City7  -\u003e  South\n                Neighbor:  City13  -\u003e  West\n        City:  City3\n        City:  City5\n        City:  City7\n                Neighbor:  City8  -\u003e  North\n        City:  City11\n        City:  City10\n        City:  City9\n                Neighbor:  City8  -\u003e  South\n        City:  City13\n                Neighbor:  City8  -\u003e  East\n----------------------------------------\n\nINFO[0027] Program finished  \n```\n\n### Example 3\n\n- Input:\n  \n  `aliens` = 30\n\n  `iterations` = 10000\n\n  `file` = ./data/world_big.txt\n\n```bash\n❯ go run main.go -a 11 -i 5000  -f ./data/world_big.txt\n```\n\n- Reference ouput\n\n```bash\n❯ go run -race main.go -a 30 -i 10000  -f ./data/world_big.txt\nINFO[0000] World loaded from file                       \n\nINFO[0000] Alien invasion started with 30 aliens and 10000 iterations \nWARN[0000] City City7 destroyed by Aliens 12 and 14      alien=Alien12 id=12\nWARN[0000] City City2 destroyed by Aliens 16 and 2       alien=Alien16 id=16\nWARN[0000] City City6 destroyed by Aliens 11 and 4       alien=Alien11 id=11\nWARN[0000] City City11 destroyed by Aliens 7 and 5       alien=Alien7 id=7\nWARN[0000] City City1 destroyed by Aliens 13 and 3       alien=Alien13 id=13\nWARN[0000] City City8 destroyed by Aliens 9 and 6        alien=Alien9 id=9\nWARN[0000] City City10 destroyed by Aliens 15 and 19     alien=Alien15 id=15\nWARN[0000] City City13 destroyed by Aliens 25 and 1      alien=Alien25 id=25\nWARN[0000] City City9 destroyed by Aliens 17 and 28      alien=Alien17 id=17\nWARN[0000] City City4 destroyed by Aliens 10 and 21      alien=Alien10 id=10\nWARN[0000] City City3 destroyed by Aliens 26 and 8       alien=Alien26 id=26\nWARN[0000] City City12 destroyed by Aliens 24 and 22     alien=Alien24 id=24\nWARN[0000] City City5 destroyed by Aliens 30 and 23      alien=Alien30 id=30\nINFO[0000] no more cities available. Exiting             alien=Alien20 id=20\nINFO[0000] no more cities available. Exiting             alien=Alien18 id=18\nINFO[0000] no more cities available. Exiting             alien=Alien27 id=27\nINFO[0000] no more cities available. Exiting             alien=Alien29 id=29\n\nINFO[0000] Invasion terminated ...                      \n\nPrinting world:\n----------------------------------------\nNumber of cities:  0\n----------------------------------------\n\nINFO[0000] Program finished          \n```\n\n## Test coverage\n\n```\n❯ go test -v ./..\n=== RUN   TestAliensLifeCycleBasic\n=== RUN   TestAliensLifeCycleBasic/Should_start_N_aliens\n=== RUN   TestAliensLifeCycleBasic/Should_stop_N_aliens_on_cancel\n--- PASS: TestAliensLifeCycleBasic (0.30s)\n    --- PASS: TestAliensLifeCycleBasic/Should_start_N_aliens (0.30s)\n    --- PASS: TestAliensLifeCycleBasic/Should_stop_N_aliens_on_cancel (0.00s)\nPASS\nok      github.com/alejoacosta74/allien_invasion/aliens 1.172s\n=== RUN   TestAlienInvasion\n=== RUN   TestAlienInvasion/With_odd_number_of_aliens,_at_least_1_alien_should_stay_alive_and_max_iterations_reached\n\n=== RUN   TestAlienInvasion/With_aliens_(even)_\u003e\u003e_5,_all_cities_will_likely_be_destroyed\n\n--- PASS: TestAlienInvasion (0.01s)\n    --- PASS: TestAlienInvasion/With_odd_number_of_aliens,_at_least_1_alien_should_stay_alive_and_max_iterations_reached (0.00s)\n    --- PASS: TestAlienInvasion/With_aliens_(even)_\u003e\u003e_5,_all_cities_will_likely_be_destroyed (0.01s)\nPASS\nok      github.com/alejoacosta74/allien_invasion/app    0.721s\n=== RUN   TestCityFileReader\n=== RUN   TestCityFileReader/Reads_all_the_cities\n=== RUN   TestCityFileReader/Reads_all_neighbours_and_directions\n--- PASS: TestCityFileReader (0.00s)\n    --- PASS: TestCityFileReader/Reads_all_the_cities (0.00s)\n    --- PASS: TestCityFileReader/Reads_all_neighbours_and_directions (0.00s)\n=== RUN   TestLoadMap\n=== RUN   TestLoadMap/Should_create_a_world_structure_from_a_file\n--- PASS: TestLoadMap (0.00s)\n    --- PASS: TestLoadMap/Should_create_a_world_structure_from_a_file (0.00s)\nPASS\n```\n\n\n## To Do\n\n- Add support for graph structure\n- Increase test coverage","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falejoacosta74%2Falien-invasion-simulation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falejoacosta74%2Falien-invasion-simulation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falejoacosta74%2Falien-invasion-simulation/lists"}