The command below executes the simulator. The stage number should be replaced with a number between 0 and 15.
On one shell execute:
java -jar Ex4_Server_v0.0.jar <stage number>on the other shell:
pip install -r requirements.txt
cd src
python main.pyEitan Kats, Adi Yafe, Ori Howard
In this assignment we were asked to create a Pokémon game. The game is displayed on a directed graph and has 16 levels (
0-15).
Each level has a different number of agents and Pokémons.
The Algorithms We Used:
- value - the value of the Pokémon
- type - the type of the Pokémon indicates the direction of the edge the Pokemon is 'sitting' on
- position - the position of the Pokémon on the graph
- id - the id of the agent
- value - the score of the agent (increases when the agent catches a Pokémon)
- src - the source of the agent
- dest - the destination of the agent. If the next destination has not been assigned, it will be -1 speed - the speed of the agent
- position - represents the current position of the agent
The goal is to navigate the agents in the directed graph in the fastest way to catch as many Pokémons as they can.
GameHandler manages the game. It decorates the client module that communicates with the server.
How we used it:
- Fetch the information of the chosen level from the server.
- Parse the Pokémon.
- Send a request to the server to get the json that represents the Pokémon and assign each Pokémon to the corresponding edge.
- Calculate the estimated location of the Pokémon on the edge (ratio).
- Create the amount of agents participating in the current level and assign near Pokémons with the highest values.
The GameUI class is responsible for drawing and scaling the objects.
- Find the minimum and maximum game proportions of the graph nodes.
- Using the game proportions, each object is scaled and then displayed on the screen.
While the game is running: Fetch information about the agents and Pokémons. The algorithm finds the optimal Pokémon for each agent with respect to the speed and the amount of load on that agent. We only assign Pokémons that are not already being chased by other agents.
In each iteration of the game loop:
If an agent has a task, the time to complete it is calculated and added to a queue. This is calculated according to the
speed and the time it will take the agent to complete the task, with respect to the current game time. The render queue
is used to call the move method in the server at the right time.
Note: The time is a countdown clock of the current game level duration.
For example: If the current time is T1, and it takes 2 seconds for the agent to pass the current edge, then the next render time will be T1-2.
When the agent reaches the last edge in the current path, 2 timestamps are inserted to the render queue. The first is the timestamp to catch Pokémon and the second is the time it will take to reach the destination node. The calculation of the render time for the Pokémon catch is with respect to the ratio of the Pokémon on the edge.
- nodeMap - this is a hashmap which contains all the nodes of the graph, the key is the id of the node and the value is the node itself
- parsedEdges - this is a list of the edges that are in the graph
- pos - location of the graph node
- id - the id of the node
- weight - the weight of the node
- destMap - a hashmap that maps between the nodes that this node can reach and the edges that reach them
- sourceMap - a hashmap that maps between a node and the sources that can each is
- source - the id of the source node
- dest - the id of the dest node
- weight - the weight of the edge
The DiGraph is used to hold the graph that is that represents the current scenario.
This graph is a directed weighted graph
Graph Algo contains the implementation of Dijkstra (from ex-3) and additional code that loads the graph from a given file
An object representing an edge in the graph.
An object representing a node in the graph.
This is a class that represents the agents that need to chase the Pokémon that spawn on the graph
This is a class that represents the Pokémon that are spread out on the graph
Represents the location of the objects that are displayed on the screen.
This class contains methods that scale the object according to given proportions.
The GameHandler is an implementation of the Decorator Design pattern, we Decorate the client and use the GameHandler
to communicate with the server.
The main algorithms that are being executed in the game loop are in the GameHandler.
The GameUI class is used to draw objects that participate in the game onto the screen.
The game proportions are calculated in this class by using the proportions of the graph. Objects that are drawn on the screen are scaled here as well.
This is an abstract class that represents a drawable object that has a position and an icon. Mainly used to draw the agents and Pokémon.
| Stage Number | Grade | Moves |
|---|---|---|
| 0 | 100 | 49 |
| 1 | 535 | 241 |
| 2 | 249 | 87 |
| 3 | 861 | 325 |
| 4 | 333 | 115 |
| 5 | 677 | 273 |
| 6 | 79 | 39 |
| 7 | 349 | 188 |
| 8 | 130 | 71 |
| 9 | 469 | 240 |
| 10 | 159 | 76 |
| 11 | 1656 | 600 |
| 12 | 40 | 33 |
| 13 | 269 | 174 |
| 14 | 201 | 96 |
| 15 | 392 | 223 |
Icons were taken from : https://flaticon.com

