Closed. This question does not meet Stack Overflow guidelines。它当前不接受答案。
想改善这个问题吗? Update the question,所以它是on-topic,用于堆栈溢出。
6年前关闭。
这导致该gomoku游戏中的动作超出了
获胜的举动和
额外移动后的checkForWin方法是检测获胜的方法,但是
在对应的makeMove之后,应该立即使用checkForWin方法
方法。
**
//为简洁起见,省略了try / catch块
您的代码的一部分:
如果
想改善这个问题吗? Update the question,所以它是on-topic,用于堆栈溢出。
6年前关闭。
**
这导致该gomoku游戏中的动作超出了
获胜的举动和
额外移动后的checkForWin方法是检测获胜的方法,但是
在对应的makeMove之后,应该立即使用checkForWin方法
方法。
**
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块
/* 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.
*/
最佳答案
checkForWin works correctly when tested with just a file in a test class
您的代码的一部分:
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");
如果
checkForWin
返回true
,则您的方法必须挂在makeMove(gameFile)
处。这可能会陷入一些无限循环中。关于java - 为什么为true时checkforWin(File f)不返回true? ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/18167984/
10-09 03:04