Note that there are some explanatory texts on larger screens.

plurals
  1. POJava arraylist - Check if the two items in arraylist index are set while generating random ints from list?
    primarykey
    data
    text
    <p>My coordinates list:</p> <pre><code> int[][] coords = { {3093, 3630 }, {3095, 3632}, {3098, 3633}, {3101, 3633 }, {3104, 3631}, {3106, 3629}, {3107, 3627}, {3108, 3624}, {3109, 3620}, {3108, 3617}, {3106, 3614}, {3102, 3613}, {3099, 3613}, {3097, 3613}, {3093, 3614}, {3090, 3617}, {3087, 3619} }; </code></pre> <p>Generation part:</p> <pre><code> int random = Misc.random(coords.length - 1); handler.move(coords[random][0], coords[random][1], 0); </code></pre> <p>Basically what I am trying to do, if these coordinates are already taken, then re-generate the coords.</p> <ol> <li>I can't really store these coords into a big arraylist, because I don't always want this feature to function, for example if I have more players than the items in the coords[] array, then this won't be activated.</li> </ol> <p>Therefore I created a arraylist of used coords, and this is my logic on how to do this:</p> <pre><code> int[][] coords = { {3093, 3630 }, {3095, 3632}, {3098, 3633}, {3101, 3633 }, {3104, 3631}, {3106, 3629}, {3107, 3627}, {3108, 3624}, {3109, 3620}, {3108, 3617}, {3106, 3614}, {3102, 3613}, {3099, 3613}, {3097, 3613}, {3093, 3614}, {3090, 3617}, {3087, 3619} }; ArrayList&lt;Integer&gt; coordinates = new ArrayList&lt;Integer&gt;(); int random = Misc.random(coords.length - 1); if (getPlayersCount() &lt; coords.length) { if (coordinates.contains(coords[random][0], coords[random][1])) { random = Misc.random(coords.length - 1); } else { handler.move(coords[random][0], coords[random][1], 0); coords.add(coords[random][0], coords[random][1]); } } else { random = Misc.random(coords.length - 1); handler.move(coords[random][0], coords[random][1], 0); } </code></pre> <p>Basically, if there are less players than the array length, process. If coordinates arraylist contains generated X, Y, regenerate it, else move player and add the coords to the list.</p> <p>But it seems like I did something wrong, as I get this error: <code>error: no suitable method found for contains(int,int)</code></p> <p><em><strong>How can I do this?</em></strong></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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