Board true deep copy Constructor and createInnerWalls small bug
This commit is contained in:
parent
83d5217151
commit
c14d1d812f
@ -75,7 +75,8 @@ class Board {
|
|||||||
// Clone arrays
|
// Clone arrays
|
||||||
this.tiles = b.tiles.clone();
|
this.tiles = b.tiles.clone();
|
||||||
this.supplies = b.supplies.clone();
|
this.supplies = b.supplies.clone();
|
||||||
this.walls = b.walls;
|
for (Edge it: b.walls)
|
||||||
|
this.walls.add(new Edge(it));
|
||||||
}
|
}
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
||||||
@ -458,15 +459,15 @@ class Board {
|
|||||||
*/
|
*/
|
||||||
private int createInnerWalls () {
|
private int createInnerWalls () {
|
||||||
ShuffledRange randTiles = new ShuffledRange(0, N*N);
|
ShuffledRange randTiles = new ShuffledRange(0, N*N);
|
||||||
for (int tileId, i =0, walls =0, shuffleMark =0 ; true ; ) {
|
for (int tileId, walls =0, shuffleMark =0 ; true ; ) {
|
||||||
// randomly pick a wallable tile.
|
// randomly pick a wallable tile.
|
||||||
do {
|
do {
|
||||||
if ((tileId = randTiles.get())== Const.EOR) {
|
if ((tileId = randTiles.get())== Const.EOR) {
|
||||||
if (i == shuffleMark) // Wallable tiles exhausted.
|
if (walls == shuffleMark) // Wallable tiles exhausted.
|
||||||
return walls;
|
return walls;
|
||||||
else { // Re-shuffle and continue.
|
else { // Re-shuffle and continue.
|
||||||
randTiles = new ShuffledRange(0, N*N);
|
randTiles = new ShuffledRange(0, N*N);
|
||||||
shuffleMark =i;
|
shuffleMark =walls;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} while (!isWallable(tileId));
|
} while (!isWallable(tileId));
|
||||||
|
@ -314,7 +314,7 @@ class Edge {
|
|||||||
* of the closed room into the problem of finding a non simple graph.
|
* 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
|
* If the board has non connected wall structure then we would need a non
|
||||||
* coherent graph to represent it. This class provides constroctors and
|
* coherent graph to represent it. This class provides constructors and
|
||||||
* methods to create coherent graphs
|
* methods to create coherent graphs
|
||||||
*
|
*
|
||||||
* An example of the biggest coherent graph we can create from the board bellow,
|
* An example of the biggest coherent graph we can create from the board bellow,
|
||||||
@ -330,7 +330,7 @@ class Edge {
|
|||||||
class Graph {
|
class Graph {
|
||||||
/**
|
/**
|
||||||
* Constructs a node of the graph using the value of a vertex(node).
|
* Constructs a node of the graph using the value of a vertex(node).
|
||||||
* @param v The verteg to attach.
|
* @param v The vertex to attach.
|
||||||
*/
|
*/
|
||||||
Graph (int v) {
|
Graph (int v) {
|
||||||
V = v;
|
V = v;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user