
-----------------------------------
prosyntax
Mon Jun 12, 2006 11:51 pm

Loops and Rand.Int --HELP!
-----------------------------------
Hi, I programming a mastermind game that can be played against the computer or another player.

I'm having trouble in the computer mode.
I have generated a random code (answer), the player recieves 7 tries.
I evaluate the player's guess against the solution to generate hints or exit the loop if the player has gotten it right on the first try.  But when I evaluate for hints, I substitute some of the characters in the answer and the guess for some other random character so I don't evaluate again if I had already assessed them as an exact/partial match.
If they recieve hints regarding if they have an exact or partial match, that obviously means they didn't get it right the first time, so they may guess again.  When they guess again, the program must go through the same structure of comparing the guess to the answer.  But because I've substituted in different characters for the code from the previous evaluation, I don't have the same code to compare to the answer.  How may I solve that problem?  Because if I do Rand.Int again to get a code, then that code would not be the same! :shock:

-----------------------------------
Mr. T
Mon Jun 12, 2006 11:54 pm

Alex's Opinion
-----------------------------------
Er...how about posting some code.  :think:

-----------------------------------
prosyntax
Mon Jun 12, 2006 11:59 pm

code
-----------------------------------

var answer : string := ""

for a : 1 .. 4
    answer := answer + intstr (Rand.Int (1,5))
end for


-----------------------------------
Mr. T
Tue Jun 13, 2006 12:01 am

Re: Loops and Rand.Int --HELP!
-----------------------------------
Because if I do Rand.Int again to get a code, then that code would not be the same! :shock:
Store the initial Rand.Int'ed stuff in vars and keep them untouched throughout the entire program.

-----------------------------------
prosyntax
Tue Jun 13, 2006 12:07 am

RE
-----------------------------------
So if I store it in variables initially, it won't change the value through and through?

-----------------------------------
prosyntax
Tue Jun 13, 2006 12:13 am

...problem
-----------------------------------
But if my game may be played against the computer and person vs. person, but wouldn't declaring my characters for the code initially clash with the rest of the code for my program?  I'd need to write a whole seperate category of code just for comp vs. person game and a person vs. person game

-----------------------------------
Mr. T
Tue Jun 13, 2006 12:13 am

Alex's Opinion
-----------------------------------
var keep, alter : int := 2343

alter := alter + 1000

if keep >= alter then
    put "Turing is screwed."
else
    put
        "Good job! Your 'alter' and 'keep' variables started off with the same value.  After adding 1000 to the 'alter' variable, you compared it to the unchanged keep variable and you found out that 'alter' > 'keep'"
end if
