Hey guys! Don't kniw if this is the right place to put this, but i'm looking for a little help in creating a Tic-Tac-Toe game code. At the moment, it can reconise if the players wins the game, but if the computer wins, it doesn't reconise. Any help would be appricated!


<HTML>
<HEAD><TITLE>TicTacToe</TITLE>

<div align="center";
</div>
<META http-equiv=Content-Type content="text/html; charset=UTF-8">
<STYLE type=text/CSS>
.b{background-color:Red;height:40px;width:40px}
</STYLE>

<style type="text/css">
p.ex1 {margin:2cm 4cm 3cm 4cm}
</style>


<SCRIPT type="text/javascript">
var wins=['--X-X-X--','X---X---X','X--X--X--','-X--X--X-','--X--X--X','XXX------','---XXX---','------XXX']
var t=''; var m1=[]; var m2=[]; var mt=[]; var moved=0;

function win(z){for(i=0;i<fe.length;i++){if(wins[z].charAt(i)=='X'){fe[i].style.backgroundColor='lime'}}}
function cp(z,arr){
for(i=0;i<wins[z].length;i++){if(wins[z].charAt(i)=='X' && t.charAt(i)=='_'){fe[i].value='O';moved=1;return } }
move(z+=1,arr);
}
function move(z,arr){var n;
if(arr[z]!=undefined){ for(i=0;i<wins.length;i++){if(wins[i]==arr[z]){n=i}} cp(n,arr);}
else{var mt=[]; for(i=0;i<t.length;i++){ if(t.charAt(i)=='_'){mt.push(i)} } if(mt.length>0){ mt.sort(function(a,b){return Math.random()-0.5}); fe[mt[0]].value='O';moved=1 } }
}

function d(){ t=''; moved=0; m1=[]; m2=[]; var b=new Array('0','0','0','0','0','0','0','0');
for(i=0;i<fe.length;i++){if(fe[i].value=='X'){t+='X'} else if(fe[i].value=='O'){t+='O'} else{ t+='_'}}

for(i=0;i<wins.length;i++){
for(j=0;j<wins[i].length;j++){
if(t.charAt(j)==wins[i].charAt(j) ){ b[i]++}
}
}

for(i=0;i<b.length;i++){ if(b[i]==3){win(i);moved=1;return}
else if(b[i]==2){m2.push(wins[i]);}
else if(b[i]==1){m1.push(wins[i]);}
}


if(moved==0 && m2.length>0){m2.sort(function(a,b){return Math.random()-0.5});move(0,m2); }
else if(moved==0 && m1.length>0){m1.sort(function(a,b){return Math.random()-0.5});move(0,m1)}

// document.getElementById('a').innerHTML=t+'<br>'+b+'<br>'+m1+'<br>'+m2


}
</SCRIPT>



<META content="MSHTML 6.00.2900.2963" name=GENERATOR></HEAD>
<BODY scroll="auto">
<div style="width:500px;height:100px;border:2pxlpx Solid Blue;">
<h3> Welcome to Tic-Tac-Toe! </h3>
<p> The aim of the game is to get 3 crosses in a row! Try not to let the circles win though! Click on a square to start the game. Good luck! </p>
<TABLE BORDER=1>
<TR>
<TD> a </TD>
<TD><SCRIPT type="text/javascript"> var t='<form>'
for(i=0;i<9;i++){ if(i!=0 && i%3==0){t+='<br>'}
t+='<input type=button onclick="if(!this.value){this.value=\'X\';d()}" class="b" value=\'\'>'}
document.write(t+'</form>');
var fe=document.forms[0].elements;


</SCRIPT>


</TD>
</TR>
<TR>
<TD> c </TD>
<TD> d </TD>
</TR>
</TABLE>

<div align="center">
<SCRIPT LANGUAGE="JavaScript">

document.write('<form><input type=button value="Refresh" onClick="history.go()"></form>')
// End -->
</script>
</div>

&copy James Hardwick
<div id="a"></div>
</BODY></HTML>