Package ch.epfl.cs107.play.areagame
Class AreaGraph
java.lang.Object
ch.epfl.cs107.play.areagame.AreaGraph
AreaGraph is a specific kind of graph apply to Area.
The graph is composed of AreaNodes which are defined by their position in the
graph (DiscreteCoordinates)
and the existence of directed edge between them (from) and their four
neighbors (to).
Nodes are stored into a Map.
Note: DiscreteCoordinate are serializable reimplementing hashCode() and
equals() making the keys dependant only from
the DiscreteCoordinate x and y values and not from the object itself.
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddNode(DiscreteCoordinates c, boolean left, boolean up, boolean right, boolean down) Add if absent a new Node into the graph.getNodes()keySet()booleannodeExists(DiscreteCoordinates coordinates) Return if a node exists in the graphvoidsetSignal(DiscreteCoordinates coordinates, Logic signal) Activates/desactivates a node using a logic signalCompute the shortest path in this AreaGraph from given DiscreteCoordinate to given DiscreteCoordinates
-
Constructor Details
-
AreaGraph
public AreaGraph()Default AreaGraph Constructor
-
-
Method Details
-
addNode
Add if absent a new Node into the graph. Create a new Node and put it in the nodes map at given coordinates key. Note: DiscreteCoordinate are serializable reimplementing hashCode() and equals() making the keys dependant only from the DiscreteCoordinate x and y values and not from the object itself.- Parameters:
c- (DiscreteCoordinate): Position in the graph of the node to add, used as key for the map, not nullleft- (boolean): indicate if directed edge to the left direction existsup- (boolean): indicate if directed edge to the up direction existsright- (boolean): indicate if directed edge to the right direction existsdown- (boolean): indicate if directed edge to the down direction exists
-
getNodes
-
nodeExists
Return if a node exists in the graph- Parameters:
coordinates- (DiscreteCoordinates): may be null- Returns:
- (boolean): true if the given node exists in the graph
-
setSignal
Activates/desactivates a node using a logic signal- Parameters:
coordinates- (DiscreteCoordinates): the nodes coordinatessignal- (Logic) : the Logic value assigned to the node
-
keySet
- Returns:
- (List of DiscreteCoordinates): the positions of all the nodes in the graph
-
shortestPath
Compute the shortest path in this AreaGraph from given DiscreteCoordinate to given DiscreteCoordinates- Parameters:
from- (DiscreteCoordinates): source node of the desired path, not nullto- (DiscreteCoordinates): sink node of the desired path, not null- Returns:
- (Iterator of Orientation): return an iterator containing the shortest path from source to sink, or null if the path does not exists !
-