如何在微信小程序中实现五子棋游戏-古蔺大橙子建站
RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
如何在微信小程序中实现五子棋游戏

这篇文章主要介绍了如何在微信小程序中实现五子棋游戏的相关知识,内容详细易懂,操作简单快捷,具有一定借鉴价值,相信大家阅读完这篇如何在微信小程序中实现五子棋游戏文章都会有所收获,下面我们一起来看看吧。

创新互联是一家专业提供乐平企业网站建设,专注与网站设计、成都网站设计、HTML5、小程序制作等业务。10年已为乐平众多企业、政府机构等服务。创新互联专业的建站公司优惠进行中。

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;
   }
  }
 }

关于“如何在微信小程序中实现五子棋游戏”这篇文章的内容就介绍到这里,感谢各位的阅读!相信大家对“如何在微信小程序中实现五子棋游戏”知识都有一定的了解,大家如果还想学习更多知识,欢迎关注创新互联行业资讯频道。


当前文章:如何在微信小程序中实现五子棋游戏
网页链接:http://scgulin.cn/article/ijehsj.html