Creating a program that guesses the colours( not a colour)??
Afficher commentaires plus anciens
I am currently stuck at task 4 at checking how many colours the user entered are correct, and the colour and position are correct! I've tried so hard. Please don't say that I did not make an attempt. And is my false condition correct for breaking the loop? Thanks I am new to MATLAB.
%Written by:
% Student ID:
%ver 01, 8 Dec by JL
% Initiate Random Color Sequence
% r-red; b-blue; y-yellow; g-green; w-white; p-purple; o-orange;
all_colors = 'rbygwpo';
index = randperm(7);
hidden_seq = all_colors(index(1:5));
count = 0;
while 1
%Prompting user to enter input
result = input('Guess the 5 characters colour sequence: ');
count = count + 1;
%Validate user input
if numel(result) > 5 || numel(result) < 5
error('You have entered more or less than 5 characters')
end
%Check the user guesses
% 1. How many guesses has correct colors and position?
% 2. How many guesses has correct colors?
result == hidden_seq
end
Réponse acceptée
Plus de réponses (1)
Steven Lord
le 5 Déc 2015
0 votes
Since this is an assignment, I'll just give a hint. If you remove the exact matches from both (a copy of) the guess and (a copy of) the right answer and have 2 blue, 1 red, and 1 yellow left in your guess and 1 blue, 2 red, and 1 green left in your correct answer, how many "right color, wrong location" entries do you have? How did you figure that out? Can you automate that process?
Catégories
En savoir plus sur Computer Vision Toolbox dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!