image thumbnail

MOO Maker

by

 

A variant of classical "MOO" or "Cows n Bulls" game.

MOO(action)
function MOO(action)

global fig moomat Guess ghands hnd moonum;
clc
%--------------------------------------------------------------------------
if nargin < 1,  
    moomat=[ThinkNumber();ThinkNumber();ThinkNumber();ThinkNumber()];
    for ii=1:4,
        for jj=1:4,
            if length(find(moomat(:,ii)==moomat(jj,ii)))>1,
                possinum=[];
                for kk=0:9,
                    if isempty(find(moomat(jj,:)==int2str(kk))) && isempty(find(moomat(:,ii)==int2str(kk))),
                        possinum=[possinum int2str(kk)];                            
                    end
                end
                moomat(jj,ii)=possinum(1+mod(fix(10*rand(1,1)),length(possinum)));
            end
        end
    end
%     moomat
    Guess=['0000';'0000';'0000';'0000'];
    
    fig=figure('Name','MOO','NumberTitle','off','Visible','off',...
               'units','centimeters','position',[5 5 10 10]);
         
    %Guess Handles 
    moonum=ThinkNumber();
    for ii=1:4,
        cdata=imread([moonum(ii),'.tif']);
        uicontrol('style','pushbutton','units','centimeters',...
                  'position',[1+ii 8 1 2],'cdata',cdata); 
    end 
    
    %Hint Handles
    x=2:5;
    y=6:-1:3; 
    for ii=1:4,
        for jj=1:4,
            cdata=imread([Guess(jj,ii),'.tif']);
            ghands(ii,jj)=uicontrol('style','pushbutton','units','centimeters',...
                                    'position',[x(ii) y(jj) 0.8 0.8],'userdata',0,...
                                    'callback',{@board,ii,jj},'cdata',cdata); 
        end
    end 
    
    %Option Handles
    x=[6*[1 1 1 1] 2:5];
    y=[6:-1:3 2*[1 1 1 1]]; 
    Opt_Name=[...,
              '0b0c'; '0b1c'; '1b0c';
              '0b2c'; '1b1c'; '2b0c';
              '0b3c'; '1b2c'; '2b1c'; '3b0c';
              '0b4c'; '1b3c'; '2b2c'; '3b1c'; '4b0c'];
          
    for ii=1:8,
        if ii<=4;
            guesser=moomat(ii,:);
        else
            guesser=moomat(:,ii-4);
        end
%         guesser
        BC=BsCs(guesser);
        for jj=1:15,
            if Opt_Name(jj,:)==BC, break; end
        end
        cdata=imread([Opt_Name(jj,:),'.tif']);
        uicontrol('style','pushbutton','units','centimeters',...
                  'position',[x(ii) y(ii) 1 1],'cdata',cdata);        
    end
    
    %creating default buttons
    uicontrol('units','centimeters','position',[8 6 1 0.6],...
                'string','New','callback','MOO(''New'')',...
                'interruptible','on','BackgroundColor','w');
            
    uicontrol('units','centimeters','position',[8 5 1 0.6],...
                'string','Rules','callback','MOO(''Rules'')',...
                'interruptible','on','BackgroundColor','w');
            
    hnd=uicontrol('units','centimeters','position',[8 4 1 0.6],...
                'string','Ans.','callback','MOO(''Ans'')',...
                'interruptible','on','BackgroundColor','w');
            
    uicontrol('units','centimeters','position',[8 3 1 0.6],...
                'string','Exit','callback','delete(gcf)',...
                'interruptible','on','BackgroundColor','w');
                    
    figure(fig);
    action='';
end
%--------------------------------------------------------------------------
if strcmp(action,'New'),
    closereq;
    MOO();
end
%--------------------------------------------------------------------------
if strcmp(action,'Ans'),
    if strcmp(get(hnd,'string'),'Ans.'),
        for ii=1:4,
            for jj=1:4,
                cdata=imread([moomat(jj,ii),'.tif']);
                set(ghands(ii,jj),'cdata',cdata); 
            end
        end 
        set(hnd,'string','Clear','BackgroundColor',[1 0.6 0.3]);
    else
        for ii=1:4,
            for jj=1:4,
                cdata=imread([Guess(jj,ii),'.tif']);
                set(ghands(ii,jj),'cdata',cdata); 
            end
        end 
        set(hnd,'string','Ans.','BackgroundColor','w');
    end
end
%--------------------------------------------------------------------------
if strcmp(action,'Rules'),
    msg={'MOO Game Rules:'...
         '     1) UUU will guess the HINTS assumed by CPU.',...
         '     2) 8 Hints has information of Blacks & Whites.',...
         '     3) BLACK represents Correct Color in Correct Position.',...
         '     4) WHITE represents Correct Color in Wrong Position.',...
         '     5) CODE is displayed on the Circular Dial.',...
         '     6) All the NUMBERS in a ROW/COLUMN should be distinct.'};
     
    msgbox(msg,'MOO','help');    
end
%--------------------------------------------------------------------------
if strcmp(action,'Exit') 
    closereq;
end
%--------------------------------------------------------------------------

Contact us