资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

怎么在微信小程序中实现五子棋游戏-创新互联

本篇文章给大家分享的是有关怎么在微信小程序中实现五子棋游戏,小编觉得挺实用的,因此分享给大家学习,希望大家阅读完这篇文章后可以有所收获,话不多说,跟着小编一起来看看吧。

创新互联建站是一家专注网站建设、网络营销策划、成都微信小程序、电子商务建设、网络推广、移动互联开发、研究、服务为一体的技术型公司。公司成立十余年以来,已经为上千发电机租赁各业的企业公司提供互联网服务。现在,服务的上千客户与我们一路同行,见证我们的成长;未来,我们一起分享成功的喜悦。

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://cdkjz.cn/article/eshsp.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:400-028-6601 / 大客户专线   成都:13518219792   座机:028-86922220