Labyrinth
A labyrinth game assignment
host.labyrinth.Graph Class Reference

Provides a graph functionality for the room preventing algorithm. More...

Package Functions

 Graph (int v)
 Constructs a node of the graph using the value of a vertex(node). More...
 
 Graph (Edge e)
 Constructor that transform an edge into graph. More...
 
int getV ()
 Access to the current vertex. More...
 
ArrayList< GraphgetE ()
 Access to the links of the current vertex. More...
 
boolean attach (Edge e)
 Attach an edge into a graph IFF the graph already has a vertex with the same value as one of the vertices of the edge. More...
 
int count (int v)
 Counts the number of vertices on the graph with the value of v More...
 

Private Member Functions

int tryAttach (Edge e, int count)
 Recursive algorithm that tries to attach an edge into a graph IFF the graph already has a vertex with the same value as one of the vertices of the edge. More...
 
int tryCount (int v, int count)
 Recursive algorithm that tries to count the number of vertices on the graph with the same value as v. More...
 

Private Attributes

int V
 The value of the current vertex/node. More...
 
ArrayList< GraphE
 A list of all the child nodes. More...
 

Detailed Description

Provides a graph functionality for the room preventing algorithm.

We use a graph to represent the wall structure of the walls. This way its easy to find any closed loops. Using graph we transform the problem of the closed room into the problem of finding a non simple graph.

If the board has non connected wall structure then we would need a non coherent graph to represent it. This class provides constructors and methods to create coherent graphs

An example of the biggest coherent graph we can create from the board bellow, starting from V=1 is:

   6—7   8                (1)
   |       |               /  \
   3   4   5             (4)  (2)
   |   |   |                    \
   0   1—2                    (5)–(8)

Definition at line 358 of file Common.java.

Constructor & Destructor Documentation

◆ Graph() [1/2]

host.labyrinth.Graph.Graph ( int  v)
package

Constructs a node of the graph using the value of a vertex(node).

Parameters
vThe vertex to attach.

Definition at line 363 of file Common.java.

◆ Graph() [2/2]

host.labyrinth.Graph.Graph ( Edge  e)
package

Constructor that transform an edge into graph.

Parameters
eThe edge to transform.

Definition at line 371 of file Common.java.

Member Function Documentation

◆ attach()

boolean host.labyrinth.Graph.attach ( Edge  e)
package

Attach an edge into a graph IFF the graph already has a vertex with the same value as one of the vertices of the edge.

Parameters
eThe edge to attach.
Returns
The status of the operation.
  • True on success
  • False on failure

Definition at line 390 of file Common.java.

◆ count()

int host.labyrinth.Graph.count ( int  v)
package

Counts the number of vertices on the graph with the value of v

Parameters
vThe vertex to count
Returns
The number of vertices with value v

Definition at line 399 of file Common.java.

◆ getE()

ArrayList<Graph> host.labyrinth.Graph.getE ( )
package

Access to the links of the current vertex.

Definition at line 380 of file Common.java.

◆ getV()

int host.labyrinth.Graph.getV ( )
package

Access to the current vertex.

Definition at line 378 of file Common.java.

◆ tryAttach()

int host.labyrinth.Graph.tryAttach ( Edge  e,
int  count 
)
private

Recursive algorithm that tries to attach an edge into a graph IFF the graph already has a vertex with the same value as one of the vertices of the edge.

Parameters
eThe edge to attach.
countAn initial count value to feed the algorithm.
Returns
The status of the operation.
  • True on success
  • False on failure

Definition at line 414 of file Common.java.

◆ tryCount()

int host.labyrinth.Graph.tryCount ( int  v,
int  count 
)
private

Recursive algorithm that tries to count the number of vertices on the graph with the same value as v.

Parameters
vThe vertex to count
countAn initial count value to feed to the algorithm.
Returns
The number of vertices with value v

Definition at line 436 of file Common.java.

Member Data Documentation

◆ E

ArrayList<Graph> host.labyrinth.Graph.E
private

A list of all the child nodes.

Definition at line 445 of file Common.java.

◆ V

int host.labyrinth.Graph.V
private

The value of the current vertex/node.

Definition at line 444 of file Common.java.


The documentation for this class was generated from the following file: