How to Make a board in Matlab

조회 수: 13 (최근 30일)
Krish Desai
Krish Desai 2015년 11월 4일
댓글: Geoff Hayes 2015년 11월 8일
I want to make a n x n size board in Matlab (n is a user input). How do I do this?
I want it to appear as:
1 2 3 4 5 6 7 8 9 10
1 x x x x x x x x x x
2 x x x x x x x x x x
3 x x x x x x x x x x
4 x x x x x x x x x x
5 x x x x x x x x x x
6 x x x x x x x x x x
7 x x x x x x x x x x
8 x x x x x x x x x x
9 x x x x x x x x x x
10 x x x x x x x x x x

채택된 답변

Geoff Hayes
Geoff Hayes 2015년 11월 8일
Krish - you could consider using a cell array to represent the characters in your board. For example,
n = 12;
board = cell(n+1,n+1);
% initialize the board
for u=1:n+1
for v=1:n+1
if u==1
if v<=n
board{u,v+1} = v;
board{v+1,u} = v;
end
elseif v==1
% do nothing
else
board{u,v} = 'x';
end
end
end
would create a board similar to what you are requesting. I noticed that you tagged your question with "GUI". Were you hoping to create some sort of GUI with the above board embedded in it?
  댓글 수: 2
Krish Desai
Krish Desai 2015년 11월 8일
편집: Krish Desai 2015년 11월 8일
My end goal is to create a game themed of off Game of Thrones. Using this board, a user inputs a number and that number corresponds to an action. So for instance if the number 5,5 is inputted that position is revealed. If there are no kings surrounding the square in one space any way then all the spaces are uncovered. If there are no kings surrounding the uncovered squares the surrounding squares are also uncovered and so on. To open a position the user uses a knight, the game ends by uncovering all the kings or losing all your knights.
To answer your question, I have no idea if I need to use a GUI or not, but I was told that it was a way I could start.
Geoff Hayes
Geoff Hayes 2015년 11월 8일
Krish - I think that you have to decide whether you want to create a game that is driven from the command line or whether you want to use a GUI. If the latter, then you will need to decide how best to represent the board on an axes (possibly create a grid of some kind).

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Board games에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by