为了账号安全,请及时绑定邮箱和手机立即绑定
  • if (this.chessList.length > 0) { deleteItem = this.chessList.pop(); for (var i = 0; i < this.count; i++) { if (deleteItem[2]) { if (this.myWin[i] && this.wins[deleteItem[0]][deleteItem[1]][i]) { if (this.myWin[i] < 999) { this.myWin[i]--; } this.otherWin[i] -= 999; } } else { if (this.otherWin[i] && this.wins[deleteItem[0]][deleteItem[1]][i]) { if (this.otherWin[i] < 999) { this.otherWin[i]--; } this.myWin[i] -= 999; } } } this.chessBoard[deleteItem[0]][deleteItem[1]] = 0; } else { this.type = !this.type; } this.resetFn(); },
    查看全部
  • // 为canvas添加背景图片 var logo = document.getElementById('img'); this.context.drawImage(logo, 0, 0, this.windowWidth - 50, this.windowWidth - 50) // 画棋盘 this.darwChessboard(); }, // 悔棋 takeBackFn: function () { if (this.takeBack && this.chessList.length > 0) { return; } this.takeBack = true; var deleteItem = this.chessList.pop(); this.chessBoard[deleteItem[0]][deleteItem[1]] = 0; for (var i = 0; i < this.count; i++) { if (deleteItem[2]) { if (this.myWin[i] && this.wins[deleteItem[0]][deleteItem[1]][i]) { if (this.myWin[i] < 999) { this.myWin[i]--; } this.otherWin[i] -= 999; } } else { if (this.otherWin[i] && this.wins[deleteItem[0]][deleteItem[1]][i]) { if (this.otherWin[i] < 999) { this.otherWin[i]--; } this.myWin[i] -= 999; } } }
    查看全部
  • // 开始 startFn: function () { if (this.start) { return; } var isComputAI = document.getElementsByClassName('active')[0].getAttribute('data-type'); if (isComputAI === '1') { this.isAI = true; } this.over = false; this.start = true; this.startBtn.classList.add('admit_btn'); this.startBtn.classList.remove('start_btn'); this.admitted.classList.remove('admit_btn'); this.admitted.classList.add('start_btn'); this.back.classList.remove('admit_btn'); this.back.classList.add('start_btn'); this.resetting.classList.add('reset_btn'); this.resetting.classList.remove('admit_btn'); this.admit = true; this.reset = true; }, // 重置 resetFn: function () { // 获取canvas实例并自适应 var chessDom = document.getElementById('chess'); this.chessDom = chessDom; this.context = chessDom.getContext('2d'); this.context.strokeStyle = '#BFBFBF';
    查看全部
  • // 点击重置按钮 this.resetting.onclick = function () { if (!that.reset) { if (that.over && !that.start) { that.tip = '游戏未开始'; } alert(that.tip); return; } that.initData(); that.startBtn.classList.remove('admit_btn'); that.startBtn.classList.add('start_btn'); that.admitted.classList.add('admit_btn'); that.admitted.classList.remove('start_btn'); that.back.classList.add('admit_btn'); that.back.classList.remove('start_btn'); that.resetting.classList.remove('reset_btn'); that.resetting.classList.add('admit_btn'); that.resetFn(); } // 对战模式选择 document.getElementsByClassName('text_ct')[0].onclick = function (e) { if (that.start) { return; } var index = Number(e.target.getAttribute('data-type')); if (index === that.index) { return; } var children = this.children; children[that.index].classList.remove('active'); children[index].classList.add('active'); that.index = index; } },
    查看全部
  • // 初始化方法 init: function () { this.initData(); this.initCanvasData(); // 初始化canvas数据 }, initCanvasData: function () { var that = this; this.resetFn(); // 点击开始按钮 this.startBtn.onclick = function () { that.startFn(); } // 点击认输按钮 this.admitted.onclick = function () { if (!that.admit) { if (that.over && that.start) { that.tip = '游戏已结束'; } else if (that.over && !that.start) { that.tip = '游戏未开始'; } alert(that.tip); return; } if (that.type) { alert('你输了') that.over = true; that.admit = false; that.admitted.classList.add('admit_btn'); that.admitted.classList.remove('start_btn'); } } // 点击悔棋按钮 this.back.onclick = function () { if (!that.admit) { if (that.over && that.start) { that.tip = '游戏已结束'; alert(that.tip); return; } else if (that.over && !that.start) { that.tip = '游戏未开始'; alert(that.tip); return; } } that.takeBackFn(); }
    查看全部
  • window.onload = function () { var chess = { tip: '', // 提示消息 windowWidth: document.documentElement.clientWidth, // 当前窗口可见宽度 windowHeight: document.documentElement.clientHeight, // 当前窗口可见高度 startBtn: document.getElementById('startBtn'), // 开始按钮 admitted: document.getElementById('admitted'), // 认输按钮 back: document.getElementById('back'), // 悔棋按钮 resetting: document.getElementById('resetting'), // 重置按钮 initData: function () { this.start = false; // true--游戏开始(点击开始按钮) false--游戏结束 this.reset = false; // 重置 true--重置按钮可点 false--重置按钮不可点 this.over = true; // true--游戏结束 false--游戏开始中 this.admit = false; // true--认输按钮可点 false--认输按钮不可点 this.type = true; // true--黑子 false--白子 this.isAI = false; // true--人机 false--非人机 // 初始化落子二维数组 this.chessBoard = []; this.wins = []; // 赢法数组 this.count = 0; // 初始化棋盘变量 this.num = 15; // 赢法的统计数组 this.myWin = []; this.otherWin = []; this.index = 0; this.takeBack = false; this.chessList = []; },
    查看全部
  • body { background: #495C65; } canvas { display: block; margin: auto auto; box-shadow: -3px -3px 3px #EFEFEF, 5px 5px 5px #B9B9B9; /*background: url('../images/chess.jpg') no-repeat; background-size: cover;*/ } .chessTitle { margin: 10px 0px; line-height: 40px; text-align: center; font-family: '微软雅黑'; font-size: 36px; } .chessTitle[data-text]::after { content: attr(data-text); color: #FFFFFF; -webkit-mask-image: -webkit-gradient(linear, 0 0, 0 bottom, from(#FBD1CE), to(rgba(204, 126, 11, 0))); } .btn_box { margin-top: 20px; } .btn_box .btn { margin: 10px auto; width: 3rem; height: 2rem; line-height: 2rem; text-align: center; border-radius: 50%; } .btn_box .start_btn { background-color: darkorange; } .btn_box .reset_btn { background-color: aqua; } .btn_box .admit_btn { background-color: gainsboro; } .text_ct { height: 2rem; line-height: 2rem; text-align: center; color: #FFFFFF; } .active { background: #F99707; }
    查看全部
  • 遍历未落子的交叉点,然后基于规则为该交叉点计算得分,最后得分最高的点即为计算机准备落子的点,考虑两个方面:①计算机连上5颗子②阻止我们连上5颗子
    查看全部
  • 在所有走法中选出评估分数最大的一步
    查看全部
  • 解决5个子判定的bug if(chessBoard[i][j]==0){ oneStep(i,j,me); if(me){ chessBoard[i][j] = 1; }else{ chessBoard[i][j] = 2; } for(var k=0; k<count; k++){ if(wins[i][j][k]){ if(me){ myWin[k]++; aiWin[k] = 6; }else{ aiWin[k]++; myWin[k] = 6; } } if(myWin[k]==5){ window.alert("You win!"); over = true; }else if(aiWin[k]==5){ window.alert("AI win!"); over = true; } } me=!me; }
    查看全部
  • ai
    查看全部
  • 我的笔记
    查看全部
    0 采集 收起 来源:课程介绍

    2016-04-28

  • 使劲学!
    查看全部
  • 努力学习!
    查看全部
  • 哈哈,在学习?
    查看全部
    0 采集 收起 来源:课程介绍

    2016-04-27

举报

0/150
提交
取消
课程须知
本课程是前端高级课程 1、具备算法基础
老师告诉你能学到什么?
1、五子棋AI的运行原理 2、五子棋AI使用到的数据结构 3、编程实现五子棋AI

微信扫码,参与3人拼团

意见反馈 帮助中心 APP下载
官方微信
友情提示:

您好,此课程属于迁移课程,您已购买该课程,无需重复购买,感谢您对慕课网的支持!