MATLAB: How to create a grid for memory tile game

creategridmemory tile game

How to create a grid for memory tile game in MATLAB. The grid should contain random number of rows and number of columns by the choice of the player.

Best Answer

The grid generation is easy:
nrows = 5; % User Input: Number Of Rows
ncols = 7; % User Input: NumberOf Columns
XL = [0 nrows];
YL = [0 ncols];
rowx = repmat([0:ncols], 2, 1);
rowy = [min(XL)*ones(1, ncols+1); max(XL)*ones(1, ncols+1)];
colx = [min(YL)*ones(1, nrows+1); max(YL)*ones(1, nrows+1)];
coly = repmat([0:nrows], 2, 1);
figure(1)
plot(rowx, rowy, 'g')
hold on
plot(colx, coly, 'g')
hold off
axis equal tight
Related Question