aithread.java
来自「Java五子棋 支持本地游戏」· Java 代码 · 共 43 行
JAVA
43 行
import java.io.IOException;
/**
*
* this class creates a thread for a computer player
*
*/
class AIThread extends Thread
{
Player computerPlayer;
ChessGame game;
//the search engine of the computer player
SearchEngine engine;
AIThread(ChessGame game)
{
this.game = game;
this.computerPlayer = game.notLocalPlayer;
engine = new AlphaBetaEngine(game.mapSize, 2);
}
public void run()
{
//loop until game is over
while(game.status != GameStatus.Over)
{
//see if its computer's turn
if(this.computerPlayer != game.activePlayer)
{
this.suspend();
continue;
}
//search a move
engine.searchAGoodMove(game.chessMap, computerPlayer.chessMan);
ChessPos pos = engine.bestMove;
//play chess
game.playChess(pos.x, pos.y);
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?