othelloai.java
来自「JCreator下开发」· Java 代码 · 共 24 行
JAVA
24 行
// 电脑下棋
class OthelloAI
{
private int color;
public OthelloAI(int c)
{
if (!(c == Cyberthello.WHITE || c == Cyberthello.BLACK))//不是黑子也不是白字
throw new IllegalArgumentException("Invalid value for color: " + c);//抛出错误,落子颜色不对
color = c;//把颜色置成电脑所执的颜色
}
public Move chooseMove(OthelloBoard board)
{
for (int r = 0; r < 8; ++r)
for (int c = 0; c < 8; ++c)
{
Move move = new Move(r, c);
if (board.isValidMove(move, color))
return move;
}
return Move.pass;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?