-
思路:
1、遍历整个棋盘的点,找到还没有被落子的点
2、基于规则计算出每个点的得分,基于得分排序中最高的点落子
规则:
1、让计算机连上五颗子
2、阻止人连上五颗子
查看全部 -
掌握基本AI知识查看全部
-
wins[][][]:赢法数组 mywin=[]; 我方赢法统计数组 computerwin=[]:计算机方统计数组查看全部
-
} } } this.chessBoard[u][v] = 2; this.type = !this.type; }, // 落子函数 i--X轴交叉点下标 j--Y轴交叉点下标 type--true为黑子,false为白子 backGauge--棋盘边框线宽度 oneStep: function (i, j, type, backGauge) { this.context.beginPath(); this.context.arc(backGauge + i * this.residue, backGauge + j * this.residue, Math.floor(this.residue / 2) - 3, 0, 2 * Math.PI); this.context.closePath(); var gradient = this.context.createRadialGradient(backGauge + i * this.residue + 2, backGauge + j * this.residue - 2, Math.floor(this.residue / 2) - 3, backGauge + i * this.residue + 2, backGauge + j * this.residue - 2, 0); if (type) { gradient.addColorStop(0, '#0A0A0A'); gradient.addColorStop(1, '#636766'); } else { gradient.addColorStop(0, '#D1D1D1'); gradient.addColorStop(1, '#F9F9F9'); } this.context.fillStyle = gradient; this.context.fill(); } }; chess.init(); };查看全部
-
for (var x = 0; x <= this.num; x++) { for (var y = 0; y <= this.num; y++) { if (this.wins[x][y][k] && this.chessBoard[x][y] === 0) { if ((x-q)*(x-q) === 1 ||(y-w)*(y-w) === 1 ) { u = x; v = y; } } } } } } } } } } } } } this.chessList.push([u, v, this.type]); this.oneStep(u, v, this.type, this.backGauge); for (var k = 0; k < this.count; k++) { if (!this.type && this.wins[u][v][k]) { this.myWin[k] += 999; if (this.otherWin[k] < 999) { this.otherWin[k]++; if (this.otherWin[k] >= 5) { alert('电脑赢了'); this.over = true; this.admit = false; this.admitted.classList.add('admit_btn'); this.admitted.classList.remove('start_btn'); this.back.classList.add('admit_btn'); this.back.classList.remove('start_btn'); }查看全部
-
for (var x = 0; x <= this.num; x++) { for (var y = 0; y <= this.num; y++) { if (this.wins[x][y][k] && this.chessBoard[x][y] === 0) { if ((x-q)*(x-q) === 1 ||(y-w)*(y-w) === 1 ) { u = x; v = y; } } } } } } } } } if (aIScore[i][j][l] === max) { for (var m = 1; m < 5; m++) { if (myScore[i][j][m] > maxScore) { maxScore = myScore[i][j][m]; u = i; v = j; } else if (myScore[i][j][m] === maxScore) { for (var k = 0; k < this.count; k++) { if (this.otherWin[k] === l) { for (var x = 0; x <= this.num; x++) { for (var y = 0; y <= this.num; y++) { if (this.wins[x][y][k] && this.chessBoard[x][y] === 2) { q = x; w = y; } } }查看全部
举报
0/150
提交
取消