**
this causes an extra move to made in this gomoku game beyond the winning move and the checkForWin metho after the extra move is the method that detects the win but it should be the checkForWin method immediately after the corresponding makeMove method.
**
import java.io.File;
boolean hasWinner = false;
File gameFile = new File("src/centralGameFile.txt");
do{
//player 1
makeMove(gameFile);
// check for win
if (checkForWin(gameFile)){
hasWinner = true;
break;
}
// player 2
makeMove(gameFile);
// check for win
if (checkForWin(gameFile)){
hasWinner = true;
break;
}
}while(hasWinner == false);
System.out.println("somebody has won the game");
/*this method is located in another class in the same package and is
called from an instance of the class using the access operator */
protected boolean checkForWin(File f){
//return true if the file has a winner in it using scanner to look for it
//this method works correctly when tested with just a file in a test class
}
// try/catch blocks omitted for brevity
/* makeMove(File f) method copies the text from f and over writes
it adding another character; in context this is a gomoku/tic-tac-toe
style game but on a bigger board.
*/
a part of your code:
If
checkForWin
returnstrue
, your method must be hanging atmakeMove(gameFile)
. This is possibly stuck in some infinite loop.