Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><a href="http://docs.oracle.com/javase/7/docs/api/java/util/ArrayList.html#contains%28java.lang.Object%29" rel="nofollow"><code>ArrayList#contains</code></a> compares a <code>Object</code> with those objects contained within the list...</p> <blockquote> <p>Returns true if this list contains the specified element. More formally, returns true if and only if this list contains at least one element e such that (o==null ? e==null : o.equals(e)).</p> </blockquote> <p>Your list contains arrays of <code>int</code>, which aren't easily comparable.</p> <p>It would be much easier if you used a <code>Object</code> whose <code>equals</code> method was capable of comparing the coordinates of other similar objects. Something like...</p> <pre><code>public class Coordinate { private int latitude; private int longitude; public Coordinate(int latitude, int longitude) { this.latitude = latitude; this.longitude = longitude; } public int getLatitude() { return latitude; } public int getLongitude() { return longitude; } public boolean equals(Object value) { boolean equals = false; if (value instanceof Coordinate) { Coordinate coord = (Coordinate) value; equals = getLatitude() == coord.getLatitude() &amp;&amp; getLongitude() == coord.getLongitude(); } return equals; } //good practice to override hashcode when you override equals public int hashcode() { int hash = 7; hash = 89 * hash + this.latitude; hash = 89 * hash + this.longitude; return hash; } } </code></pre> <p>Then you could use something more like...</p> <pre><code>Coordinate[] coords = { new Coordinate(3093, 3630 ), new Coordinate(3095, 3632), new Coordinate(3098, 3633), new Coordinate(3101, 3633 ), new Coordinate(3104, 3631), new Coordinate(3106, 3629), new Coordinate(3107, 3627), new Coordinate(3108, 3624), new Coordinate(3109, 3620), new Coordinate(3108, 3617), new Coordinate(3106, 3614), new Coordinate(3102, 3613), new Coordinate(3099, 3613), new Coordinate(3097, 3613), new Coordinate(3093, 3614), new Coordinate(3090, 3617), new Coordinate(3087, 3619) }; ArrayList&lt;Coordinate&gt; coordinates = new ArrayList&lt;Coordinate&gt;(); int random = Misc.random(coords.length - 1); if (getPlayersCount() &lt; coords.length) { Coordinate coord = new Coordinate(coords[random].getLatitude(), coords[random].getLongitude()); if (coordinates.contains(coord)) { random = Misc.random(coords.length - 1); } else { handler.move(coords[random].getLatitude(), coords[random].getLongitude(), 0); coordinates.add(coords[random]); } } else { random = Misc.random(coords.length - 1); handler.move(coords[random].getLatitude(), coords[random].getLongitude(), 0); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload