From c14d1d812f312eda499c445e2827a8fbafa34100 Mon Sep 17 00:00:00 2001 From: Anastasia Foti Date: Tue, 17 Nov 2020 17:08:25 +0200 Subject: [PATCH] Board true deep copy Constructor and createInnerWalls small bug --- src/host/labyrinth/Board.java | 9 +++++---- src/host/labyrinth/Common.java | 4 ++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/host/labyrinth/Board.java b/src/host/labyrinth/Board.java index fbb89b6..c127a0a 100644 --- a/src/host/labyrinth/Board.java +++ b/src/host/labyrinth/Board.java @@ -75,7 +75,8 @@ class Board { // Clone arrays this.tiles = b.tiles.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 () { 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. do { if ((tileId = randTiles.get())== Const.EOR) { - if (i == shuffleMark) // Wallable tiles exhausted. + if (walls == shuffleMark) // Wallable tiles exhausted. return walls; else { // Re-shuffle and continue. randTiles = new ShuffledRange(0, N*N); - shuffleMark =i; + shuffleMark =walls; } } } while (!isWallable(tileId)); diff --git a/src/host/labyrinth/Common.java b/src/host/labyrinth/Common.java index ef8cc9f..87177ee 100644 --- a/src/host/labyrinth/Common.java +++ b/src/host/labyrinth/Common.java @@ -314,7 +314,7 @@ class Edge { * 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 constroctors and + * 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, @@ -330,7 +330,7 @@ class Edge { class Graph { /** * 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) { V = v;