# help me , Treasure hunt game code

5 visualizzazioni (ultimi 30 giorni)
justlikethat il 16 Mag 2021
Commentato: David Fletcher il 16 Mag 2021
A treasure chest is placed on any number of floors in a 100-story building. If you match the number of floors, you'll be the winner.
Gameplay If the computer says any number of floors, the treasure chest will be located higher than the player said.
only tells you it's in a down position.
The position of the treasure chest through continuous player questions. You can get it right.
he sooner you find it, the less questions you ask, the higher the score. You can't play games like this.
Write down the Matlab code that exists.
f = floor(rand()*100) + 1
t = input('t')
n = 0;
while n<1
n = n+1;
if t>f
disp('up')
end
if t<f
disp('down')
end
end
I want to make sure that I don't see the code f on which floor I'm coming out, I want to know the code to know how many times I've tried, and I want to know the code to know each score according to the number of attempts.
My English is not good, so there may be some grammatical errors. thank you.
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Risposta accettata

David Fletcher il 16 Mag 2021
Try this:
f = floor(rand()*100) + 1;
n = 0;
while 1
t = input('t')
if t<f
disp('up')
elseif t>f
disp('down')
else
disp('correct')
break;
end
n = n+1;
end
%number of tries
n
##### 3 CommentiMostra 1 commento meno recenteNascondi 1 commento meno recente
justlikethat il 16 Mag 2021
@David Fletcher I changed n = 0; to n = 1; .
That's how I get the price I want. Is this right?
David Fletcher il 16 Mag 2021
In the code n represents the number of guesses - I suppose if you want to relate it to a score (or prize), then it would be inversely proportional to the number of guesses (i.e the more guesses, the lower the prize and vice versa). A simple implementation would be to start with a 'prize' of £1000 and the player gets 1000/n at the end

Accedi per commentare.

### Categorie

Scopri di più su Strategy & Logic in Help Center e File Exchange

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by