image thumbnail
from Cohesion Adhesion Balls by Krishna Lalith
Player having the last move wins the game.

[C_A_B,Box]=Condition(Xnew,Ynew,SXnew,SYnew,C_A_B,Box)
function [C_A_B,Box]=Condition(Xnew,Ynew,SXnew,SYnew,C_A_B,Box)

%at each point there are '3' checks(>=<)
%--------------------------------------------------------------------------
   if C_A_B(Xnew,Ynew)==C_A_B(SXnew,SYnew)
       C_A_B(Xnew,Ynew)=0;
       Box(Xnew,Ynew)=0;
       C_A_B(SXnew,SYnew)=0;
       Box(SXnew,SYnew)=0;
   end
   
   if C_A_B(Xnew,Ynew) > C_A_B(SXnew,SYnew)       
       C_A_B(SXnew,SYnew)=C_A_B(Xnew,Ynew);
       Box(SXnew,SYnew)=1;
       C_A_B(Xnew,Ynew)=0;
       Box(Xnew,Ynew)=0;
   end
   
   if C_A_B(Xnew,Ynew) < C_A_B(SXnew,SYnew)
       Box(SXnew,SYnew)=1;
       C_A_B(Xnew,Ynew)=0;
       Box(Xnew,Ynew)=0;       
   end
%--------------------------------------------------------------------------

Contact us at files@mathworks.com