谁能帮我看看哪里错了
var chess = document.getElementById("chess");
var me=true;
var context = chess.getContext('2d');
var chessboard=[];//二维数组棋盘
var wins=[]; //三维数组
var mywin=[];//
var computerwin=[]
var over=false;
var count=0;
drawchessboard();
winstyle();
clearchessboard();
function newgame(){
context.clearRect(0,0,450,450);
drawchessboard();
clearchessboard();
over=false;
me=true;
}
function clearchessboard() {
//定义二维数组,棋盘 都没下过时
for(var i=0;i<15;i++){
chessboard[i]=[];
for(var j=0;j<15;j++) {
chessboard[i][j]=0;
}
}
for(var i=0;i<count;i++) {
mywin[i]=0;
computerwin[i]=0;
}
}
chess.onclick = function(e){
if(over) {
return;
}
if(!me) {return;}
var x=e.offsetX;
var y=e.offsetY;
var i=Math.floor(x/30);
var j=Math.floor(y/30);
if(chessboard[i][j]==0) {
onestep(i,j,me);
chessboard[i][j]=1;
for(var k=0;k<count;k++) {
if(wins[i][j][k]==true) {
mywin[k]++;
computerwin[k]=99;
if(mywin[k]==5) {
window.alert("you win");
over=true;
}
}
}
if(over==false) {
me=!me;
computerAI();
}
}
}
var computerAI =function() {
var myscore=[];
var computerscore=[];
var m=0;
var u=0,v=0;
for(var i=0;i<15;i++) {
myscore[i]=[];
computerscore[i]=[];
for(var j=0;j<15;j++) {
myscore[i][j]=0;
computerscore[i][j]=0;
}
}
for(var i=0;i<15;i++) {
for(var j=0;j<15;j++) {
if(chessboard[i][j]==0) {
for(var k=0;k<count;k++) {
if(wins[i][j][k]) {
if(mywin[k]==1) {
myscore[i][j] +=200;
}
else if(mywin[k]==2) {
myscore[i][j] +=400;
}
else if(mywin[k]==3) {
myscore[i][j] +=2000;
}
else if(mywin[k]==4) {
myscore[i][j] +=10000;
}
if(computerwin[k]==1) {
computerscore[i][j] += 220;
}
else if(computerwin[k]==2) {
computerscore[i][j] += 420;
}
else if(computerwin[k]==3) {
computerscore[i][j] += 2100;
}
else if(computerwin[k]==4) {
computerscore[i][j] += 20000;
}
}
}
if(myscore[i][j]>m) {
m=myscore[i][j];
u=i;
v=j;
}
else if(myscore[i][j]==m) {
if(computerscore[i][j]>computerscore[u][v]) {
u=i;
v=j;
}
}
if(computerscore[i][j]>m) {
m=computerscore[i][j];
u=i;
v=j;
}
else if(computerscore[i][j]==m) {
if(myscore[i][j]>myscore[u][v]) {
u=i;
v=j;
}
}
}
}
}
console.log(m);
onestep(u,v,false);
chessboard[u][v]=2;
for(var k=0;k<count;k++) {
if(wins[u][v][k]) {
computerwin[k]++;
mywin[k]=99;
if(computerwin[k]==5) {
window.alert("computer win");
over=true;
}
}
}
if(!over) {
me=!me;
}
}
function winstyle() {
for(var i=0;i<15;i++) {
wins[i]=[];
for(var j=0;j<15;j++){
wins[i][j]=[];
for(var k=0;k<count;k++) {
wins[i][j][count]=false;
}
}
}
//赢法种类
//横向
for(var i=0;i<15;i++) {
for(var j=0;j<11;j++) {
for(var k=0;k<5;k++) {
wins[i][j+k][count]=true;
}
count++;
}
}
//竖向
for(var i=0;i<15;i++) {
for(var j=0;j<11;j++) {
for(var k=0;k<5;k++) {
wins[j+k][i][count]=true;
}
count++;
}
}
//\向
for(var i=0;i<11;i++) {
for(var j=0;j<11;j++) {
for(var k=0;k<5;k++) {
wins[i+k][j+k][count]=true;
}
count++;
}
//console.log(count);
///向
}
for(var i=0;i<11;i++) {
for(var j=14;j>3;j--) {
for(var k=0;k<5;k++) {
wins[i+k][j-k][count]=true;
}
count++;
}
}
console.log(count);
}
function onestep(i,j,me)
{
context.beginPath();
context.arc(15+i*30,15+j*30,13,0,2*Math.PI);
context.closePath();
var gradient=context.createRadialGradient(15+i*30+2,15+j*30-2,13,15+i*30+2,15+j*30-2,0);
if(me) {
gradient.addColorStop(0,"#0a0a0a");//黑
gradient.addColorStop(1,"#636766");//灰
}
else{
gradient.addColorStop(0,"#d1d1d1");//灰
gradient.addColorStop(1,"#f9f9f9");//白
}
context.fillStyle = gradient;
context.fill();
}
function drawchessboard(){
context.strokeStyle = "#bfbfbf";
for(var i=0;i<15;i++)
{
context.moveTo(15+30*i,15);
context.lineTo(15+30*i,435);
context.stroke();
context.moveTo(15,15+30*i);
context.lineTo(435,15+30*i);
context.stroke();
}
}
还有html部分
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>五子棋</title>
<link rel="stylesheet" type="text/css" href="css/main.css">
</head>
<body>
<p><button id="newgame" onclick="newgame()">new game</button></p>
<canvas id="chess" width="450px" height="450px">
</canvas>
<script type="text/javascript" src="js/main.js"></script>
</body>
</html>
css部分
@charset "utf-8";
/* CSS Document */
#chess{
border:1px solid red;
display:block;
margin:50px auto;
}
运行起来没有问题,但是每下完一盘点newgame按钮时,总会多一个小圈出来,而且那个小圈不会影响走位。