-
Notifications
You must be signed in to change notification settings - Fork 0
Home
EX2: this project has 2 parts:
part A-represent a directed,weighted,graph.
node_D class:
this class is quite simple implementation for node_data interface, this class represent a node at directed weighted graph, each node has : -unique id(int key) -tag(int) -weight(double) -info(String) -geo_location(3D point that represent this node's location)
the methods: this class has only constructors methods( default constructor and deep copy constructor), and get&set functions
directed weighted graph class:
the graph consist of nodes and weighted edges
the graph itself is representes by hashmap<Integer,node>.each node is hashed by his key. the edges is containd in 2 hashmaps <Integer,<hashmap<Integer,edge_data>> - the first hashmap-each node has a inner hashmap with edges(that start at this node),that represent his neighbors and the edges bewteen them. the sec hashmap- each node has a inner hashmap with edges(that end(!) at this node), this hashmap usud for remove node (and the Suitable edges) from the graph
the methods:
default constructor-create new graph deep copy constructor- returns an independent copy of the graph //O(n),n=the number of nodes at this graph getNode-returns node(if exist) by key //O(1) getEdge-returns the edge between two given nodes(if exist) //O(1) addNode-adds the given node to the graph //O(1) connect-create an new edge(or update the value of the edge if there is already one) between two given nodes(if exist) with given value //O(1) getV- returns a collection with all current nodes in the graph //O(1) getE- returns a collection with all edges that start at given node //O(k),k=the number of the edges that start at this node removeNode-removes node from the graph, removes all the edges that connected to this node //O(k),k=the number of the edges that connect to this node removeEdge-removes edge from src node to dest nodes (by given int src,int dest) nodeSize-returns current number of nodes at the graph //O(1) edgeSize-returns current number of edges at the graph //O(1) getMC-returns the number of operations performed on the graph //O(1)
weighted graph algorithms class:
this class Gives some other capabilities of the graph by implementing several algorithms
the methods: init-this object inits a given directed weighted graph and perform the methods on this graph. copy-by used directed weighted graph's copy constructor,returns an independent copy of this graph //O(n),n=the number of nodes at this graph
isConnected- return true if this graph is connected (if there is a path from every node to each other node at the graph) by using "shortestpathdist" method, basicly,this method iterate over all the nodes at the graph, and for each node it checks if there is a distance between the current node to each other node at the graph, if one of the distances is -1 , there is no way between those 2 nodes and therefore the graph is not hardly connected //O(n),n=the number of nodes at this graph.
shortestPath-returns a list of nodes that represented the shortest path between two given nodes by using "dijkastra" algorithm //O(n),n=the number of nodes at this graph
shortestPathDist- returns the value of the weight of the shortest path between two given nodes //O(n),n=the number of nodes at this graph
save&load- two methods that allowing to save and load a graph to/from given address at json format.
part B of the project:
this part implemets a pokemons game by using given game server that supplies the informaion of the different levels, and include a graphics interface.
the game is performed on directed weighted graph,and include two main objects, agents and pokemons. the agent suppose to "catch" the pokemons and so to earn the points.
the program first of all pop up a login frame to enter the id number and the desiere level number.(by implement a one-time Jframe&Jpanel interface)
this game is mainly managed by 3 classes, main class, arena class, and the frame class.
the main class responsible to create the first connection to the game server,accept the information of the desiere level(at json format), and init the agents in the first positions. and of course to control the thread that run the game. the progress of the game is depends at "move" method that performed in the server according to "move agents" algorithm , the game's thread call to "move" At varying rates, according to the remaining time of the level. the thread calls to "repaint" method of the frame after each move to show the visual progress of the game
the arena class responsible to manage the "board" of the game, the arena accepct during the game(and of course at the beginning) the current information of the game(at json format),make the deserialize to all of the object, and "decide" what is the next move of the agents (by using "move agents" algorithm), the move agents algorithm: this algorithm iterate over all of the agents that currently needs to get order where to proceed(it their "dest" is -1) and for each agent its iterate over all of the pokemons, and check what to witch pokemon this agent will arrive at the fasteset time, by using shortestpath algorithm, and choose the next node at the recive list of nodes.
the frame class responsible to show the graphics implementation of the game,
the frame using Jpanel and on the panel it draws all of the objects of the game at their current position according the current information at the arena.
the paint methods is:
draw graph- call to draw node and draw edge for each node and edge of at the graph
draw node- draw node at his static location as red circle
draw edge- draw edge between his src and dest nodes as black line
draw agents- draw the agents at their currens location as image of "picachu"
draw pokemons- draw the pokemons at their current location as image of pokemon ball according his type(if the type is -1 it draws the upside down image)
draw background-draw background as image of pokemon logo
this is the full show of level 11:

download&using the project: the src directory contains api folder and gameclient folder, api contains all of the interfaces and implementations of directed weighted graph, nodes,algorithms and so on, basicly- Everything related to part A. gameclient contains all of the classes that related to part B, the main program, the arena, the frames,and the implementations of the objects.
so.. for using the projects all tou has to do is to "clone" the all project, and use it as you wish for using the game: for your comfortable, there is a jar file in the main projects folder named Ex2.jar, for use it all you has to do is to make sure that this file will be located with the 6 json files that located in data folder( A0,A1,A2,A3,A4,A5),and with the images that located in doc directory(agent.png,pokemon.png,rotated_pokemon.png,background.png,background2.png) (or just run this jar directly from the main project directory), and then double click at this file will pop up the login frmae of the game.
for execute this jar file from command line-
move to this project directory, and perform the next order: java-jar Ex2,jar id levelnum .
for example: java-jar Ex2.jar 123456789 11
example:
