Problem with an array

Blitz3D Forums/Blitz3D Beginners Area/Problem with an array

First off, here's my code:

Dim DICE(5)
DICE(1) = 1
DICE(2) = 2
DICE(3) = 2
DICE(4) = 1
DICE(5) = 5

Global COUNT = 0
Global THREE_OF_A_KIND = False

For I = 1 To 5
	For J = 1 To 5
	
		If DICE(I) = J
			COUNT = COUNT + 1
			Print COUNT
		EndIf
		
	Next
Next

If COUNT > 2
	THREE_OF_A_KIND = True
EndIf

If THREE_OF_A_KIND = True
	Print "ASD"
	WaitKey()
EndIf


I'm trying to make a Yahtzee game, and i've come across a error trying to calculate wether or not a roll is a three of a kind.

For some reason it keeps showing that dice(I) always equals J, which shouldn't happen. Should it? Why does it keep showing this?

Probably you need to track the count of the single number..
Dim DICE(5)
Dim acount(5)

DICE(1) = 1
DICE(2) = 2
DICE(3) = 2
DICE(4) = 2 
DICE(5) = 5

Global THREE_OF_A_KIND = False

For i=1 To 5
For j=1 To 5
If i=dice(j)
	acount(i)=acount(i)+1
	Print "DICE: "+dice(i)+" = "+acount(i)
	End If
Next
Next

For i=1 To 5
If acount(i)>2 three_of_a_kind=True
;you can control the frequency of the extraction per single number if you want
Next


If THREE_OF_A_KIND = True
	Print "ASD"
	WaitKey()
EndIf
End


With the code you posted it shows that the dice are the following values:

dice 1: 1
dice 2: 1
dice 3: 2
dice 4: 3
dice 5: 1

when it's actually 1,2,2,2,3... Odd.

Your just reading it wrong val, try changing the print statement to this, might make the info clearer.

Print "DICE "+j+" value is '"+dice(i)+"'  / "+acount(i)+" of these found so far"


acount(i) counts how many times the number i in Dice(i) is present.
For i=1 To 5
Print "DICE: "+i+" = "+acount(i)
Next

maybe this is more clear...

Makes sense now. . Hehe. Thanks guys.

I got the arrays down, but now I have another problem. How do you calculate a fullhouse so that ANY order of the dice works. I'm stuck here :s

what is a FULLHOUSE? Sorry but english in not my natural language.

I would suggest that you do a sort on your dice data so that order will no longer be a problem... That way you can just check to see if

Case1: the first three and last two are the same
Case2: the first two and last three are the same

If Case1 or Case2 are true you have a full house... unless they are all the same in which case you have Yahtzee (5 of a kind)

I just checked the rules and I think this works,

I changed the >2 for the 3 of a kind check since this would detect 4 of a kind too which I assume is wrong...not sure on the rules for that but you can tell us ;)

Dim DICE(5)
Dim acount(5)

DICE(1) = 2
DICE(2) = 2
DICE(3) = 2
DICE(4) = 5 
DICE(5) = 3

Global THREE_OF_A_KIND = False
Global fullhouse=0

For i=1 To 5
For j=1 To 5
If i=dice(j)
	acount(i)=acount(i)+1
	Print "DICE: "+dice(j)+" = "+acount(i)
	End If
Next
Next


For i=1 To 5
If acount(i)=3 Then  three_of_a_kind=True ;changed since >2 might mean there are 4 dice of the same value
;you can control the frequency of the extraction per single number if you want
Next

;Fullhouse check
For i=1 To 5
If acount(i)=2 Then fullhouse=fullhouse+2
If acount(i)=3 Then fullhouse=fullhouse+3
Next

If fullhouse=5
THREE_OF_A_KIND=False ;we have a fullhouse so ignore 3 of a kind...is this an ok rule?
Print "Fullhouse!"
WaitKey()
EndIf



If THREE_OF_A_KIND = True
	Print "3 of a Kind"
	WaitKey()
EndIf
End
  


.