9 package host.labyrinth;
11 import java.util.ArrayList;
12 import java.util.Collections;
21 static final int EOR =-1;
27 static int boardSize = 15;
28 static int supplySize = 4;
29 static int maxRounds = 100;
30 static boolean loopGuard =
false;
31 static boolean interactive =
false;
38 static final int UP =1;
39 static final int RIGHT =3;
40 static final int DOWN =5;
41 static final int LEFT =7;
64 static final int Begin =1;
65 static final int End =8;
66 static final int Step =2;
86 this.
id = toID(row, col);
108 case Direction.
UP: this.
id = toID(row+1, col);
break;
130 static int toID(
int row,
int col) {
168 numbers =
new ArrayList<Integer>();
169 init (begin, end, 1);
177 Range(
int begin,
int end,
int step) {
178 numbers =
new ArrayList<Integer>();
179 init (begin, end, step);
185 private void init (
int begin,
int end,
int step) {
187 for (
int i=begin ; i<end ; i+=step)
195 if (!numbers.isEmpty())
196 return numbers.remove(0);
217 Collections.shuffle(numbers);
228 super(begin, end, step);
229 Collections.shuffle(numbers);
271 Edge(
int tileId,
int direction) {
334 E =
new ArrayList<Graph>();
342 E =
new ArrayList<Graph>();
349 ArrayList<Graph>
getE() {
return E; }
360 return tryAttach(e, 0) > 0;
369 return tryCount (v, 0);
385 count = n.tryAttach (e, count);
386 if (V == e.
getV1()) {
390 if (V == e.
getV2()) {
407 count = n.tryCount (v, count);
414 private ArrayList<Graph>
E;
static final int RIGHT
East direction.
Class to hold constant values for entire application.
int getV1()
Access of the first node of the edge.
Helper C++-like enumerator class to hold direction.
Position(int tileId)
Basic constructor from Id.
static final int End
Iterator style end of range direction (one place after the last)
int id
The id coordinate of the constructed Position object.
Graph(int v)
Constructs a node of the graph using the value of a vertex(node).
ArrayList< Graph > E
A list of all the child nodes.
void init(int begin, int end, int step)
Common utility to create the range for all constructors.
int getV2()
Access of the second node of the edge.
Range(int begin, int end, int step)
Create the range [begin, end) using step as interval between items.
int v2
Second vertex of the edge.
ShuffledRange(int begin, int end)
Create a shuffled version of range [begin, end)
Edge(int tileId, int direction)
This constructor acts as the interface between the application's wall representation and the one base...
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...
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...
Provides a graph functionality for the room preventing algorithm.
Helper C++ like enumerator class for direction ranged loops.
int getId()
Read access to id coordinate.
Position(int row, int col)
Basic constructor from row-column coordinates.
int V
The value of the current vertex/node.
int getRow()
Read access to virtual row coordinate.
int getCol()
Read access to virtual column coordinate.
ArrayList< Graph > getE()
Access to the links of the current vertex.
static int toRow(int id)
Takes Id coordinate and return the corresponding row coordinate.
Edge(Edge e)
A deep copy contructor.
static final int EOR
Number to indicate the End Of Range.
Graph(Edge e)
Constructor that transform an edge into graph.
static int toCol(int id)
Takes Id coordinate and return the corresponding column coordinate.
Position(int row, int col, int direction)
Constructor from row-column coordinates and a direction.
An Application wide board position implementation holding just the id coordinate. ...
static final int maxTileWalls
Number of maximum walls for each tile on the board.
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 vert...
int v1
First vertex of the edge.
int getV()
Access to the current vertex.
static final int noSupply
Number to indicate the absent of supply.
static int toID(int row, int col)
Takes row and column coordinates and return the calculated Id coordinate.
Application wide object to hold settings like values for the session.
Class to create ranges of numbers.
ArrayList< Integer > numbers
handle to range
static int boardSize
Default board's size (if no one set it via command line)
static final int LEFT
West direction.
static final int noTileId
Number to indicate wrong tileId.
A utility class used for room prevent algorithm.
int count(int v)
Counts the number of vertices on the graph with the value of v
static final int UP
North direction.
static int opposite(int direction)
Utility to get the opposite direction.
static final int DOWN
South direction.
Range(int begin, int end)
Create the range [begin, end)
ShuffledRange(int begin, int end, int step)
Create a shuffled version of the range [begin, end) using step as interval between items...
Class to create shuffled ranges of numbers.