Question: Can someone help me turn this matlab code into a custom function? Also, if I have a 4x4 matrix and for say an element above
Can someone help me turn this matlab code into a custom function? Also, if I have a 4x4 matrix and for say an element above (a number) it, below it, and to the left and right of it can't be the same.. how would i write that into a code? for example, I have to create the functions to create the 2048 game on matlab. (boardsize refers to the 4x4 matrix that was created in previous code)
This is my code:
if boardsize(1)==2048 fprintf('WIN') elseif boardsize(2)==2048 fprintf('WIN') elseif boardsize(3)==2048 fprintf('WIN') elseif boardsize(4)==2048 fprintf('WIN') elseif boardsize(5)==2048 fprintf('WIN') elseif boardsize(6)==2048 fprintf('WIN') elseif boardsize(7)==2048 fprintf('WIN') elseif boardsize(8)==2048 fprintf('WIN') elseif boardsize(9)==2048 fprintf('WIN') elseif boardsize(10)==2048 fprintf('WIN') elseif boardsize(11)==2048 fprintf('WIN') elseif boardsize(12)==2048 fprintf('WIN') elseif boardsize(13)==2048 fprintf('WIN') elseif boardsize(14)==2048 fprintf('WIN') elseif boardsize(15)==2048 fprintf('WIN') elseif boardsize(16)==2048 fprintf('WIN') elseif boardsize(:,:)~=0 fprintf('LOSE') end
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
