Create matlab code for memory game.
Mostrar comentarios más antiguos
I want to create matlab code for following memory game.
Request input from the player to select two cards by entering row and column numbers.
Decision: Are the two selected/newly discovered letters the same?
clear
clc
disp('Welcome to the Memory Game Buddy!')
disp('Here is the board so far, buddy!!!')
% initialize the board
board = cell(4,8);
% prompt user
prompt = "Please enter first card (row col):";
x = input(prompt);
prompt2 = "Please enter second card (row col):";
y = input(prompt2);
4 comentarios
Walter Roberson
el 16 de Ag. de 2022
Walter Roberson
el 16 de Ag. de 2022
You should be checking
isnumeric(x) && isnumeric(y) && numel(x) == 2 && numel(y) == 2
and you should also be checking that any(x ~= y) or else you would be permitting the user to select the same location twice, and of course the values would be the same in that case...
Bozza
el 16 de Ag. de 2022
cell(4,8);
That would generate a 4 x 8 cell array, and then throw it away.
cell{1,8} = '+';
That would generate a 1 x 8 cell array named cell and assign '+' to the last column of the row. After you did this, the name cell would be a variable and it would no longer be possible to explicitly allocate cell arrays.
You should be assigning values to variables
clear cell
board = cell(4,8);
board(:) = {'+'}
Then
isnumeric(x) && isnumeric(y) && numel(x) == 2 && numel(y) == 2
You are calculating a logical result and displaying it, but you should instead be using it to make a decision with an if statement.
Respuestas (1)
Techniques for filling in the hidden board
gorp = repmat('27=@/',1,3)
gorp = gorp(randperm(numel(gorp)))
gorp = reshape(gorp, 3, 5)
2 comentarios
Bozza
el 16 de Ag. de 2022
Walter Roberson
el 17 de Ag. de 2022
gorp = repmat('27=@/',1,3)
That takes 5 different characters and repeats each one 3 times
gorp = gorp(randperm(numel(gorp)))
and that scrambles into a random order
gorp = reshape(gorp, 3, 5)
and that turns it into a 3 x 5 array in which each of the 5 characters is repeated 3 times.
You should be able to use the same kinds of techniques to repeat 8 different characters 4 times and create a 4 x 8 array from the results.
isnumeric(x) && isnumeric(y) && numel(x) == 2 && numel(y) == 2;
Well, before you used to be computing the logical result and displaying it instead of using it to make a decision. Now you have progressed to computing the logical result and discarding it, without using it to make a decision.
Categorías
Más información sobre Card games en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!