溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

怎么在微信小程序中實(shí)現(xiàn)五子棋游戲

發(fā)布時間:2021-06-04 17:34:30 來源:億速云 閱讀:653 作者:Leah 欄目:web開發(fā)

本篇文章給大家分享的是有關(guān)怎么在微信小程序中實(shí)現(xiàn)五子棋游戲,小編覺得挺實(shí)用的,因此分享給大家學(xué)習(xí),希望大家閱讀完這篇文章后可以有所收獲,話不多說,跟著小編一起來看看吧。

AI代碼

computerAI(){
  var playerScore = [],computerScore = [];
  var max = 0,u = 0, v = 0;
  for (var i = 0; i < this.type; i++){
   playerScore[i] = [];
   computerScore[i] = [];
   for (var j = 0; j < this.type; j++){
    playerScore[i][j] = 0;
    computerScore[i][j] = 0;
   }
  }
  for (var x = 0; x < this.type; x++) {
   for (var y = 0; y < this.type; y++) {
    var po = this.checkPosition(x, y);
    if (po.status == 0){
     for (var k = 0; k < this.count; k++) {
      if (this.WIN_ARRAY[x][y][k]){
       if (this.player[k] == 1){
        playerScore[x][y] += 10;
       } else if (this.player[k] == 2){
        playerScore[x][y] += 20;
       } else if (this.player[k] == 3) {
        playerScore[x][y] += 40;
       } else if (this.player[k] == 4) {
        playerScore[x][y] += 80;
       }
       if (this.computer[k] == 1) {
        computerScore[x][y] += 15;
       } else if (this.player[k] == 2) {
        computerScore[x][y] += 25;
       } else if (this.player[k] == 3) {
        computerScore[x][y] += 45;
       } else if (this.player[k] == 4) {
        computerScore[x][y] += 85;
       }
      }
     }
     if (playerScore[x][y] > max){
      max = playerScore[x][y];
      u = x;
      v = y;
     } else if (playerScore[x][y] == max){
      if (computerScore[x][y] > computerScore[u][v]){
       u = x;
       v = y;
      }
     }
     if (computerScore[x][y] > max) {
      max = computerScore[x][y];
      u = x;
      v = y;
     } else if (computerScore[x][y] == max) {
      if (playerScore[x][y] > playerScore[u][v]) {
       u = x;
       v = y;
      }
     }
    }
   }
  }
  var point = this.checkPosition(u,v);
  if(point.status == 0){
   this.oneStep(point);
   point.status = -1;
   this.COMPUTER_ARRAY.push(point);
   for (var i = 0; i < this.count; i++) {
    if (this.WIN_ARRAY[point.pointX][point.pointY][k]) {
     this.computer[k]++;
     this.player[k] = 100;
    }
   }
   if (point.status == -1 && this.COMPUTER_ARRAY.length >= this.CHESS_LEN && this.checkWin(point, this.COMPUTER_ARRAY)) {
    wx.showToast({ title: '白棋勝利!' });
    this.isStart = false;
   }
   if (this.isStart) {
    this.isWho = !this.isWho;
   }
  }
 }

以上就是怎么在微信小程序中實(shí)現(xiàn)五子棋游戲,小編相信有部分知識點(diǎn)可能是我們?nèi)粘9ぷ鲿姷交蛴玫降?。希望你能通過這篇文章學(xué)到更多知識。更多詳情敬請關(guān)注億速云行業(yè)資訊頻道。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI