void ai_move(){ static int priority[3][3],p,no,nx,s[9],c,i,j; for(i=0;i<3;i++) { no=0; nx=0; for(j=0;j<3;j++) { if(box[j]==-1) no++; if(box[j]==1) nx++; } if(no+nx == 3) p=10; if(no==2 && nx==0) p=0; if(no==0 && nx==2) p=1; if(no==0 && nx==0) p=2; if(no==1 && nx==0) p=3; if(no==0 && nx==1) p=4; for(j=0;j<3;j++) priority[j]=p; } for(j=0;j<3;j++) { no=0; nx=0; for(i=0;i<3;i++) { if(box[j]==-1) no++; if(box[j]==1) nx++; } if(no+nx == 3) p=10; if(no==2 && nx==0) p=0; if(no==0 && nx==2) p=1; if(no==0 && nx==0) p=2; if(no==1 && nx==0) p=3; if(no==0 && nx==1) p=4; for(i=0;i<3;i++) priority[j]+=p; } for(int a=0;a<9;a++) { for(i=0;i<3;i++) { for(j=0;j<3;j++) { if(priority[j]==a && box[j]==0) { s[c]=(j*3)+i; c++; } } } if(c>0) break; } int q=random(0,c-1); domove(s[q]); if(complete_check()==1) finished();}
In this function, priority[3][3] is an array that stores the priority number of each block and the one with least priority is what the AI moves...
"no" and "nx" store the number of O's and X's respectively.
The problem is that the priority calculation has some error(I guess so) which i am unable to find...Or if there is some other problem, that i don't know about....
Please somebody help me...This AI has really made me mad :(