I ran Main.java with the initial mode to be "Frightened". Then I provided my name and difficulty to the program. Moreover, I input "Left" for Pacman to got left. I expected to see a maze in which Pacman moved to the left on the console, but instead, this was the output: Exception in thread "main" java.lang.IndexOutOfBoundsException: Index 0 out of bounds for length 0 at java.base/jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:64) at java.base/jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Preconditions.java:70) at java.base/jdk.internal.util.Preconditions.checkIndex(Preconditions.java:266) at java.base/java.util.Objects.checkIndex(Objects.java:359) at java.base/java.util.ArrayList.get(ArrayList.java:427) at Game.Game.moveGhosts(Game.java:244) at Game.Game.handleMovements(Game.java:165) at Game.Game.gameTick(Game.java:83) at Game.Main.main(Main.java:55)
Solution: ArrayList of algs in Frightened.java is not null when retrieved to Game.java. I changed to checking condition in boolean moveGhosts() in Game.java from if(algs!=null) to if (algs.size()!=0)