unknown errors (ArrayIndexOutOfBoundsException) (chess engine)

edited April 2018 in Questions about Code

In my code, I have a chess engine, but when I play it, I usually never get to finish a game, because this error appears:

java.lang.ArrayIndexOutOfBoundsException: 63
at alight2.calculatevalue(alight2.java:193)
at alight2.depthvalue(alight2.java:277)
at alight2.depthvalue(alight2.java:238)
at alight2.depthvalue(alight2.java:268)
at alight2.depthvalue(alight2.java:238)
at alight2.minimax(alight2.java:307)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at processing.core.PApplet.method(PApplet.java:3730)
at processing.core.PApplet$2.run(PApplet.java:3768)

it is shown as red text in the console, and the game doesn't crash but the ai doesn't move. I have no idea what it is, and what caused it, but I do know that it only happens when the ai is running. I think it may be because I have a functions that calls itself over and over again, but that is the only way I know how to do minimax. Any help would be appreciated! files and data are in this link:https://drive.google.com/open?id=1RzAXEzEXAgAqDbRzOjX97ncquVZKYDYH same challenge as before, please just tell me what went wrong.


  • I don't think that is the problem, as out of bound exeptions usually crash the program, in my case the program doesn't stop, the ai just doesn't move. I have read it, but the console didn't tell me the problem.

  • I have no idea what it is, and what caused it

    It says on your console log line 1 that it is an ArrayIndexOutOfBoundsException.

    It says on console line 7 that it is "at alight2.minimax". That's a pretty specific place to get started.

    Do you have a function / method "minimax()"? For example, in ai.pde, on line 120?

  • yes, I do, but I don't know anything else about it that caused the error, and I have no other arrays exept PImage[][]s, and when those are out of bounds, it crashes the application, but this is very different.

  • edited April 2018

    Well, I don't know.

    It is an "array" error (ArrayIndexOutOfBoundsException), and you only have so many arrays addressed by this function. Further, it is an "index" error (ArrayIndexOutOfBoundsException), and you only pass array index arguments at certain times -- that should narrow it down to only a few lines.

    Maybe try debugging those lines? Add try / catch? You know the exact error name, so you could catch it....

    For one example, you are not passing in locationsglobal as an argument and then returning an updated version, which might be cleaner. Could there be some kind of racing or concurrent modifying happening there?

    Of course, it could be something else -- but that is a way to start narrowing it down....

  • How do I use try/catch

  • do I put the error name?

  • Did you see the link I gave you with an example, showing how to use try/catch, and where to put the error name?

  • I did go to the link

  • edited April 2018

    How do I use try/catch

    Like in the example I linked, by wrapping it around the code that might fail.

      try {
        line = reader.readLine();
      } catch (IOException e) {
        line = null;

    do I put the error name?


      try {
      } catch (ArrayIndexOutOfBoundsException e) {
        locationsminimax[i][j] = null;
  • I think I have the problem. The position variables in tab variables, sometimes they don't all have 63 values, I might have forgotten a comma somewhere and one int ended up as 50-63

Sign In or Register to comment.