0

So I'm doing a search method and my HashSet<GameBoard> explored has all the explored states. I need to add more states to "explored" so I don't check the same state over and over again. I need to compare states with a copy of itself and if the VALUE of them are the same, I don't check it again. I know I have to override the .equals()method in Obj class for it to do a deep search and I did just that. Below is my equals method.

public boolean equals  (GameBoard a){
    for(int j = 0;j < a.len;j++){
        if(a.boardArr[j] != this.boardArr[j]){
            return false;
        }
    }
    return true;
}

I add GameBoard to explored using explored.add(state);. But this doesn't seem to do anything. I even commented out the equals method completely and the result is the same. It keeps adding the same state to the explored state and hence I have an infinite loop. Really need some help here does anyone know how to solve this?

Nathan
  • 350
  • 1
  • 2
  • 11
  • 1
    The param type needs to be Object. SImply put the @Override annotation on methods that you think override something, and the compiler will tell you when you got something wrong! – GhostCat Sep 21 '18 at 19:08
  • @rabbitguy The method has the wrong signature. It is not relevant what it is doing until that is fixed. – GhostCat Sep 21 '18 at 19:08
  • Sorry I used just as a general object, which is gameboard, I'll edit it – Nathan Sep 21 '18 at 19:17
  • I mean: the parameter for the equals method is wrong! – GhostCat Sep 21 '18 at 19:40

0 Answers0