Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %% Magic Trick
- %{
- I'm back! New and improved!
- JK I'm still undercooked.
- anyways comments for the good of the order are at the end
- %}
- clc, clear
- Names = {'Ace ','Two ','Three ', 'Four ', 'Five ', 'Six ', 'Seven ', 'Eight ', 'Nine ', 'Ten ', 'Jack ', 'Queen ', 'King '};
- Suits = {'Hearts', 'Diamond', 'Clubs', 'Spades'};
- q = 1; % Random Number
- while q < 53 % Creates set values of cards
- for column = 1:4
- for row = 1:13
- Set(q) = strcat(Names(row), Suits(column));
- q = q + 1;
- row = row + 1;
- end
- end
- end
- Set = reshape(Set, 13,4); % reshaping the Set array
- ran_cards = randperm(52,21); % Drawing random cards for game
- for i = 1:length(ran_cards) % Giving random number card values
- game_cards(i) = Set(ran_cards(i));
- end
- % This took 90 min to make... moving on...
- fprintf('\n Choose a card \n')
- Set_up = reshape(game_cards, 7,3) % Shows cards to viewer
- % Allocating columns to vectors for first redeal
- x1 = Set_up(:,1);
- y1 = Set_up(:,2);
- z1 = Set_up(:,3);
- First = input(['Which column is your card in? \n'...
- 'Left, Middle, Right \n\n'],'s'); % First shuffle
- a1 = strcmp(First,'Left'); % placeholder
- b1 = strcmp(First,'Middle'); % placeholder
- c1 = strcmp(First,'Right'); % placeholder
- if a1 == 1 || b1== 1 ||c1 == 1 % Making sure column is chosen
- fprintf('\n Great! Shuffling... \n\n')
- else
- while a1 ~= 1 && b1 ~= 1 && c1 ~= 1
- First = input(['Which column is your card in? \n'...
- 'Left, Middle, Right \n\n'],'s'); % First shuffle
- a1 = strcmp(First,'Left'); % placeholder
- b1 = strcmp(First,'Middle'); % placeholder
- c1 = strcmp(First,'Right'); % placeholder
- end
- fprintf('\n Great! Shuffling... \n')
- end
- % That took another 60 min...
- switch First
- case 'Left'
- yxz1 = [y1; x1; z1];
- q1 = 1;
- while q1 < 22
- for row1 = 1:7
- for column1 = 1:3
- ReDeal_1(row1,column1) = yxz1(q1);
- q1 = q1 + 1;
- column1 = column1 + 1;
- end
- end
- end
- case 'Middle'
- xyz1 = [x1; y1; z1];
- q1 = 1;
- while q1 < 22
- for row1 = 1:7
- for column1 = 1:3
- ReDeal_1(row1,column1) = xyz1(q1);
- q1 = q1 + 1;
- column1 = column1 + 1;
- end
- end
- end
- case 'Right'
- xzy1 = [x1; z1; y1];
- q1 = 1;
- while q1 < 22
- for row1 = 1:7
- for column1 = 1:3
- ReDeal_1(row1,column1) = xzy1(q1);
- q1 = q1 + 1;
- column1 = column1 + 1;
- end
- end
- end
- end
- % Shows first redeal
- fprintf('First Redeal\n')
- reshape(ReDeal_1, 7,3)
- % Allocating columns to vectors for second redeal
- x2 = ReDeal_1(:,1);
- y2 = ReDeal_1(:,2);
- z2 = ReDeal_1(:,3);
- Second = input(['Which column is your card in? \n'...
- 'Left, Middle, Right \n\n'],'s'); % Second shuffle
- a2 = strcmp(Second,'Left'); % placeholder
- b2 = strcmp(Second,'Middle'); % placeholder
- c2 = strcmp(Second,'Right'); % placeholder
- if a2 == 1 || b2== 1 ||c2 == 1 % Making sure column is chosen
- fprintf('\n Great! Shuffling... \n\n')
- else
- while a2 ~= 1 && b2 ~= 1 && c2 ~= 1
- Second = input(['Which column is your card in? \n'...
- 'Left, Middle, Right \n\n'],'s'); % Second shuffle
- a2 = strcmp(Second,'Left'); % placeholder
- b2 = strcmp(Second,'Middle'); % placeholder
- c2 = strcmp(Second,'Right'); % placeholder
- end
- fprintf('\n Great! Shuffling... \n')
- end
- switch Second
- case 'Left'
- yxz2 = [y2; x2; z2];
- q2 = 1;
- while q2 < 22
- for row2 = 1:7
- for column2 = 1:3
- ReDeal_2(row2,column2) = yxz2(q2);
- q2 = q2 + 1;
- column2 = column2 + 1;
- end
- end
- end
- case 'Middle'
- xyz2 = [x2; y2; z2];
- q2 = 1;
- while q2 < 22
- for row2 = 1:7
- for column2 = 1:3
- ReDeal_2(row2,column2) = xyz2(q2);
- q2 = q2 + 1;
- column2 = column2 + 1;
- end
- end
- end
- case 'Right'
- xzy2 = [x2; z2; y2];
- q2 = 1;
- while q2 < 22
- for row2 = 1:7
- for column2 = 1:3
- ReDeal_2(row2,column2) = xzy2(q2);
- q2 = q2 + 1;
- column2 = column2 + 1;
- end
- end
- end
- end
- % Shows second redeal
- fprintf('Second Redeal\n')
- reshape(ReDeal_2, 7, 3)
- % Allocating columns to vectors for third redeal
- x3 = ReDeal_2(:,1);
- y3 = ReDeal_2(:,2);
- z3 = ReDeal_2(:,3);
- Third = input(['Which column is your card in? \n'...
- 'Left, Middle, Right \n\n'],'s'); % Third shuffle
- a3 = strcmp(Third,'Left'); % placeholder
- b3 = strcmp(Third,'Middle'); % placeholder
- c3 = strcmp(Third,'Right'); % placeholder
- if a3 == 1 || b3 == 1 ||c3 == 1 % Making sure column is chosen
- fprintf('\n Great! Shuffling... \n\n')
- else
- while a3 ~= 1 && b3 ~= 1 && c3 ~= 1
- Third = input(['Which column is your card in? \n'...
- 'Left, Middle, Right \n\n'],'s'); % Third shuffle
- a3 = strcmp(Third,'Left'); % placeholder
- b3 = strcmp(Third,'Middle'); % placeholder
- c3 = strcmp(Third,'Right'); % placeholder
- end
- fprintf('\n Great! Shuffling... \n')
- end
- switch Third
- case 'Left'
- yxz3 = [y3; x3; z3];
- q3 = 1;
- while q3 < 22
- for row3 = 1:7
- for column3 = 1:3
- ReDeal_3(row3,column3) = yxz3(q3);
- q3 = q3 + 1;
- column3 = column3 + 1;
- end
- end
- end
- case 'Middle'
- xyz3 = [x3; y3; z3];
- q3 = 1;
- while q3 < 22
- for row3 = 1:7
- for column3 = 1:3
- ReDeal_3(row3,column3) = xyz3(q3);
- q3 = q3 + 1;
- column3 = column3 + 1;
- end
- end
- end
- case 'Right'
- xzy3 = [x3; z3; y3];
- q3 = 1;
- while q3 < 22
- for row3 = 1:7
- for column3 = 1:3
- ReDeal_3(row3,column3) = xzy3(q3);
- q3 = q3 + 1;
- column3 = column3 + 1;
- end
- end
- end
- end
- fprintf('Is This your card?')
- ReDeal_3(11)
- % Total elapsed time : 3 hours 30 min
- %{
- For best viewing experience
- I recommend undocking command window to
- play through the code.
- I spent way too much time on lines that could be
- ignored from not undocking.
- IMPORTANT
- Clear the variables after every run.
- Code relies on user input every time.
- SIDE NOTES
- Edited code to remove final reshuffle.
- Every card ended up in the middle row instead of
- any of the three rows. Should work the same
- Code is based off card trick using 21 different cards.
- Seven rows of three condensed and redealt 2x.
- Usually ends with a minigame but that extra coding
- would take me a LOT longer.
- So the short version it is. Hope you enjoyed it!
- I know that others could've 'done it faster'
- give me a break though.
- I haven't used MATLAB since last semester,
- and I only used it for Simulink
- so my coding is a little rusty.
- A lot rusty.
- My goal is to remake this code to read tarot cards
- one day. Maybe I'll do that over the summer.
- Maybe I'll make the minigame.
- I'll probably do neither.
- %}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement