12 package host.labyrinth;
14 import java.util.ArrayList;
15 import java.util.Collections;
26 static final int EOR =-1;
37 static int boardSize = 15;
38 static int supplySize = 4;
39 static int maxRounds = 100;
40 static boolean loopGuard =
false;
41 static boolean interactive =
false;
57 static final int Begin =1;
58 static final int End =8;
59 static final int Step =2;
60 static final int numOfDirections =4;
67 static final int UP =1;
68 static final int RIGHT =3;
69 static final int DOWN =5;
70 static final int LEFT =7;
79 static int get (
int fromId,
int toId) {
110 this.
id = toID(row, col);
132 case Direction.
UP: this.
id = toID(row+1, col);
break;
154 static int toID(
int row,
int col) {
192 numbers =
new ArrayList<Integer>();
193 init (begin, end, 1);
201 Range(
int begin,
int end,
int step) {
202 numbers =
new ArrayList<Integer>();
203 init (begin, end, step);
209 private void init (
int begin,
int end,
int step) {
211 for (
int i=begin ; i<end ; i+=step)
219 if (!numbers.isEmpty())
220 return numbers.remove(0);
228 return numbers.size();
248 Collections.shuffle(numbers);
259 super(begin, end, step);
260 Collections.shuffle(numbers);
302 Edge(
int tileId,
int direction) {
365 E =
new ArrayList<Graph>();
373 E =
new ArrayList<Graph>();
380 ArrayList<Graph>
getE() {
return E; }
391 return tryAttach(e, 0) > 0;
400 return tryCount (v, 0);
416 count = n.tryAttach (e, count);
417 if (V == e.
getV1()) {
421 if (V == e.
getV2()) {
438 count = n.tryCount (v, count);
445 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...
static final double opponentFactor
static final double supplyFactor
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.
static final int moveItems
The number of items return by move()
Position(int row, int col)
Basic constructor from row-column coordinates.
static final int viewDistance
The max distance of the Heuristic player's ability to see.
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 final int noOpponent
Number to indicate the absent of supply.
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.