%% Tic-Tac-Flow: Model of a Hand-held Game
% 
% This model shows a variation of the classic tic-tac-toe game with an
% interesting twist. Only the last three moves of each player count. Thus
% the user needs to also account for the order in which the opponent has
% played the last few moves. This adds a nontrivial twist to the gameplay. 
% 
% The model shows several Stateflow(R) charts interacting with each other.
% It exhibits how heavily event-based logic can be captured naturally in
% Stateflow.  It also describes Stateflow semantics such as parallel
% substates, graphical functions and MATLAB(R) handle graphics from
% Stateflow. The model is divided into several subsystems which naturally
% separate the game control from the I/O. This allows for the Stateflow
% code generated from the game control chart to be reused in a hardware
% component.

% Copyright 2006-2019 The MathWorks, Inc.

mdl='sf_tictacflow';
open_system(mdl);

%% 
% The UI is implemented as a MATLAB figure which interacts with the
% Stateflow simulation. The button callback functions drive the inputs to
% the Stateflow chart.


% for now let us completely bypass the entire simulation just to get the
% pretty pictures to appear.
figH = sf_tictacflowgui('fig');

buttonH(1) = sf_tictacflowgui('play_button',figH,1,0);
buttonH(2) = sf_tictacflowgui('play_button',figH,8,1);
buttonH(3) = sf_tictacflowgui('play_button',figH,3,2);
buttonH(4) = sf_tictacflowgui('play_button',figH,6,3);
buttonH(5) = sf_tictacflowgui('play_button',figH,4,4);
buttonH(6) = sf_tictacflowgui('play_button',figH,2,5);
buttonH(7) = sf_tictacflowgui('play_button',figH,5,6);
buttonH(8) = sf_tictacflowgui('play_button',figH,0,7);
buttonH(9) = sf_tictacflowgui('play_button',figH,7,8);
startButtonH = sf_tictacflowgui('start_button',figH);
turnSignalH = sf_tictacflowgui('turn_signal',figH);

set(buttonH(1), 'BackGroundColor', [1, 0, 0]);
set(buttonH(3), 'BackGroundColor', [0, 1, 0]);
set(turnSignalH, 'BackGroundColor', [1, 0, 0]);
