From 7df51c33f5a486a967a2550fdcf7664af1678dd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Mon, 11 Jan 2016 00:24:52 +0100 Subject: SearchBoard: use ArrayListIt --- .../ch/asynk/rustanddust/engine/SearchBoard.java | 27 +++++++++------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/core/src/ch/asynk/rustanddust/engine/SearchBoard.java b/core/src/ch/asynk/rustanddust/engine/SearchBoard.java index 0fc4c9a..9fd06ad 100644 --- a/core/src/ch/asynk/rustanddust/engine/SearchBoard.java +++ b/core/src/ch/asynk/rustanddust/engine/SearchBoard.java @@ -1,9 +1,6 @@ package ch.asynk.rustanddust.engine; import java.util.List; -import java.util.LinkedList; -import java.util.ArrayDeque; -import java.util.Iterator; import java.util.Collection; import ch.asynk.rustanddust.engine.util.ArrayListIt; @@ -38,10 +35,10 @@ public class SearchBoard private int searchCount; private Node nodes[]; - private ArrayDeque stack; - private LinkedList queue; - private ArrayDeque roadMarch; - private List los; + private ArrayListIt stack; + private ArrayListIt queue; + private ArrayListIt roadMarch; + private ArrayListIt los; private boolean losBlocked; public SearchBoard(Board board, int cols, int rows) @@ -58,9 +55,9 @@ public class SearchBoard nodes[i + (j * cols)] = new Node((i + dx), j); } - this.queue = new LinkedList(); - this.stack = new ArrayDeque(20); - this.roadMarch = new ArrayDeque(5); + this.queue = new ArrayListIt(30); + this.stack = new ArrayListIt(20); + this.roadMarch = new ArrayListIt(5); this.los = new ArrayListIt(10); } @@ -283,10 +280,10 @@ public class SearchBoard if (range <= 0) return targets.size(); - queue.add(from); + queue.enqueue(from); while (queue.size() != 0) { - Node src = queue.remove(); + Node src = queue.dequeue(); if (src.remaining <= 0) continue; @@ -305,12 +302,10 @@ public class SearchBoard dst.search = searchCount; dst.remaining = rangeLeft; - queue.add(dst); + queue.enqueue(dst); Tile t = getTile(dst); if (!t.isEmpty() && hasClearLineOfSight(from, dst, angle)) { - Iterator it = t.iterator(); - while (it.hasNext()) { - Pawn target = it.next(); + for (Pawn target : t) { if (shooter.canEngage(target)) targets.add(target); } -- cgit v1.1-2-g2b99