7th Guest Germ Game

by

 

The microscope game from 7th guest with simple 'AI'.

[x1,y1,x2,y2]=guestzet(A,turn,method)
function [x1,y1,x2,y2]=guestzet(A,turn,method)


switch method

    case 'AI1' % strictly random
        moves=availablemoves(A,turn);
        
        index=floor(rand(1)*(size(moves,1)))+1;
        
        x1=moves(index,1);
        y1=moves(index,2);
        x2=moves(index,3);
        y2=moves(index,4);
        

    case 'AI2' % best option                                                 
        moves=availablemoves(A,turn);
        
        for i=1:size(moves,1)
            x1=moves(i,1);
            y1=moves(i,2);
            x2=moves(i,3);
            y2=moves(i,4);
            B=guestzetdoen(A,x1,y1,x2,y2,'sim',method);
            balance(i)=calculatebalance(B,turn);            
        end
        
        [balance,index]=sort(balance,'descend');
        a=index(balance==balance(1));
        index=floor(rand(1)*(length(a)))+1;
        
        x1=moves(a(index),1);
        y1=moves(a(index),2);
        x2=moves(a(index),3);
        y2=moves(a(index),4);
        
    case 'AI3' % 1 step ahead
        moves1=availablemoves(A,turn);
       
        turn1=turn;
        for i=1:size(moves1,1)            
            x1=moves1(i,1);
            y1=moves1(i,2);
            x2=moves1(i,3);
            y2=moves1(i,4);
            B=guestzetdoen(A,x1,y1,x2,y2,'sim',method);
            
%             turn=turn*-1;
            moves2=availablemoves(B,turn*-1);
            balance2=[];
            for j=1:size(moves2,1)
                x1=moves2(j,1);
                y1=moves2(j,2);
                x2=moves2(j,3);
                y2=moves2(j,4);                
                C=guestzetdoen(B,x1,y1,x2,y2,'sim',method);
                balance2(j)=calculatebalance(C,turn);
            end
            if length(balance2)==0
                balance2=calculatebalance(B,turn);
            end
            balance2=sort(balance2,'ascend');
            balance1(i)=balance2(1);
%             turn=turn1;
        end
        [balance,index]=sort(balance1,'descend');
        a=index(balance==balance(1));
        index=floor(rand(1)*(length(a)))+1;
        a(index);
        
        x1=moves1(a(index),1);
        y1=moves1(a(index),2);
        x2=moves1(a(index),3);
        y2=moves1(a(index),4);
        
        


        
        
    case 'manual'                                               %werkt!!!!!
        test=0;
        
        while test==0
            [x,y]=ginput(2);
            x1=floor((y(1)-1)/40)+1;
            y1=floor((x(1)-1)/40)+1;
            x2=floor((y(2)-1)/40)+1;
            y2=floor((x(2)-1)/40)+1;
            if A(x1,y1)==turn && A(x2,y2)~=turn
                [B,test]=guestzetdoen(A,x1,y1,x2,y2,'sim',method);
            end
           
        end
        
end





















Contact us