ginput tic tac toe

8 views (last 30 days)
Yasin Kilic
Yasin Kilic on 26 Sep 2020
Commented: Yasin Kilic on 29 Sep 2020
Hi
I have made a figure that resemblies a tic tac toe (XO) board
I am very new to matlab, and i have been assigned to make a tic tac toe game, the contruction is up to me
We have had 3 courses with matlab
I have made a figure, and i thought that maybe with the ginput i can put in my mark for either X or O
Can someone guide me thru a simple method to make this game work?
I really appreciate your help
% Create figure
figure1 = figure;
% Create axes
axes1 = axes('Parent',figure1,...
'Position',[0.232142857142857 0.383333333333333 0.433928571428571 0.395238095238095]);
% Create light
light('Parent',axes1,'Position',[-0.433012701892219 0.5 0.75]);
% Create line
annotation(figure1,'line',[0.375 0.375],...
[0.777571428571429 0.383333333333333]);
% Create line
annotation(figure1,'line',[0.503571428571429 0.501785714285714],...
[0.768047619047619 0.373809523809524]);
% Create line
annotation(figure1,'line',[0.2375 0.660714285714286],...
[0.520428571428571 0.519047619047619]);
% Create line
annotation(figure1,'line',[0.233928571428571 0.666071428571429],...
[0.65852380952381 0.65952380952381]);
ginput

Answers (1)

Mohammad Sami
Mohammad Sami on 28 Sep 2020
You can set xlim and ylim for your axes to [0 3]. Then you can get the [x,y] = ginput(1).
Another option would be to use 9 buttons in 3x3 configuration.
  3 Comments
Mohammad Sami
Mohammad Sami on 29 Sep 2020
You can place text on axes using text function. text(axes1,x,y,'X'); This will place the text X at the specified location.
Yasin Kilic
Yasin Kilic on 29 Sep 2020
Thank you very much
I now a game
I can make x and o
When it makes x at one location my matrix make an 1 in that places, and when it makes o at one location my matrix makes 2 in that place
Like
1 0 0
0 0 2
0 0 0
How can i make a code for who have won ?
Can i make something like
If my matrix reads 1 1 1 player X have won
or 2 2 2 or
1 2 1
1 2 1
0 2 0 player O have won
Is there a code to this?

Sign in to comment.

Categories

Find more on Strategy & Logic in Help Center and File Exchange

Products


Release

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!