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!
<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+='_'}}
<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>
Bookmarks