|
Post by Nick on Sept 14, 2002 20:09:20 GMT -5
Hi,
I don't know if anyone has heard of or played this game, but I want to make it. How would I go about getting the random order of numbers/symbols/what ever?
|
|
|
Post by mog42 on Sept 14, 2002 22:55:19 GMT -5
There are 4 pegs with 6 colors, right? Then use this instruction:
randInt(1,6,4)
It will return a list with 4 random numbers whose values are anywhere between 1 and 6.
|
|
|
Post by Nick on Sept 15, 2002 13:55:24 GMT -5
I figured that part out, but how would i check that against the users input and tell them if it is a right number or a right number but in the wrong spot?
I have a basic game made if you would like to see it I can post it.
|
|
|
Post by mog42 on Sept 15, 2002 16:52:36 GMT -5
The best way to do that would be to use a list to store the numbers the user is trying to guess and another list to store the user's input.
L1 is the numbers the user is trying to guess, and L2 is the list that gets user input. L3 is a list that stores program output. In L1 and L2, the numbers 1-6 are colors. In L3, 1 means right color/right spot, and 2 means right color/wrong spot.
{0,0,0,0}->L3 For(A,1,4 ;execute loop once for each number in list 0->C ;I'll explain C later If L1(A)=L2(A ;If the user guessed a number correctly Then 1->L3(A ;1 means that they guessed correctly 0->L2(A ;eliminated this number from input list so it isn't counted twice Else ;check to see if they have the right number in the wrong spot For(B,1,4 ;check every spot to look for the right color If L1(A)=L2(B) and not(L1(B)=L2(B) and not(C ;If they got the right number in the wrong spot Then 2->L3(A 0->L2(A 1->C ;This makes the program remember that it already found a right color in a wrong spot. End End End End
You'll probably want to use sortA( on L3 so you mix up the order of the numbers
|
|
|
Post by Chris on Sept 15, 2002 17:00:35 GMT -5
i'm not sure what their input would be (i've never played mastermind)...but based on what you said you'd be comparing it to, that it's a color from 1-6 and a location from 1-4, if that's the case then, this would work for you
C=the user's number, L=the location they put in, and L1=the list that randint(1,6,4) returned
----code---- Delvar L2 For(A,1,4 0 If C=L1(A 1 Ans->L2(A End Delvar A If sum(L2 2->A If L2(L 1->A ----end code----
if the user picked the right number and the right spot A will have 1 in it, if they picked the right number but the wrong spot, A will have 2 in it, and if you want to determin how many spots have the number he picked in it, you can do sum(L2
hope that helps
|
|
|
Post by Chris on Sept 15, 2002 17:01:11 GMT -5
HAHAHAHAHHA, mog answered your question while i was typing a reply to it.....HAHAHAHAHAHAHAHAHAH
|
|
|
Post by mog42 on Sept 15, 2002 18:29:09 GMT -5
Heh, that doesn't happen much on this board, does it? At big message boards, that sort of thing happens rather frequently. But here, it's uncommon for there to be more than 2 users online simulatneously.
|
|