Ludii Forum
out of bounds - when doing comparison of two regionSite values - Printable Version

+- Ludii Forum (https://ludii.games/forums)
+-- Forum: Problems (https://ludii.games/forums/forumdisplay.php?fid=5)
+--- Forum: Ludii Player Problems (https://ludii.games/forums/forumdisplay.php?fid=6)
+--- Thread: out of bounds - when doing comparison of two regionSite values (/showthread.php?tid=991)



out of bounds - when doing comparison of two regionSite values - dale walton - 06-04-2022

MCTS error in game: Soup
java.lang.ArrayIndexOutOfBoundsException
MCTS error in game: Soup
java.lang.ArrayIndexOutOfBoundsException
Exception in thread "Thread-1460" java.lang.ArrayIndexOutOfBoundsException
Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException
java.lang.ArrayIndexOutOfBoundsException
java.lang.ArrayIndexOutOfBoundsException
java.lang.ArrayIndexOutOfBoundsException
java.lang.ArrayIndexOutOfBoundsException
java.lang.ArrayIndexOutOfBoundsException


The offending code is in this define

The script would work for a few moves and then everything would disappear, when a potential move would require this define to be evaluated.
I later commented out an ifAfterwards condition on the moves, and then got the error:

Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException
when the consequence needed to be used.


My guess is that the index:1 might be pointing to a non-included site, such as one without a mover.. and thus have a value of -1 instead of the value of the second member of the set.
Please document this ludeme better it that is the intent. However, if the ludeme is offered, it doesn't seem it should give us this kind of view of the inner workings, but rather a consistent extraction ordering of only valid values.

(I trust index:0 never is -1 if there is any valid result.)

I also found problems in a different script when I tried to access arrayValues by index number in (values Remembered) 

(define "PlacedTerminal2Core"
(if
  (or
  (< 2
    (count Pieces Mover
    in:(sites Around (last To))
  ))
  (and
    (= 2
    (count Pieces Mover in:(sites Around (last To)))
    )
    (< 1
    (count Steps
      (regionSite (intersection (sites Occupied by:Mover) (sites Around (last To))) index:0)
      (regionSite (intersection (sites Occupied by:Mover) (sites Around (last To))) index:1)
  ))))
  (add (to (site)) stack:True)
))


Game is being played on board with use:Vertex
Th define is trying to add a piece on top if the newly placed piece if it is NEITHER

A) isolated
B) next to one friendly piece
C) next to 2 friendly pieces that for a small triangle.

Since my approach to coding in Ludii is evolutionary trial and error, I no longer have the entire script...

------------------
I just tried:
(and
    (= 2
      (size Array (array (intersection (sites Occupied by:Next) (sites Around (last To)))))
    )
    (= 1
      (count Steps
      (min (array (intersection (sites Occupied by:Next) (sites Around (site)))))
      (max (array (intersection (sites Occupied by:Next) (sites Around (site)))))
  ))))


and I am still getting the error. 73 is the number of cells in the board and the game only uses vertexes, so there may be a problem with not checking the default for this correctly.

MCTS error in game: Soup
java.lang.ArrayIndexOutOfBoundsException: Index -1 out of bounds for length 73
at game.rules.play.moves.nonDecision.effect.Add.eval(Add.java:198)
at game.rules.play.moves.nonDecision.operators.logical.If.eval(If.java:122)
at game.rules.play.moves.nonDecision.operators.logical.And.eval(And.java:152)
at other.move.Move.apply(Move.java:522)
at game.Game.applyInternal(Game.java:2848)
at game.Game.apply(Game.java:2815)
at game.Game.apply(Game.java:2759)
at other.model.AlternatingMove.playout(AlternatingMove.java:633)
at game.Game.playout(Game.java:3446)
at search.mcts.playout.RandomPlayout.runPlayout(RandomPlayout.java:48)
at search.mcts.MCTS.lambda$selectAction$0(MCTS.java:707)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:829)
Exception in thread "Thread-19" java.lang.ArrayIndexOutOfBoundsException: Index -1 out of bounds for length 73
at game.rules.play.moves.nonDecision.effect.Add.eval(Add.java:198)
at game.rules.play.moves.nonDecision.operators.logical.If.eval(If.java:122)
at game.rules.play.moves.nonDecision.operators.logical.And.eval(And.java:152)
at other.move.Move.apply(Move.java:522)
at game.Game.applyInternal(Game.java:2848)
at game.Game.apply(Game.java:2815)
at game.Game.apply(Game.java:2759)
at search.minimax.AlphaBetaSearch.alphaBeta(AlphaBetaSearch.java:631)
at search.minimax.AlphaBetaSearch.alphaBeta(AlphaBetaSearch.java:590)
at search.minimax.AlphaBetaSearch.alphaBeta(AlphaBetaSearch.java:632)
at search.minimax.AlphaBetaSearch.iterativeDeepening(AlphaBetaSearch.java:354)
at search.minimax.AlphaBetaSearch.selectAction(AlphaBetaSearch.java:228)
at other.ThinkingThread$ThinkingThreadRunnable.run(ThinkingThread.java:188)
at java.base/java.lang.Thread.run(Thread.java:829)

Sorry - it turned out to be much simpler - I found the bug in my code:
(add (to (site)) stack:True)

Should have been
(add (to (last To)) stack:True)