chesscompute.java~1~

来自「手机端游戏开发程序」· JAVA~1~ 代码 · 共 32 行

JAVA~1~
32
字号
package chess;

public class Chess {
  static int COMPUTER = 2;
  static int MAN = 1;
  int position = 0, bestX = 0, bestY = 0;
  int board[][] = new int[16][16];

  public Chess() { //构造函数,初始化棋盘
    for (int i = 0; i < 16; i++) {
      for (int j = 0; j < 16; j++) {
        board[i][j] = 0;
      }
    }

  }

  private void updateChessboard(int x, int y, int who) {
    board[x][y] = who; //who走到了x,y
  }

  public void getNextPositon(int x, int y) {
    this.updateChessboard(x, y, MAN); //人走到x,y-->更新了board[][]
    Analyse aa = new Analyse(this.board);
    this.position = aa.computerDo();
    this.bestY = position % 100 - 1;
    this.bestX = position / 100 - 1; //分析得到电脑最佳的下一步
    this.updateChessboard(this.bestX, this.bestY, COMPUTER); //电脑走了bestX,bestY,更新board[][]

  }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?