No BSD License  

Highlights from
Agitation-Board game

image thumbnail
from Agitation-Board game by Paul de Wit
aka Trouble be the first to get all 4 pieces around the board.

Agitation(varargin)
function varargout = Agitation(varargin)
% Agitation M-file for Agitation.fig
%      Agitation, by itself, creates a new Agitation or raises the existing
%      singleton*.
%
%      H = Agitation returns the handle to a new Agitation or the handle to
%      the existing singleton*.
%
%      Agitation('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in Agitation.M with the given input arguments.
%
%      Agitation('Property','Value',...) creates a new Agitation or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before Agitation_OpeningFunction gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to Agitation_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help Agitation

% % Last Modified by GUIDE v2.5 16-Jul-2004 16:09:13

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
    'gui_Singleton',  gui_Singleton, ...
    'gui_OpeningFcn', @Agitation_OpeningFcn, ...
    'gui_OutputFcn',  @Agitation_OutputFcn, ...
    'gui_LayoutFcn',  [] , ...
    'gui_Callback',   []);
if nargin & isstr(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT

function Agitation_OpeningFcn(hObject,eventdata,handles)
handles.fig = hObject;
handles=guihandles(handles.fig);
Struct = {'axes1','axes2','axes3','axes4','axes5','axes6','axes7','axes8',...
        'axes9','axes10','axes11','axes12','axes13','axes14',...
        'axes15','axes16','axes17','axes18','axes19','axes20',...
        'axes21','axes22','axes23','axes24','axes25','axes26',...
        'axes27','axes28','box0_axes','box1_axes','box2_axes',...
        'box3_axes','home1','home2','home3','home4'};
Struct_red2 = {'box4_axes','box5_axes','box6_axes','box7_axes', ...
        'homered1','homered2','homered3','homered4'};
Struct_green2 = {'box8_axes','box9_axes','box10_axes','box11_axes',...
        'homegreen1','homegreen2','homegreen3','homegreen4'};
Struct_yellow2 = {'box12_axes','box13_axes','box14_axes','box15_axes',...
        'homeyellow1','homeyellow2','homeyellow3','homeyellow4'};
Slider_field = {'slider1','slider5','slider6'};
handles.struct = Struct;
handles.struct_red2 = Struct_red2;
handles.struct_green2 = Struct_green2;
handles.struct_yellow2 = Struct_yellow2;
handles.Slider = Slider_field;
handles.DoNotTouch = 0;
handles.pause = .1;
handles.pause2 = .1;
% Update handles structure
guidata(hObject, handles);


function varargout = Agitation_OutputFcn(hObject, eventdata, handles)
guidata(hObject,handles)
init(handles);

%%%%%%%%%%%%%%%%%% initialize %%%%%%%%%%%%%%%%%%%%
function init(handles)
home;
handles.Dicecolor = 1; % default off
handles.Sounds = 0;    % default on
handles.Autoroll = 1;  % default of
handles = resetdice(handles);
% hide 
% update handle structure
guidata(handles.figure1, handles);
% make sure all fields are cleared

%%%%%%%%%%%%%%%%%% reset dice to 0, roll = 0 %%%%%%%%%%%%%%%%%%%%
function varargout = resetdice(handles)
handles.rollnumber = 0;
handles.dice = -1*ones(1,36);
handles.unselected = ones(1,36);
handles.currentAxes = -1;
% set 'Visible', 'off';
axeshandles = getaxeshandles(handles);
% Update handles structure
guidata(handles.figure1, handles);
highlightselection(handles);
if nargout
    varargout{1} = handles;
end



function rollbutton_Callback(hObject, eventdata, handles)
resetdice(handles)
axeshandles = handles.Dice1_axes;
set(handles.rollbutton,'style','text','string','                                                            Please wait')
% % add rollingpatterns here
% % compute new dice hand
dice = round(ceil(6*rand));
% 
% % plot new dice hand
diceplot(dice, axeshandles);
handles.dice2=dice;
handles.stoperror=0;
guidata(hObject,handles)


function pushbutton2_Callback(hObject, eventdata, handles)
Struct=handles.struct;
Struct_red=handles.struct_red2;
Struct_green=handles.struct_green2;
Struct_yellow=handles.struct_yellow2;
Slider=handles.Slider;
handles.DoNotTouch = 0;
handles.stopNow = 0;
check4win(hObject,handles,0,0,0)
set(handles.helpbox,'string','')
for i = 1:length(Struct)
    h(i) = getfield(handles, Struct{i});
end

for i = 1:length(Struct_red)
    t(i) = getfield(handles, Struct_red{i});
end

for i = 1:length(Struct_green)
    p(i) = getfield(handles, Struct_green{i});
end

for i = 1:length(Struct_yellow)
    q(i) = getfield(handles, Struct_yellow{i});
end

for i = 1:length(Slider)
    r(i) = getfield(handles, Slider{i});
    set(r(i),'Value',0.5)
end
for j = 29:32
    set(h(j),'Color',[0 1 1]);
end
for j = 1:28
    set(h(j),'Color',[1 1 1])
end
for j = 33:36
    set(h(j),'Color',[1 1 1])
end
for j = 1:4
    set(t(j),'Color',[1 0 0])
end
for j = 5:8
    set(t(j),'Color',[1 1 1])
end
for j = 1:4
    set(p(j),'Color',[0 1 0])
end
for j = 5:8
    set(p(j),'Color',[1 1 1])
end
for j = 1:4
    set(q(j),'Color',[1 1 .25])
end
for j = 5:8
    set(q(j),'Color',[1 1 1])
end
Struct_red = {'box4_axes','box5_axes','box6_axes','box7_axes'};
Struct_blue = {'box0_axes','box1_axes','box2_axes','box3_axes'};
Struct_green = {'box8_axes','box9_axes','box10_axes','box11_axes'};
Struct_yellow = {'box12_axes','box13_axes','box14_axes','box15_axes'};

handles.struct_red = Struct_red;
handles.struct_blue = Struct_blue;
handles.struct_green = Struct_green;
handles.struct_yellow = Struct_yellow;

cla
set(handles.rollbutton,'style','pushbutton','string','Roll')
guidata(hObject,handles)

function movepiece(hObject,handles)
if isempty(handles.currentAxes)==1
    return
end
Struct_red = handles.struct_red;
Struct_green = handles.struct_green;
Struct_yellow = handles.struct_yellow;
direction = [1 2 3 4 5 6 7 8 9 10 11 12 13 14 ...
        15 16 17 18 19 20 21 22 23 24 25 26 27 28 ...
        33 34 35 36];
field = {'currentAxes','dice2'};
currentAxes = getfield(handles,field{1});
dice = getfield(handles,field{2});
Struct=handles.struct;
for i = 1:length(Struct)
    h(i) = getfield(handles, Struct{i});
end
if currentAxes < 5
    Color = get(h(currentAxes+28),'color');
elseif currentAxes >=5 & currentAxes <=32
    Color = get(h(currentAxes-4),'color');
else 
    Color = get(h(currentAxes),'color');
end
if Color == [0 1 1] & dice==6 & currentAxes < 5
    send_home = get(h(1),'Color');
    if send_home == [0 1 1]
        return
    end
    if send_home == [1 0 0]
        for j = 1:4
            t(j) = getfield(handles, Struct_red{j});
            y(j,:) = get(t(j),'Color');
            if y(j,:) ==[1 1 1]
                A(j) = j;
            end
        end
        set(t(max(A)),'Color',[1 0 0])
    end  
    if send_home == [0 1 0]
        for j = 1:4
            t(j) = getfield(handles, Struct_green{j});
            y(j,:) = get(t(j),'Color');
            if y(j,:) ==[1 1 1]
                A(j) = j;
            end
        end
        set(t(max(A)),'Color',[0 1 0])
    end  
    if send_home == [1 1 .25]
        for j = 1:4
            t(j) = getfield(handles, Struct_yellow{j});
            y(j,:) = get(t(j),'Color');
            if y(j,:) ==[1 1 1]
                A(j) = j;
            end
        end
        set(t(max(A)),'Color',[1 1 .25])
    end  
    set(h(1),'Color',[0 1 1])
    set(h(currentAxes+28),'Color',[1 1 1])
end
if Color == [0 1 1] & currentAxes >= 5
    currentAxes=currentAxes-4;
    if currentAxes+dice > 32
        return
    end
    aflag=0;
    aflag1=0;
    aflag2=0;
    send_home = get(h(direction(currentAxes+dice)),'Color');
    for i = currentAxes+1:currentAxes+dice
        if get(h(direction(currentAxes+dice)),'Color')==[0 1 1]
            aflag1=1;
            break
        end            
        [axescolor] = checkcolor(hObject,handles,i);
        if axescolor ==[1 1 1]
            aflag2=0;
        end
        if axescolor ==[1 0 0] 
            set(h(direction(i)),'Color',axescolor)
            if aflag2==0
                set(h(direction(i-1)),'Color',[1 1 1])  
                aflag2=1;
            end
            aflag=1;
        elseif axescolor ==[0 1 1]
            set(h(direction(i)),'Color',axescolor)
            if aflag2==0
                set(h(direction(i-1)),'Color',[1 1 1])
                aflag2=1;
            end
            aflag=1;
        elseif axescolor ==[0 1 0]
            set(h(direction(i)),'Color',axescolor)
            if aflag2==0
                set(h(direction(i-1)),'Color',[1 1 1])
                aflag2=1;
            end
            aflag=1;
        elseif axescolor ==[1 1 .25]
            set(h(direction(i)),'Color',axescolor)
            if aflag2==0
                set(h(direction(i-1)),'Color',[1 1 1])
                aflag2=1;
            end
            aflag=1;
        else
            set(h(direction(i)),'Color',[0 1 1])
            if aflag==0                
                set(h(direction(i-1)),'Color',[1 1 1])
            else
                aflag=0;
            end
            pause(handles.pause2)
        end
    end
    if send_home == [1 0 0]
        for j = 1:4
            t(j) = getfield(handles, Struct_red{j});
            y(j,:) = get(t(j),'Color');
            if y(j,:) ==[1 1 1]
                A(j) = j;
            end
        end
        set(t(max(A)),'Color',[1 0 0])
    end    
    if send_home == [0 1 0]
        for j = 1:4
            t(j) = getfield(handles, Struct_green{j});
            y(j,:) = get(t(j),'Color');
            if y(j,:) ==[1 1 1]
                A(j) = j;
            end
        end
        set(t(max(A)),'Color',[0 1 0])
    end    
    if send_home == [1 1 .25]
        for j = 1:4
            t(j) = getfield(handles, Struct_yellow{j});
            y(j,:) = get(t(j),'Color');
            if y(j,:) ==[1 1 1]
                A(j) = j;
            end
        end
        set(t(max(A)),'Color',[1 1 .25])
    end    
    if aflag1==0
        set(h(direction(i)),'Color',[0 1 1])
    end
end
check4win(hObject,handles,13,16,1)
guidata(hObject,handles)

function movecpu(hObject,handles)

pause(handles.pause2)
Struct = {'axes8','axes9','axes10','axes11','axes12','axes13',...
        'axes14','axes15','axes16','axes17','axes18','axes19',...
        'axes20','axes21','axes22','axes23','axes24','axes25',...
        'axes26','axes27','axes28','axes1','axes2','axes3',...
        'axes4','axes5','axes6','axes7','homered1','homered2',...
        'homered3','homered4','box4_axes','box5_axes','box6_axes',...
        'box7_axes'};
SliderRed = {'slider6'};
direction = [1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 ...
        19 20 21 22 23 24 25 26 27 28 29 30 31 32];
handles.SliderRed = SliderRed;
SliderRed = getfield(handles,SliderRed{1});
SliderRed = get(SliderRed,'Value');
Struct_red = handles.struct_red;
Struct_blue = handles.struct_blue;
Struct_green = handles.struct_green;
Struct_yellow = handles.struct_yellow;
currentAxes = handles.currentAxes;
axeshandles = handles.Dice1_axes;
dice = round(ceil(6*rand));
handles.dice = dice;
diceplot(dice, axeshandles);
aflag5=0;
%check for win
for i=29:32
    b(i) = getfield(handles,Struct{i});
    Colorb = get(b(i),'Color');
    if Colorb ==[1 0 0]
        aflag5=1;
    else
        aflag5=0;
        break
    end
end

if aflag5==1
    check4win(hObject,handles,1,4,2)
    movecpu2(hObject,handles)
    return
end
for i = 1:length(Struct)
    h(i) = getfield(handles, Struct{i});
end
for i = 1:length(h)
    Color(i,:) = get(h(i),'Color');
end

for i = 1:length(h)
    if Color(i,:) ==[1 0 0]
        red(i) = 1;
    end
end
start=1;
slack=1;
slack_start=1;
red=find(red==1);
red2=find(red < 29);
Count=0;
for i =29:32
    HomeColor=get(h(i),'Color');
    if HomeColor==[1 0 0]
        Count=Count+1;
    end
end

if length(red2)==0
    A=1;B=0;C=0;D=0;
elseif length(red2)==1
    A=1;B=0;C=0;D=0;
elseif length(red2)==2
    A=.2;B=.5;C=0;D=0;
elseif length(red2)==3
    A=.15;B=.25;C=.45;D=0;
end
if ~exist('A')
    A=.5;
elseif ~exist('B')
    B=.5;
elseif ~exist('C')
    C=.5;
elseif ~exist('D')
    D=.5;
end
winner = probability(A,B,C,D);
box1 = get(h(1),'Color');
if box1==[1 0 0] & dice==6
    start=1;
    slack_start=1;
    slack=0;
end
j = winner;
aflag6=0;
for k=1:4
    if red(j) > 32 & dice==6
        start = 1;
        slack = 1;
        slack_start = 1;
    elseif red(j) <= 32 & isempty(red2)==0
        start = red(j);
        slack = 0;
        slack_start = 1;
        if dice+start-slack > 32
            start = red(1);
            if dice+start-slack > 32
                if dice==6
                    aflag6=1;
                elseif dice~=6
                    check4win(hObject,handles,1,4,2)
                    movecpu2(hObject,handles)
                    return
                end
                break %can't move or need 6 to get out
            end
            j=1;
        end
        if get(h(direction(dice+start-slack)),'Color')==[1 0 0]
            start = red(j+1);
        end
        if dice+start-slack > 32 
            start = red(1);
            if get(h(direction(dice+start-slack)),'Color')==[1 0 0]
                start = red(2);
                if dice+start-slack > 32
                    start = red(1);
                    aflag6=1;
                    break %can't move or need 6 to get out
                end
            end
            j=1;
        end
        if get(h(direction(dice+start-slack)),'Color')==[1 0 0]
            start = red(j+2);
        end
        if dice+start-slack > 32
            start = red(1);
            aflag6=1
            break %can't move or need 6 to get out
        end
        if get(h(direction(dice+start-slack)),'Color')==[1 0 0]
            start = red(j+3);
        end
    end
end
box_color=find(red > 32);
if dice==6 & isempty(red2)==0 & start < 29 & aflag6==0
    RandNumber=ceil(10*rand);
    SliderRed=10*SliderRed;
    if SliderRed < RandNumber
        dice=-1;
    end
    SliderRed=(1/10)*SliderRed;
end  
check = box1*[0 1 1]';
if check ~=0 & (start > 28 | box1 == [1 1 1] | box1 ==[0 1 1] | box1==[0 1 0]) & isempty(box_color)==0 & (dice==6 | aflag6==1)
    slack = 1;
    slack_start = 1;
    set(h(33),'Color',[1 1 1])
    if length(box_color) < 4
        set(h(34),'Color',[1 1 1])
        start = 1;
        slack = 1;
        slack_start = 1;
    end
    if length(box_color) < 3
        set(h(35),'Color',[1 1 1])
        start = 1;
        slack = 1;
        slack_start = 1;
    end
    if length(box_color) < 2
        set(h(36),'Color',[1 1 1])
        start = 1;
        slack = 1;
        slack_start = 1;
    end
    set(h(1),'Color',[1 0 0])
    if box1 == [0 1 1]
        for j = 1:length(Struct_blue)
            t(j) = getfield(handles, Struct_blue{j});
            y(j,:) = get(t(j),'Color');
            if y(j,:) ==[1 1 1]
                A(j) = j;
            end
        end
        set(t(max(A)),'Color',[0 1 1])
    end
    if box1 == [0 1 0]
        for j = 1:length(Struct_green)
            t(j) = getfield(handles, Struct_green{j});
            y(j,:) = get(t(j),'Color');
            if y(j,:) ==[1 1 1]
                A(j) = j;
            end
        end
        set(t(max(A)),'Color',[0 1 0])
    end
    if box1 == [1 1 .25]
        for j = 1:length(Struct_yellow)
            t(j) = getfield(handles, Struct_yellow{j});
            y(j,:) = get(t(j),'Color');
            if y(j,:) ==[1 1 1]
                A(j) = j;
            end
        end
        set(t(max(A)),'Color',[1 1 .25])
    end
    check4win(hObject,handles,1,4,2)
    movecpu2(hObject,handles)
    return
else
    aflag6=1;
end
if dice==-1
    aflag5=1;
    dice=6
end
if length(red2)==0
    check4win(hObject,handles,1,4,2)
    movecpu2(hObject,handles)
    return
end
if start > 28
    start = red(1);
    if start+dice > 32
        check4win(hObject,handles,1,4,2)
        movecpu2(hObject,handles)
        return
    end
end
if (Count==3 | Count==2) & dice+start-slack > 32
    check4win(hObject,handles,1,4,2)
    movecpu2(hObject,handles)
    return
end
if get(h(direction(dice+start-slack)),'Color')==[1 0 0] & length(red2)==3
    check4win(hObject,handles,1,4,2)
    movecpu2(hObject,handles)
    return
end
aflag4=0;
if start > 28
    start = 1;
    slack = 1;
    slack_start = 1;
    aflag4=1;
end
if get(h(direction(dice+start-slack)),'Color')==[1 0 0]
    check4win(hObject,handles,1,4,2)
    movecpu2(hObject,handles)
    return
end
aflag=0;
aflag2=0;
OK=0;
send_home = get(h(direction(dice+start-slack)),'Color');
for j = 1:length(Struct_red)
    t(j) = getfield(handles, Struct_red{j});
    y(j,:) = get(t(j),'Color');
    if y(j,:) ==[1 1 1]
        A(j) = 1;
    else
        A(j) =0;
    end
end
if dice==6
    if box1==[1 0 0] | aflag5==1
        OK=1;
    elseif A==[1 1 1 1]  %If all initial boxes are white
        OK=1;
    end
end
if (OK==1 & aflag4==0) | aflag6==1
    for i = start+slack_start:dice + start - slack
        axescolor = get(h(direction(i)),'Color');
        if axescolor ==[1 1 1]
            aflag2=0;
        end
        if axescolor==[0 1 1]
            set(h(direction(i)),'Color',axescolor)
            if aflag2==0
                set(h(direction(i-1)),'Color',[1 1 1])
                aflag2=1;
            end
            aflag=1;
        elseif axescolor==[1 0 0]
            set(h(direction(i)),'Color',axescolor)
            if aflag2==0 
                set(h(direction(i-1)),'Color',[1 1 1])
                aflag2=1;
            end
            aflag=1;
        elseif axescolor==[0 1 0]
            set(h(direction(i)),'Color',axescolor)
            if aflag2==0 
                set(h(direction(i-1)),'Color',[1 1 1])
                aflag2=1;
            end
            aflag=1;
        elseif axescolor==[1 1 .25]
            set(h(direction(i)),'Color',axescolor)
            if aflag2==0 
                set(h(direction(i-1)),'Color',[1 1 1])
                aflag2=1;
            end
            aflag=1;
        else
            set(h(direction(i)),'Color',[1 0 0])
            if i > start & aflag==0
                set(h(i-1),'Color',[1 1 1])
            else
                aflag=0;
            end
            pause(handles.pause)
        end
    end
    if send_home == [0 1 1]
        for j = 1:length(Struct_blue)
            t(j) = getfield(handles, Struct_blue{j});
            y(j,:) = get(t(j),'Color');
            if y(j,:) ==[1 1 1]
                A(j) = j;
            end
        end
        set(t(max(A)),'Color',[0 1 1])
    end
    if send_home == [0 1 0]
        for j = 1:length(Struct_green)
            t(j) = getfield(handles, Struct_green{j});
            y(j,:) = get(t(j),'Color');
            if y(j,:) ==[1 1 1]
                A(j) = j;
            end
        end
        set(t(max(A)),'Color',[0 1 0])
    end
    if send_home == [1 1 .25]
        for j = 1:length(Struct_yellow)
            t(j) = getfield(handles, Struct_yellow{j});
            y(j,:) = get(t(j),'Color');
            if y(j,:) ==[1 1 1]
                A(j) = j;
            end
        end
        set(t(max(A)),'Color',[1 1 .25])
    end
    set(h(direction(i)),'Color',[1 0 0])
end
check4win(hObject,handles,1,4,2)
movecpu2(hObject,handles)


function movecpu2(hObject,handles)
pause(handles.pause2)
Struct2 = {'axes15','axes16','axes17','axes18','axes19','axes20',...
        'axes21','axes22','axes23','axes24','axes25','axes26',...
        'axes27','axes28','axes1','axes2','axes3','axes4','axes5',...
        'axes6','axes7','axes8','axes9','axes10','axes11','axes12',...
        'axes13','axes14','homegreen1','homegreen2','homegreen3',...
        'homegreen4','box8_axes','box9_axes','box10_axes','box11_axes'};
SliderGreen = {'slider5'};
direction = [1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 ...
        19 20 21 22 23 24 25 26 27 28 29 30 31 32];
Struct_blue = handles.struct_blue;
Struct_green = handles.struct_green;
Struct_red = handles.struct_red;
Struct_yellow = handles.struct_yellow;
currentAxes = handles.currentAxes;
axeshandles = handles.Dice1_axes;
dice = round(ceil(6*rand));
handles.dice = dice;
handles.SliderGreen = SliderGreen;
diceplot(dice, axeshandles);
SliderGreen = getfield(handles,SliderGreen{1});
SliderGreen = get(SliderGreen,'Value');

aflag6=0;
for i=29:32
    b(i) = getfield(handles,Struct2{i});
    Colorb = get(b(i),'Color');
    if Colorb ==[0 1 0]
        aflag6=1;
    else
        aflag6=0;
        break
    end
end
if aflag6==1
    check4win(hObject,handles,5,8,3)
    movecpu3(hObject,handles)
    return
end   
for i = 1:length(Struct2)
    h(i) = getfield(handles, Struct2{i});
end
for i = 1:length(h)
    Color(i,:) = get(h(i),'Color');
end

for i = 1:length(h)
    if Color(i,:) ==[0 1 0]
        green(i) = 1;
    end
end
Count=0;
for i =29:32
    HomeColor=get(h(i),'Color');
    if HomeColor==[0 1 0]
        Count=Count+1;
    end
end

start=1;
slack=1;
slack_start=1;
green=find(green==1);
green2=find(green < 29);
if length(green2)==0
    A=1;B=0;C=0;D=0;
elseif length(green2)==1
    A=1;B=0;C=0;D=0;
elseif length(green2)==2
    A=.2;B=.5;C=0;D=0;
elseif length(green2)==3
    A=.15;B=.25;C=.45;D=0;
end

if dice~=6 & isempty(green2)==1
    check4win(hObject,handles,5,8,3)
    movecpu3(hObject,handles)
    return
end
if ~exist('A')
    A=.5;
elseif ~exist('B')
    B=.5;
elseif ~exist('C')
    C=.5;
elseif ~exist('D')
    D=.5;
end

winner = probability(A,B,C,D);
box1 = get(h(1),'Color');

if box1==[0 1 0] & dice==6
    start=1;
    slack_start=1;
    slack=0;
end
j = winner;
for k=1:4
    if green(j) > 32 & dice==6
        start = 1;
        slack = 1;
        slack_start = 1;
    elseif green(j) <= 32 & isempty(green2)==0
        start = green(j);
        slack = 0;
        slack_start = 1;
        if dice+start-slack > 32
            start = green(1);
            if dice+start-slack > 32
                if dice==6
                    aflag6=1;
                elseif dice~=6
                    check4win(hObject,handles,5,8,3)
                    movecpu3(hObject,handles)
                    return
                end
                break %can't move or need 6 to get out
            end
            j=1;
        end
        if get(h(direction(dice+start-slack)),'Color')==[0 1 0]
            start = green(j+1);
        end
        if dice+start-slack > 32 
            start = green(1);
            if get(h(direction(dice+start-slack)),'Color')==[0 1 0]
                start = green(2);
                if dice+start-slack > 32
                    start = green(1);
                    aflag6=1;
                    break %can't move or need 6 to get out
                end
            end
            j=1;
        end
        if get(h(direction(dice+start-slack)),'Color')==[0 1 0]
            start = green(j+2);
        end
        if dice+start-slack > 32
            start = green(1);
            aflag6=1
            break %can't move or need 6 to get out
        end
        if get(h(direction(dice+start-slack)),'Color')==[0 1 0]
            start = green(j+3);
        end
    end
end
if dice==6 & isempty(green2)==0 & start < 29 & aflag6==0
    RandNumber=ceil(10*rand);
    SliderGreen=10*SliderGreen;
    if SliderGreen < RandNumber
        dice=-1;
    end
    SliderGreen=(1/10)*SliderGreen;
end  


box_color=find(green > 32);
check = box1*[1 0 1]';
if check~=0 & (start > 28 | box1 == [1 1 1] | box1 ==[0 1 1] | box1==[1 0 0]) & isempty(box_color)==0 & (dice==6 | aflag6==1)
    slack = 1;
    slack_start = 1;
    set(h(33),'Color',[1 1 1])
    if length(box_color) < 4
        set(h(34),'Color',[1 1 1])
        start = 1;
        slack = 1;
        slack_start = 1;
    end
    if length(box_color) < 3
        set(h(35),'Color',[1 1 1])
        start = 1;
        slack = 1;
        slack_start = 1;
    end
    if length(box_color) < 2
        set(h(36),'Color',[1 1 1])
        start = 1;
        slack = 1;
        slack_start = 1;
    end
    set(h(1),'Color',[0 1 0])
    if box1 == [0 1 1]
        for j = 1:length(Struct_blue)
            t(j) = getfield(handles, Struct_blue{j});
            y(j,:) = get(t(j),'Color');
            if y(j,:) ==[1 1 1]
                A(j) = j;
            end
        end
        set(t(max(A)),'Color',[0 1 1])
    end
    if box1 == [1 0 0]
        for j = 1:length(Struct_red)
            t(j) = getfield(handles, Struct_red{j});
            y(j,:) = get(t(j),'Color');
            if y(j,:) ==[1 1 1]
                A(j) = j;
            end
        end
        set(t(max(A)),'Color',[1 0 0])
    end
    if box1 == [1 1 .25]
        for j = 1:length(Struct_yellow)
            t(j) = getfield(handles, Struct_yellow{j});
            y(j,:) = get(t(j),'Color');
            if y(j,:) ==[1 1 1]
                A(j) = j;
            end
        end
        set(t(max(A)),'Color',[1 1 .25])
    end
    check4win(hObject,handles,5,8,3)
    movecpu3(hObject,handles)
    return
else
    aflag6=1;
end
if dice==-1
    aflag5=1;
    dice=6;
end
if start > 28
    start = green(1);
    if start+dice > 32
        check4win(hObject,handles,5,8,3)
        movecpu3(hObject,handles)  
        return
    end
end
if Count==3 & dice+start-slack > 32
    check4win(hObject,handles,5,8,3)
    movecpu3(hObject,handles)
    return
end

if get(h(direction(dice+start-slack)),'Color')==[0 1 0] & length(green2)==3
    check4win(hObject,handles,5,8,3)
    movecpu3(hObject,handles) 
    return
end
aflag4=0;
if start > 28
    start = 1;
    slack = 1;
    slack_start = 1;
    aflag4=1;
end
if get(h(direction(dice+start-slack)),'Color')==[0 1 0]
    check4win(hObject,handles,5,8,3)
    movecpu3(hObject,handles)
    return
end
aflag=0;
aflag2=0;
OK=0;
send_home = get(h(direction(dice+start-slack)),'Color');
for j = 1:length(Struct_green)
    t(j) = getfield(handles, Struct_green{j});
    y(j,:) = get(t(j),'Color');
    if y(j,:) ==[1 1 1]
        A(j) = 1;
    else
        A(j) =0;
    end
end
if dice==6
    if box1==[0 1 0] | aflag6==1
        OK=1;
    elseif A==[1 1 1 1]
        OK=1;
    end
end

if (dice~=6 | OK==1) & aflag4==0
    for i = start+slack_start:dice + start - slack
        axescolor = get(h(direction(i)),'Color');
        if axescolor ==[1 1 1]
            aflag2=0;
        end
        if axescolor==[0 1 1]
            set(h(direction(i)),'Color',axescolor)
            if aflag2==0
                set(h(direction(i-1)),'Color',[1 1 1])
                aflag2=1;
            end
            aflag=1;
        elseif axescolor==[0 1 0]
            set(h(direction(i)),'Color',axescolor)
            if aflag2==0 
                set(h(direction(i-1)),'Color',[1 1 1])
                aflag2=1;
            end
            aflag=1;
        elseif axescolor==[1 0 0]
            set(h(direction(i)),'Color',axescolor)
            if aflag2==0 
                set(h(direction(i-1)),'Color',[1 1 1])
                aflag2=1;
            end
            aflag=1;
        elseif axescolor==[1 1 .25]
            set(h(direction(i)),'Color',axescolor)
            if aflag2==0 
                set(h(direction(i-1)),'Color',[1 1 1])
                aflag2=1;
            end
            aflag=1;
        else
            set(h(direction(i)),'Color',[0 1 0])
            if i > start & aflag==0
                set(h(i-1),'Color',[1 1 1])
            else
                aflag=0;
            end
            pause(handles.pause)
        end
    end
    
    if send_home == [0 1 1]
        for j = 1:length(Struct_blue)
            t(j) = getfield(handles, Struct_blue{j});
            y(j,:) = get(t(j),'Color');
            if y(j,:) ==[1 1 1]
                A(j) = j;
            end
        end
        set(t(max(A)),'Color',[0 1 1])
    end
    if send_home == [1 0 0]
        for j = 1:length(Struct_red)
            t(j) = getfield(handles, Struct_red{j});
            y(j,:) = get(t(j),'Color');
            if y(j,:) ==[1 1 1]
                A(j) = j;
            end
        end
        set(t(max(A)),'Color',[1 0 0])
    end
    if send_home == [1 1 .25]
        for j = 1:length(Struct_yellow)
            t(j) = getfield(handles, Struct_yellow{j});
            y(j,:) = get(t(j),'Color');
            if y(j,:) ==[1 1 1]
                A(j) = j;
            end
        end
        set(t(max(A)),'Color',[1 1 .25])
    end
    set(h(direction(i)),'Color',[0 1 0])
end



check4win(hObject,handles,5,8,3)
movecpu3(hObject,handles)

function movecpu3(hObject,handles)
pause(handles.pause2)
Struct2 = {'axes22','axes23','axes24','axes25','axes26','axes27',...
        'axes28','axes1','axes2','axes3','axes4','axes5','axes6','axes7',...
        'axes8','axes9','axes10','axes11','axes12','axes13','axes14',...
        'axes15','axes16','axes17','axes18','axes19','axes20','axes21',...
        'homeyellow1','homeyellow2','homeyellow3','homeyellow4',...
        'box12_axes','box13_axes','box14_axes','box15_axes'};
SliderYellow = {'slider1'};
direction = [1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 ...
        19 20 21 22 23 24 25 26 27 28 29 30 31 32];
Struct_blue = handles.struct_blue;
Struct_green = handles.struct_green;
Struct_red = handles.struct_red;
Struct_yellow = handles.struct_yellow;
currentAxes = handles.currentAxes;
axeshandles = handles.Dice1_axes;
handles.SliderYellow = SliderYellow;
SliderYellow = getfield(handles,SliderYellow{1});
SliderYellow = get(SliderYellow,'Value');
dice = round(ceil(6*rand));
handles.dice = dice;
diceplot(dice, axeshandles);

aflag6=0;
for i=29:32
    b(i) = getfield(handles,Struct2{i});
    Colory = get(b(i),'Color');
    if Colory ==[1 1 .25]
        aflag6=1;
    else
        aflag6=0;
        break
    end
end
if aflag6==1
    handles.DoNotTouch=0;
    guidata(hObject,handles)
    check4win(hObject,handles,9,12,4)
    return
end   

for i = 1:length(Struct2)
    h(i) = getfield(handles, Struct2{i});
end
for i = 1:length(h)
    Color(i,:) = get(h(i),'Color');
end

for i = 1:length(h)
    if Color(i,:) ==[1 1 .25]
        yellow(i) = 1;
    end
end
Count=0;
for i =29:32
    HomeColor=get(h(i),'Color');
    if HomeColor==[1 1 .25]
        Count=Count+1;
    end
end

start=1;
slack=1;
slack_start=1;
yellow=find(yellow==1);
yellow2=find(yellow < 29);
if length(yellow2)==0
    A=1;B=0;C=0;D=0;
elseif length(yellow2)==1
    A=1;B=0;C=0;D=0;
elseif length(yellow2)==2
    A=.2;B=.5;C=0;D=0;
elseif length(yellow2)==3
    A=.15;B=.25;C=.45;D=0;
end

if dice~=6 & isempty(yellow2)==1
    handles.DoNotTouch=0;
    guidata(hObject,handles)
    check4win(hObject,handles,9,12,4)
    return
end
if ~exist('A')
    A=.5;
elseif ~exist('B')
    B=.5;
elseif ~exist('C')
    C=.5;
elseif ~exist('D')
    D=.5;
end

winner = probability(A,B,C,D);
box1 = get(h(1),'Color');

if box1==[1 1 .25] & dice==6
    start=1;
    slack_start=1;
    slack=0;
end
j=winner;
for k=1:4
    if yellow(j) > 32 & dice==6
        start = 1;
        slack = 1;
        slack_start = 1;
    elseif yellow(j) <= 32 & isempty(yellow2)==0
        start = yellow(j);
        slack = 0;
        slack_start = 1;
        if dice+start-slack > 32
            start = yellow(1);
            if dice+start-slack > 32
                if dice==6
                    aflag6=1;
                elseif dice~=6
                    handles.DoNotTouch=0;
                    guidata(hObject,handles)
                    check4win(hObject,handles,9,12,4)
                    return
                end
                break %can't move or need 6 to get out
            end
            j=1;
        end
        if get(h(direction(dice+start-slack)),'Color')==[1 1 .25]
            start = yellow(j+1);
        end
        if dice+start-slack > 32 
            start = yellow(1);
            if get(h(direction(dice+start-slack)),'Color')==[1 1 .25]
                start = yellow(2);
                if dice+start-slack > 32
                    start = yellow(1);
                    aflag6=1;
                    break %can't move or need 6 to get out
                end
            end
            j=1;
        end
        if get(h(direction(dice+start-slack)),'Color')==[1 1 .25]
            start = yellow(j+2);
        end
        if dice+start-slack > 32
            start = yellow(1);
            aflag6=1
            break %can't move or need 6 to get out
        end
        if get(h(direction(dice+start-slack)),'Color')==[1 1 .25]
            start = yellow(j+3);
        end
    end
end
if dice==6 & isempty(yellow2)==0 & start < 29 & aflag6==0
    RandNumber=ceil(10*rand);
    SliderYellow=10*SliderYellow;
    if SliderYellow < RandNumber
        dice=-1;
    end
    SliderYellow=(1/10)*SliderYellow;
end  

box_color=find(yellow > 32);
check = box1*[1 1 1]';
if check~=2.25 & (box1 == [1 1 1] | box1 ==[0 1 1] | box1==[1 0 0]) & isempty(box_color)==0 & (dice==6 | aflag6==1)
    slack = 1;
    slack_start = 1;
    set(h(33),'Color',[1 1 1])
    if length(box_color) < 4
        set(h(34),'Color',[1 1 1])
        start = 1;
        slack = 1;
        slack_start = 1;
    end
    if length(box_color) < 3
        set(h(35),'Color',[1 1 1])
        start = 1;
        slack = 1;
        slack_start = 1;
    end
    if length(box_color) < 2
        set(h(36),'Color',[1 1 1])
        start = 1;
        slack = 1;
        slack_start = 1;
    end
    set(h(1),'Color',[1 1 .25])
    if box1 == [0 1 1]
        for j = 1:length(Struct_blue)
            t(j) = getfield(handles, Struct_blue{j});
            y(j,:) = get(t(j),'Color');
            if y(j,:) ==[1 1 1]
                A(j) = j;
            end
        end
        set(t(max(A)),'Color',[0 1 1])
    end
    if box1 == [1 0 0]
        for j = 1:length(Struct_red)
            t(j) = getfield(handles, Struct_red{j});
            y(j,:) = get(t(j),'Color');
            if y(j,:) ==[1 1 1]
                A(j) = j;
            end
        end
        set(t(max(A)),'Color',[1 0 0])
    end
    if box1 == [0 1 0]
        for j = 1:length(Struct_green)
            t(j) = getfield(handles, Struct_green{j});
            y(j,:) = get(t(j),'Color');
            if y(j,:) ==[1 1 1]
                A(j) = j;
            end
        end
        set(t(max(A)),'Color',[0 1 0])
    end
    handles.DoNotTouch=0;
    guidata(hObject,handles)
    check4win(hObject,handles,9,12,4)
    return
else
    aflag6=1;
end
if dice==-1
    aflag5=1;
    dice=6;
end

if start > 28
    start = yellow(1);
    if start+dice > 32
        handles.DoNotTouch=0;
        guidata(hObject,handles)
        check4win(hObject,handles,9,12,4)
        return
    end
end
if Count==3 & dice+start-slack > 32
    handles.DoNotTouch=0;
    guidata(hObject,handles)
end
if dice+start-slack > 32
    handles.DoNotTouch=0;
    guidata(hObject,handles)
    check4win(hObject,handles,9,12,4)
    return
end
if get(h(direction(dice+start-slack)),'Color')==[1 1 .25] & length(yellow2)==3
    handles.DoNotTouch=0;
    guidata(hObject,handles)
    check4win(hObject,handles,9,12,4)
    return
end
aflag4=0;
if start > 28
    start = 1;
    slack = 1;
    slack_start = 1;
    aflag4=1;
end
if get(h(direction(dice+start-slack)),'Color')==[1 1 .25]
    handles.DoNotTouch=0;
    guidata(hObject,handles)
    check4win(hObject,handles,9,12,4)
    return
end
aflag=0;
aflag2=0;
OK=0;
send_home = get(h(direction(dice+start-slack)),'Color');
for j = 1:length(Struct_yellow)
    t(j) = getfield(handles, Struct_yellow{j});
    y(j,:) = get(t(j),'Color');
    if y(j,:) ==[1 1 1]
        A(j) = 1;
    else
        A(j) =0;
    end
end
if dice==6
    if box1==[1 1 .25] | aflag6==1
        OK=1;
    elseif A==[1 1 1 1]
        OK=1;
    end
end
if (dice~=6 | OK==1) & aflag4==0
    for i = start+slack_start:dice + start - slack
        axescolor = get(h(direction(i)),'Color');
        if axescolor ==[1 1 1]
            aflag2=0;
        end
        if axescolor==[0 1 1]
            set(h(direction(i)),'Color',axescolor)
            if aflag2==0
                set(h(direction(i-1)),'Color',[1 1 1])
                aflag2=1;
            end
            aflag=1;
        elseif axescolor==[0 1 0]
            set(h(direction(i)),'Color',axescolor)
            if aflag2==0 
                set(h(direction(i-1)),'Color',[1 1 1])
                aflag2=1;
            end
            aflag=1;
        elseif axescolor==[1 0 0]
            set(h(direction(i)),'Color',axescolor)
            if aflag2==0 
                set(h(direction(i-1)),'Color',[1 1 1])
                aflag2=1;
            end
            aflag=1;
        elseif axescolor==[1 1 .25]
            set(h(direction(i)),'Color',axescolor)
            if aflag2==0 
                set(h(direction(i-1)),'Color',[1 1 1])
                aflag2=1;
            end
            aflag=1;
        else
            set(h(direction(i)),'Color',[1 1 .25])
            if i > start & aflag==0
                set(h(i-1),'Color',[1 1 1])
            else
                aflag=0;
            end
            pause(handles.pause)
        end
    end
    
    if send_home == [0 1 1]
        for j = 1:length(Struct_blue)
            t(j) = getfield(handles, Struct_blue{j});
            y(j,:) = get(t(j),'Color');
            if y(j,:) ==[1 1 1]
                A(j) = j;
            end
        end
        set(t(max(A)),'Color',[0 1 1])
    end
    if send_home == [1 0 0]
        for j = 1:length(Struct_red)
            t(j) = getfield(handles, Struct_red{j});
            y(j,:) = get(t(j),'Color');
            if y(j,:) ==[1 1 1]
                A(j) = j;
            end
        end
        set(t(max(A)),'Color',[1 0 0])
    end
    if send_home == [0 1 0]
        for j = 1:length(Struct_green)
            t(j) = getfield(handles, Struct_green{j});
            y(j,:) = get(t(j),'Color');
            if y(j,:) ==[1 1 1]
                A(j) = j;
            end
        end
        set(t(max(A)),'Color',[0 1 0])
    end
    set(h(direction(i)),'Color',[1 1 .25])
end

check4win(hObject,handles,9,12,4)
handles.DoNotTouch=0;
guidata(hObject,handles)


%%%%%%%%%%%% changes the state of "selected dice axes" %%%%%%%
function diceselect_Callback(hObject,eventdata,handles)
if handles.DoNotTouch==1 | handles.stoperror==1
    return
end
handles.DoNotTouch = 1;
handles = resetdice(handles);
highlightselection(handles);
axeshandles = getaxeshandles(handles);
handles.stoperror = 1;
guidata(hObject, handles);
selecthandles = getselecthandles(handles);
axeshandles   = getaxeshandles(handles);
currentAxes = max([(find(selecthandles == hObject)),(find(axeshandles==hObject))]);
handles.currentAxes=currentAxes;
strstate = get( selecthandles(currentAxes), 'Visible'); 
state = strcmp(strstate, 'on');                        
handles.unselected( currentAxes) = state;        
highlightselection(handles);   
Struct=handles.struct;
for i = 1:length(Struct)
    h(i) = getfield(handles, Struct{i});
end
guidata(hObject,handles)
movepiece(hObject,handles)
movecpu(hObject,handles)
set(handles.rollbutton,'style','pushbutton','string','Roll')
clc
%%%%%%%%%%%%% helper function to draw selection changes %%%%%%
function highlightselection(handles)
% changes the viewed state of dice selection axes
selecthandles = getselecthandles(handles);
selected = handles.unselected;
onoff = {'on', 'off'};                                    % static variable
for i = 1:length(selected)  % go through all dice
    set( selecthandles(i), 'Visible', onoff{selected(i)+1}); % change state
end


function axescolor = checkcolor(hObject,handles,i)

field = {'currentAxes'};
currentAxes = getfield(handles,field{1});
Struct=handles.struct;
for j = 1:length(Struct)
    h(j) = getfield(handles, Struct{j});
end
if i > 28 & i < 33
    i  = i + 4;
end

axescolor=get(h(i),'Color');


function winner = probability(A,B,C,D)
QuadrantA = A*ceil(10*rand);
QuadrantB = B*ceil(10*rand);
QuadrantC = C*ceil(10*rand);
QuadrantD = D*ceil(10*rand);

Quadrant = [QuadrantA QuadrantB QuadrantC QuadrantD];

[max1,winner] = max(Quadrant);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%% helper function for rollbutton_Callback %%%%%%%%
function axeshandles = getaxeshandles(handles)
axeshandles(1) = handles.box0_axes;
axeshandles(2) = handles.box1_axes;
axeshandles(3) = handles.box2_axes;
axeshandles(4) = handles.box3_axes;
axeshandles(5) = handles.axes1;
axeshandles(6) = handles.axes2;
axeshandles(7) = handles.axes3;
axeshandles(8) = handles.axes4;
axeshandles(9) = handles.axes5;
axeshandles(10) = handles.axes6;
axeshandles(11) = handles.axes7;
axeshandles(12) = handles.axes8;
axeshandles(13) = handles.axes9;
axeshandles(14) = handles.axes10;
axeshandles(15) = handles.axes11;
axeshandles(16) = handles.axes12;
axeshandles(17) = handles.axes13;
axeshandles(18) = handles.axes14;
axeshandles(19) = handles.axes15;
axeshandles(20) = handles.axes16;
axeshandles(21) = handles.axes17;
axeshandles(22) = handles.axes18;
axeshandles(23) = handles.axes19;
axeshandles(24) = handles.axes20;
axeshandles(25) = handles.axes21;
axeshandles(26) = handles.axes22;
axeshandles(27) = handles.axes23;
axeshandles(28) = handles.axes24;
axeshandles(29) = handles.axes25;
axeshandles(30) = handles.axes26;
axeshandles(31) = handles.axes27;
axeshandles(32) = handles.axes28;
axeshandles(33) = handles.home1;
axeshandles(34) = handles.home2;
axeshandles(35) = handles.home3;
axeshandles(36) = handles.home4;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%% helper function for diceselect_Callback %%%%%%%%
function selecthandles = getselecthandles(handles)
selecthandles(1) = handles.Select0_axes;
selecthandles(2) = handles.Select1_axes;
selecthandles(3) = handles.Select2_axes;
selecthandles(4) = handles.Select3_axes;
selecthandles(5) = handles.S1;
selecthandles(6) = handles.S2;
selecthandles(7) = handles.S3;
selecthandles(8) = handles.S4;
selecthandles(9) = handles.S5;
selecthandles(10) = handles.S6;
selecthandles(11) = handles.S7;
selecthandles(12) = handles.S8;
selecthandles(13) = handles.S9;
selecthandles(14) = handles.S10;
selecthandles(15) = handles.S11;
selecthandles(16) = handles.S12;
selecthandles(17) = handles.S13;
selecthandles(18) = handles.S14;
selecthandles(19) = handles.S15;
selecthandles(20) = handles.S16;
selecthandles(21) = handles.S17;
selecthandles(22) = handles.S18;
selecthandles(23) = handles.S19;
selecthandles(24) = handles.S20;
selecthandles(25) = handles.S21;
selecthandles(26) = handles.S22;
selecthandles(27) = handles.S23;
selecthandles(28) = handles.S24;
selecthandles(29) = handles.S25;
selecthandles(30) = handles.S26;
selecthandles(31) = handles.S27;
selecthandles(32) = handles.S28;
selecthandles(33) = handles.h1;
selecthandles(34) = handles.h2;
selecthandles(35) = handles.h3;
selecthandles(36) = handles.h4;


% --- Executes during object creation, after setting all properties.
function slider1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to slider1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: slider controls usually have a light gray background, change
%       'usewhitebg' to 0 to use default.  See ISPC and COMPUTER.
usewhitebg = 1;
if usewhitebg
    set(hObject,'BackgroundColor',[1 1 .25]);
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end


function slider5_CreateFcn(hObject, eventdata, handles)
% hObject    handle to slider5 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

usewhitebg = 1;
if usewhitebg
    set(hObject,'BackgroundColor',[0 1 0]);
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end

% --- Executes during object creation, after setting all properties.
function slider6_CreateFcn(hObject, eventdata, handles)
% hObject    handle to slider6 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

usewhitebg = 1;
if usewhitebg
    set(hObject,'BackgroundColor',[1 0 0]);
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end

function check4win(hObject,handles,st,en,No)
Struct4win = {'homered1','homered2','homered3','homered4',...
        'homegreen1','homegreen2','homegreen3','homegreen4',...
        'homeyellow1','homeyellow2','homeyellow3','homeyellow4',...
        'home1','home2','home3','home4','helpbox'};
handles.Struct4win = Struct4win;
helpbox = getfield(handles,Struct4win{17});
if st==0
    set(helpbox,'visible','off')
    return
end
set(helpbox,'visible','on')
if No==1
    for i = st:en
        WIN = getfield(handles, Struct4win{i});
        WIN = get(WIN,'Color');
        if WIN==[0 1 1]
            aflag=0;
        else
            aflag=1;
            return
        end
    end
end
if No==2
    for i = st:en
        WIN = getfield(handles, Struct4win{i});
        WIN = get(WIN,'Color');
        if WIN==[1 0 0]
            aflag=2;
        else
            aflag=3;
            return
        end
    end
end
if No==3
    for i = st:en
        WIN = getfield(handles, Struct4win{i});
        WIN = get(WIN,'Color');
        if WIN==[0 1 0]
            aflag=4;
        else
            aflag=5;
            return
        end
    end
end
if No==4
    for i = st:en
        WIN = getfield(handles, Struct4win{i});
        WIN = get(WIN,'Color');
        if WIN==[1 1 .25]
            aflag=6;
        else
            aflag=5;
            return
        end
    end
end

if ~exist('aflag')
    aflag=1;
end
Text_Object = get(helpbox,'string')
if isempty(Text_Object)==1
    if aflag==0
        set(helpbox,'string','You Win!','fontweight','bold','fontsize',25)
    elseif aflag==2
        set(helpbox,'string','Red Wins!','fontweight','bold','fontsize',25)
    elseif aflag==4
        set(helpbox,'string','Green Wins!','fontweight','bold','fontsize',25)
    elseif aflag==6
        set(helpbox,'string','Yellow Wins!','fontweight','bold','fontsize',25)
    end
end
% --- Executes on button press in pushbutton.
function pushbutton4_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
HelpMessage = {'To begin the game click on "New Game" and you will see'...
        '4x4 boxes change color. Now click on the roll button and select'...
        'which box you wish to move. (N.B. you may only move the blue boxes)'...
        'To move a piece from its initial starting position you must get a'...
        'six. After you have a six you may proceed around the board. If '...
        'another six occurs you may choose whether you wish to take one out'...
        'or move the piece currently on the board. If you land on another'...
        'player you will automatically send that piece home, however if '...
        'another player lands on you, you will automatically be sent home'...
        'The object of the game is to be the first player with all four'...
        'pieces in the corresponding boxes perpendicular to the home position'...
        'The sliders in the bottom left hand corner correspond to how'...
        'aggressive the other players will be. (N.B. This does not mean'...
        'that there ability has increased, it means that if the slider is'...
        'set to the aggressive position it is more likely that the player'...
        'will take out another piece if a six is obtained).'...
        'IMPORTANT: If you do not wish to move at all just click on a white'...
        'space. However if you click on a blue piece and it is unable to move'...
        'for example the dice displays a three but the object you have chosen'...
        'will land on a blue if it moves so instead of moving you will lose'...
        'your turn.'...
        'Author: Paul de Wit'...
        'Email: pdw35@student.canterbury.ac.nz'};

helpdlg(HelpMessage)
        
    
    
    

Contact us at files@mathworks.com