BugWorld is an environment of two swarms of bugs, where the goal of the bugs is to collect the most food and bring it back to their base. This is an implementation of the game using HTML, CSS, and Javascript. This project aims to implement an assembler to parse bug instructions, a GUI for the simulator, and the actual simulator itself.
Please install npm to use the testing framework Jest.
# Clone the repository
## (via HTTPS)
git clone https://github.com/BrainTeazer/bug-world.git
# Move to the directory
cd bug-world/src/Inside bug-world/src/, open start.html in your browser.
You can directly access the website here. (Note: you need to use Constructor VPN, or be on university premises)
Valid files to upload are in bug-world/input_files/ with the naming scheme valid-*.world. Invalid files have the naming scheme invalid-*.world. Currently, the bug assemblers are not functional so there is a placeholder bug.buggy file as well.
To continue to simulation.html, all files must be uploaded and the world map must be valid. The same file can be uploaded for both bug files.
Note: The end of game page cannot be accessed directly via the UI of the website currently. You can access it by opening bug-world/src/end.html in your browser OR by using the clabsql link here
First go to bug-world/ and run:
npm installThen to run the test cases go to bug-world/ and run:
npm testbug-world/
┣ input_files/
┃ ┣ bug.buggy
┃ ┣ invalid-1.world
┃ ┣ invalid-2.world
┃ ┣ invalid-3.world
┃ ┣ invalid-4.world
┃ ┣ valid-1.world
┃ ┣ valid-2.world
┃ ┣ valid-3.world
┃ ┗ valid-4.world
┣ scripts/
┃ ┣ bug_assembler/
┃ ┃ ┣ instructions/
┃ ┃ ┃ ┣ Direction.js
┃ ┃ ┃ ┣ Drop.js
┃ ┃ ┃ ┣ Flip.js
┃ ┃ ┃ ┣ Label.js
┃ ┃ ┃ ┣ Mark.js
┃ ┃ ┃ ┣ Move.js
┃ ┃ ┃ ┣ PickUp.js
┃ ┃ ┃ ┣ Sense.js
┃ ┃ ┃ ┣ Turn.js
┃ ┃ ┃ ┗ Unmark.js
┃ ┃ ┣ Assembler.js
┃ ┃ ┣ CellDirection.js
┃ ┃ ┣ Condition.js
┃ ┃ ┣ Direction.js
┃ ┃ ┣ Grammar.js
┃ ┃ ┗ peg-0.10.0.min.js
┃ ┣ game_logic/
┃ ┃ ┣ Bug.js
┃ ┃ ┣ BugBrain.js
┃ ┃ ┣ BugCondition.js
┃ ┃ ┣ Color.js
┃ ┃ ┣ Position.js
┃ ┃ ┣ World.js
┃ ┃ ┗ WorldCell.js
┃ ┣ simulator/
┃ ┃ ┣ Engine.js
┃ ┃ ┣ GUI.js
┃ ┃ ┣ Simulator.js
┃ ┃ ┗ Tournament.js
┃ ┣ CreateWorldMap.js
┃ ┣ Files.js
┃ ┣ PageSwitch.js
┃ ┣ ParseWorldMap.js
┃ ┗ simulation.js
┣ src/
┃ ┣ end.html
┃ ┣ simulation.html
┃ ┗ start.html
┣ styles/
┃ ┣ simulation.css
┃ ┗ style.css
┣ test/
┃ ┣ Bug.test.js
┃ ┣ ParseWorldMap.test.js
┃ ┣ Position.test.js
┃ ┗ WorldCell.test.js
┣ README.md
┣ package-lock.json
┗ package.json
- Created functional welcome page
- Created functional end of game page
- Created settings page, homepage, change settings page, and a functional quit game page
- Created enumerations:
CellDirectionDirectionConditionColorBugCondition
-
Implemented
Positionclass:- Constructor
-
Implemented
WorldCellclass:- Constructor
isObstructed()isOccupied()isFriendlyBase(color)isEnemyBase(color)isFriendlyMarker(color, position)isEnemyMarker(color, position)cellMatches(position, bugCondition, color)setFood(amt)setBug(bug)clearMarker(color, position)setMarker(color, position)getBug(bug)getFood()removeBug()toString()
-
Partially implemented
Worldclass:- Constructor
isObstructedAt(pos)setFoodAt(pos, amt)setBugAt(pos, bug)cellAt(pos)getFoodAt(pos)getBugAt(pos)removeBugAt(pos)
-
Partially implemented
Bugclass:- Constructor
getPosition()toString()
-
Created
Assemblerclass with a stubassemble(file)function -
Implemented
BugBrainclass- Constructor
getNextInstruction
-
Partially implemented
GUIclass- Constructor
setIterationsNumber(num)setOptions(bool)getIterationsNumber()
-
Implemented
Simulatorclasses constructor -
Implemented file upload and ability to file parse (all on client-side)
-
Partially implemented parsing of world map file (
.worldfile)- Checks for closed border
- Checks that both swarms are present
- Checks for valid characters
- Checks for valid dimensions
- Checks for valid map file length that corresponds to given dimensions
-
Implemented creation of map on the web page using a
Worldobject created after parsing the world map file (each cell is uniquely colored based on the cell type) -
Documentation / Comments for each function implemented
-
Added test cases for:
parseMapFile(mapFile)(location:bug-world/scripts/ParseWorldMap.js)- Methods in
WorldCell.js(location:bug-world/scripts/game_logic/WorldCell.js) - Methods in
Bug.js(location:bug-world/scripts/game_logic/Bug.js) - Methods in
Position.js(location:bug-world/scripts/game_logic/Position.js)
-
Added type checking for various methods in:
World.jsWorldCell.jsPosition.jsBug.jsBugBrain.js
-
Created files for all classes in UML diagram.