function varargout = holdem(varargin)
% HOLDEM M-file for holdem.fig
% HOLDEM, by itself, creates a new HOLDEM or raises the existing
% singleton*.
%
% H = HOLDEM returns the handle to a new HOLDEM or the handle to
% the existing singleton*.
%
% HOLDEM('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in HOLDEM.M with the given input arguments.
%
% HOLDEM('Property','Value',...) creates a new HOLDEM or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before holdem_OpeningFunction gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to holdem_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 holdem
% Last Modified by GUIDE v2.5 28-Oct-2004 10:04:35
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @holdem_OpeningFcn, ...
'gui_OutputFcn', @holdem_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
% --- Executes just before holdem is made visible.
function holdem_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to holdem (see VARARGIN)
% Choose default command line output for holdem
handles.output = hObject;
set(hObject,'Color',[0.5020 0.5020 0.2510]);
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes holdem wait for user response (see UIRESUME)
% uiwait(handles.MTH);
% --- Outputs from this function are returned to the command line.
function varargout = holdem_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
newgame_gui(gcbf, handles);
% --- Executes during object creation, after setting all properties.
function getnop_CreateFcn(hObject, eventdata, handles)
% hObject handle to getnop (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
function getnop_Callback(hObject, eventdata, handles)
% hObject handle to getnop (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of getnop as text
% str2double(get(hObject,'String')) returns contents of getnop as a double
nop=str2double(get(hObject,'String'));
setappdata(gcbf, 'nop', nop);
% --- Executes during object creation, after setting all properties.
function getname_CreateFcn(hObject, eventdata, handles)
% hObject handle to getname (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
function getname_Callback(hObject, eventdata, handles)
% hObject handle to getname (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of getname as text
% str2double(get(hObject,'String')) returns contents of getname as a double
% --- Executes on button press in startgame.
function startgame_Callback(hObject, eventdata, handles)
% hObject handle to startgame (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
playername=[];
playername{1}=get(handles.getname,'String');
setappdata(gcbf, 'playername', playername);
decktype=ceil(12*rand);
setappdata(gcbf, 'decktype', decktype);
if playername{1}~=' '
set(handles.playerbox, 'Visible', 'on');
set(handles.playerslabel, 'Visible', 'on');
set(handles.stackslabel, 'Visible', 'on');
set(handles.dispname, 'Visible', 'on');
set(handles.dispstack, 'Visible', 'on');
set(handles.dispdealer, 'Visible', 'on');
set(handles.getdeal, 'Visible', 'on');
set(handles.dealbox, 'Visible', 'on');
set(handles.disppot, 'Visible', 'on');
set(handles.dispbet, 'Visible', 'on');
set(handles.dispstayin, 'Visible', 'on');
set(handles.dispqstn, 'Visible', 'on');
set(handles.disphndnum, 'Visible', 'on');
set(handles.hndnumbox, 'Visible', 'on');
nop=get(handles.getnop, 'Value');
nop=nop+2;
setappdata(gcbf, 'nop', nop);
mode=0;
setappdata(gcbf, 'mode', mode);
playername=getappdata(gcbf, 'playername');
main(mode,handles);
playername=getappdata(gcbf, 'playername');
stack=getappdata(gcbf, 'stack');
set(handles.dispname, 'String', playername)
set(handles.dispstack, 'String', stack);
set(handles.startgame, 'Enable', 'off');
set(handles.getname, 'Enable', 'off');
set(handles.getnop, 'Enable', 'off');
set(handles.getdeal, 'Enable', 'on');
set(handles.getdeal, 'Visible', 'on');
set(handles.blinds, 'String', '')
set(handles.blindstime, 'String', '')
initialize_table(handles);
end
% --- Executes during object creation, after setting all properties.
function popupmenu1_CreateFcn(hObject, eventdata, handles)
% hObject handle to getnop (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
% --- Executes on selection change in getnop.
function popupmenu1_Callback(hObject, eventdata, handles)
% hObject handle to getnop (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = get(hObject,'String') returns getnop contents as cell array
% contents{get(hObject,'Value')} returns selected item from getnop
% --- Executes on button press in getdeal.
function getdeal_Callback(hObject, eventdata, handles)
% hObject handle to getdeal (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
set(handles.getdeal, 'Enable', 'off');
set(handles.newgame, 'Enable', 'off');
set(handles.deckoptions, 'Enable', 'off');
set(handles.dispwinner, 'Visible', 'off');
quicksim=getappdata(gcbf, 'quicksim');
quicksimhand='y';
while quicksimhand=='y'
folded=getappdata(gcbf, 'folded');
nop=getappdata(gcbf, 'nop');
for i=1:nop
if folded(i)=='y'
set(eval(['handles.fhandname' int2str(i)]), 'String', 'Folded');
else
set(eval(['handles.fhandname' int2str(i)]), 'String', '');
end
end
mode=getappdata(gcbf, 'mode');
hndnum=getappdata(gcbf, 'hndnum');
quicksim=getappdata(gcbf, 'quicksim');
utime=getappdata(gcbf, 'utime');
blind=getappdata(gcbf, 'blind');
maxblind=getappdata(gcbf, 'maxblind');
rb=getappdata(gcbf, 'rb');
a=fix(clock);
ctime=(a(4)*3600)+(a(5)*60)+a(6);
if quicksim=='y'
if (hndnum/20)==floor(hndnum/20)
ctime=utime;
end
end
if blind<maxblind
if ctime>=utime
if mode==1
blind=blind*2;
a=fix(clock);
utime=((a(4)*3600)+(a(5)*60)+a(6))+(rb*60);
blindtime='The blinds just went up.';
setappdata(gcbf, 'utime', utime);
setappdata(gcbf, 'blind', blind);
end
end
a=(utime-ctime)/60;
rtime(1)=floor(a);
rtime(2)=(a-floor(a))*60;
rtimes{1}=int2str(rtime(1));
rtimes{2}=int2str(rtime(2));
if rtime(2)<10
rtimes{2}=['0' int2str(rtime(2))];
end
blindupdate=['The blinds are currently $' int2str(blind/2) '/$' int2str(blind)];
blindtime=['The blinds will go up in ' rtimes{1} ':' rtimes{2}];
if ctime>=utime
if mode~=1
blindtime='The blinds will go up next hand.';
end
end
else
blindupdate=['The blinds are currently capped at $' int2str(blind/2) '/$' int2str(blind)];
blindtime=[' '];
end
setappdata(gcbf, 'utime', utime);
set(handles.blinds, 'String', blindupdate)
set(handles.blindstime, 'String', blindtime)
set(handles.dispbet, 'String', '');
if mode==5
mode=1;
initialize_gui(gcbf, handles);
initialize_table(handles);
else
mode=mode+1;
end
setappdata(gcbf, 'mode', mode);
main(mode,handles);
set(handles.getcheck, 'Visible', 'off');
set(handles.getcall, 'Visible', 'off');
set(handles.getbet, 'Visible', 'off');
set(handles.getfold, 'Visible', 'off');
set(handles.newgame, 'Enable', 'on');
kp=getappdata(gcbf, 'kp');
if kp=='y' & quicksim=='n'
set(handles.getdeal, 'Enable', 'on');
end
folded=getappdata(gcbf, 'folded');
allfolded='n';
numfolded=0;
for f=1:nop
if folded(f)=='y'
numfolded=numfolded+1;
end
if numfolded==nop-1
allfolded='y';
end
end
quicksimhand='n';
if allfolded=='y'
quicksimhand='y';
end
if mode==0
set(handles.getdeal, 'String', 'Deal Hand');
set(handles.disppot, 'String', 'Pot: $0');
set(handles.dispstayin, 'String', '');
set(handles.dispqstn, 'String', '');
elseif mode==1
set(handles.getdeal, 'String', 'Deal Flop');
elseif mode==2
set(handles.getdeal, 'String', 'Deal Turn');
elseif mode==3
set(handles.getdeal, 'String', 'Deal River');
elseif mode==4
set(handles.getdeal, 'String', 'Show Cards');
elseif mode==5
quicksimhand='n';
set(handles.getdeal, 'String', 'Deal Hand');
set(handles.disppot, 'String', 'Pot: $0');
set(handles.dispstayin, 'String', '');
set(handles.dispqstn, 'String', '');
set(handles.deckoptions, 'Enable', 'on');
elseif mode==7
main(mode,handles);
end
if quicksim=='y'
quicksimhand='y';
end
end
function newgame_gui(fig_handle, handles)
set(handles.deckoptions, 'Enable', 'on');
set(handles.enterbetamt, 'Visible', 'off');
set(handles.getbetamt, 'Visible', 'off');
set(handles.dispwinner, 'Visible', 'off');
set(handles.playerbox, 'Visible', 'off');
set(handles.playerslabel, 'Visible', 'off');
set(handles.stackslabel, 'Visible', 'off');
set(handles.dispname, 'Visible', 'off');
set(handles.dispstack, 'Visible', 'off');
set(handles.dispdealer, 'Visible', 'off');
set(handles.getdeal, 'Visible', 'off');
set(handles.dealbox, 'Visible', 'off');
set(handles.hndnumbox, 'Visible', 'off');
set(handles.disppot, 'Visible', 'off');
set(handles.dispbet, 'Visible', 'off');
set(handles.dispstayin, 'Visible', 'off');
set(handles.dispqstn, 'Visible', 'off');
set(handles.disphndnum, 'Visible', 'off');
set(handles.getdeal, 'String', 'Deal Hand');
set(handles.disppot, 'String', '');
set(handles.dispstayin, 'String', '');
set(handles.dispbet, 'String', '');
set(handles.dispqstn, 'String', '');
set(handles.dispname, 'String', '')
set(handles.dispstack, 'String', '');
set(handles.enterbetamt, 'String', '')
set(handles.blinds, 'String', '')
set(handles.blindstime, 'String', '');
set(handles.getname, 'String', '')
set(handles.disphndnum, 'String', '');
set(handles.dispdealer, 'String', '');
set(handles.startgame, 'Enable', 'on');
set(handles.getname, 'Enable', 'on');
set(handles.getnop, 'Enable', 'on');
set(handles.getdeal, 'Enable', 'off');
initialize_gui(gcbf, handles);
function initialize_gui(fig_handle, handles)
axes(handles.card1);
cla;
axis off
axes(handles.card2);
cla;
axis off
axes(handles.card3);
cla;
axis off
axes(handles.card4);
cla;
axis off
axes(handles.card5);
cla;
axis off
axes(handles.card6);
cla;
axis off
axes(handles.card7);
cla;
axis off
axes(handles.fhand1);
cla;
axis off
axes(handles.fhand2);
cla;
axis off
axes(handles.fhand3);
cla;
axis off
axes(handles.fhand4);
cla;
axis off
axes(handles.fhand5);
cla;
axis off
axes(handles.fhand6);
cla;
axis off
axes(handles.fhand7);
cla;
axis off
axes(handles.fhand8);
cla;
axis off
for i=1:8
set(eval(['handles.fbox' int2str(i)]), 'Visible', 'off')
set(eval(['handles.fhandname' int2str(i)]), 'Visible', 'off')
set(eval(['handles.fplayername' int2str(i)]), 'Visible', 'off')
end
set(handles.fhandname1, 'String', ' ')
set(handles.fhandname2, 'String', ' ')
set(handles.fhandname3, 'String', ' ')
set(handles.fhandname4, 'String', ' ')
set(handles.fhandname5, 'String', ' ')
set(handles.fhandname6, 'String', ' ')
set(handles.fhandname7, 'String', ' ')
set(handles.fhandname8, 'String', ' ')
set(handles.getcheck, 'Visible', 'off');
set(handles.getcall, 'Visible', 'off');
set(handles.getbet, 'Visible', 'off');
set(handles.getfold, 'Visible', 'off');
set(handles.getcheck,'Value',0);
set(handles.getcall,'Value',0);
set(handles.getbet,'Value',0);
set(handles.getfold,'Value',0);
% --- Executes on button press in radiobutton1.
function radiobutton1_Callback(hObject, eventdata, handles)
% hObject handle to radiobutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of radiobutton1
% --- Executes on button press in radiobutton2.
function radiobutton2_Callback(hObject, eventdata, handles)
% hObject handle to radiobutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of radiobutton2
% --- Executes on button press in radiobutton3.
function radiobutton3_Callback(hObject, eventdata, handles)
% hObject handle to radiobutton3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of radiobutton3
% --- Executes on button press in getfold.
function getfold_Callback(hObject, eventdata, handles)
% hObject handle to getfold (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of getfold
getdcsn=get(handles.getfold,'Value');
if getdcsn==1
set(handles.getcheck,'Value',0);
set(handles.getcall,'Value',0);
set(handles.getbet,'Value',0);
set(handles.getfold,'Value',0);
setappdata(gcbf, 'getdcsn', 'f');
end
% --- Executes on button press in getbet.
function getbet_Callback(hObject, eventdata, handles)
% hObject handle to getbet (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of getbet
getdcsn=get(handles.getbet,'Value');
if getdcsn==1
set(handles.getcheck,'Value',0);
set(handles.getcall,'Value',0);
set(handles.getbet,'Value',0);
set(handles.getfold,'Value',0);
setappdata(gcbf, 'getdcsn', 'b');
end
% --- Executes on button press in getcall.
function getcall_Callback(hObject, eventdata, handles)
% hObject handle to getcall (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of getcall
getdcsn=get(handles.getcall,'Value');
if getdcsn==1
set(handles.getcheck,'Value',0);
set(handles.getcall,'Value',0);
set(handles.getbet,'Value',0);
set(handles.getfold,'Value',0);
setappdata(gcbf, 'getdcsn', 'c');
end
% --- Executes on button press in getcheck.
function getcheck_Callback(hObject, eventdata, handles)
% hObject handle to getcheck (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of getcheck
getdcsn=get(handles.getcheck,'Value');
if getdcsn==1
set(handles.getcheck,'Value',0);
set(handles.getcall,'Value',0);
set(handles.getbet,'Value',0);
set(handles.getfold,'Value',0);
setappdata(gcbf, 'getdcsn', 'k');
end
% --- Executes during object creation, after setting all properties.
function enterbetamt_CreateFcn(hObject, eventdata, handles)
% hObject handle to enterbetamt (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
function enterbetamt_Callback(hObject, eventdata, handles)
% hObject handle to enterbetamt (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of enterbetamt as text
% str2double(get(hObject,'String')) returns contents of enterbetamt as a double
% --- Executes on button press in getbetamt.
function getbetamt_Callback(hObject, eventdata, handles)
% hObject handle to getbetamt (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
betamt=str2double(get(handles.enterbetamt,'String'));
setappdata(gcbf, 'betamt', betamt);
set(handles.enterbetamt, 'String', '')
% --------------------------------------------------------------------
function file_Callback(hObject, eventdata, handles)
% hObject handle to file (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function newgame_Callback(hObject, eventdata, handles)
% hObject handle to newgame (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
newgame_gui(gcbf, handles);
% --------------------------------------------------------------------
function aboutinfo_Callback(hObject, eventdata, handles)
% hObject handle to file (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function versioninfo_Callback(hObject, eventdata, handles)
% hObject handle to versioninfo (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
aboutholdem
function initialize_table(handles)
nop=getappdata(gcbf, 'nop');
nopind=getappdata(gcbf, 'nopind');
playername=getappdata(gcbf, 'playername');
crdimg=imread(['cards/Nn.jpg']);
for i=1:7
axes(eval(['handles.card' int2str(i)]));
image(crdimg);
axis off
end
crdimg1=imread(['cards/sNn.jpg']);
crdimg=[crdimg1 crdimg1 crdimg1 crdimg1 crdimg1];
for i=1:nop
set(eval(['handles.fbox' int2str(i)]), 'Visible', 'on');
set(eval(['handles.fplayername' int2str(i)]), 'Visible', 'on');
set(eval(['handles.fhandname' int2str(i)]), 'Visible', 'on');
set(eval(['handles.fplayername' int2str(i)]), 'String', playername{nopind(i)});
axes(eval(['handles.fhand' int2str(i)]));
image(crdimg);
axis off
end
% --------------------------------------------------------------------
function deckoptions_Callback(hObject, eventdata, handles)
% hObject handle to deckoptions (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
decktype=choosedeck;
setappdata(gcbf, 'decktype', decktype);
% --------------------------------------------------------------------
function exitgame_Callback(hObject, eventdata, handles)
% hObject handle to exitgame (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
close(handles.MTH)