3 of a kind...
3 of a kind...
3 of a kind...
3 of a kind...
3 of a kind...
3 of a kind... 3 of a kind... 3 of a kind... 3 of a kind... 3 of a kind... 3 of a kind... 3 of a kind... 3 of a kind...
3 of a kind... 3 of a kind...
3 of a kind...
Go Back  Xtreme Visual Basic Talk > > > 3 of a kind...


Reply
 
Thread Tools Display Modes
  #1  
Old 04-18-2010, 04:54 AM
tinyy tinyy is offline
Newcomer
 
Join Date: Oct 2009
Posts: 10
Default 3 of a kind...


sorry if this isnt the right area im more of a reader than a poster in this forum...

Hmmm im struggling to work out the code for 3 of a kind in my yahtzee game, i think that if i can work this out i can sort my everest of the full house code!

can someone tell me where ive gone astray?

Public dice_value_array(4) As Integer

Case "lblThreeOfAKind"

dice_value_array(0) = CInt(dice1)
dice_value_array(1) = CInt(dice2)
dice_value_array(2) = CInt(dice3)
dice_value_array(3) = CInt(dice4)
dice_value_array(4) = CInt(dice5)

Dim count As Integer = 0

For i As Integer = 0 To 5
For j As Integer = 1 To 6
If dice_value_array(i) = dice_value_array(j) Then
count += 1
End If
Next


If (count >= 3) Then
score += 20
threeof = score
Label9.Text = threeof.ToString
lblThreeOfAKind.Enabled = False
End If
Next

any help would be great cos i think im a stones throw away from insanity!
Reply With Quote
  #2  
Old 04-18-2010, 05:35 AM
Guest0496 Guest0496 is offline
Newcomer
 
Join Date: Apr 2010
Posts: 15
Default

Quote:
Originally Posted by tinyy View Post
sorry if this isnt the right area im more of a reader than a poster in this forum...

Hmmm im struggling to work out the code for 3 of a kind in my yahtzee game, i think that if i can work this out i can sort my everest of the full house code!

can someone tell me where ive gone astray?

Public dice_value_array(4) As Integer

Case "lblThreeOfAKind"

dice_value_array(0) = CInt(dice1)
dice_value_array(1) = CInt(dice2)
dice_value_array(2) = CInt(dice3)
dice_value_array(3) = CInt(dice4)
dice_value_array(4) = CInt(dice5)

Dim count As Integer = 0

For i As Integer = 0 To 5
For j As Integer = 1 To 6
If dice_value_array(i) = dice_value_array(j) Then
count += 1
End If
Next


If (count >= 3) Then
score += 20
threeof = score
Label9.Text = threeof.ToString
lblThreeOfAKind.Enabled = False
End If
Next

any help would be great cos i think im a stones throw away from insanity!
Now the first problem i see is that
For i As Integer = 0 To 5
For j As Integer = 1 To 6

when you declared


Public dice_value_array(4) As Integer

If dice_value_array(i) = dice_value_array(j) Then
count += 1

Here would be my solution:

Code:
Public dice_value_array(4)

                dice_value_array(0) = CInt(dice1)
                dice_value_array(1) = CInt(dice2)
                dice_value_array(2) = CInt(dice3)
                dice_value_array(3) = CInt(dice4)
                dice_value_array(4) = CInt(dice5)

For i as integer = 0 to 4
     For j as integer = 0 to 4
          if i =  j then
          'don't compare it's the same dice
          else
               If dice_value_array(i) = dice_value_array(j) Then
                    count += 1
               End If
          end if 
     next j
next i

If (count >= 3) Then
score += 20
threeof = score
Label9.Text = threeof.ToString
lblThreeOfAKind.Enabled = False
End If
Next
I havn't tested it, but give that a go.

Last edited by Guest0496; 04-18-2010 at 05:39 AM. Reason: Fixed something i missed
Reply With Quote
  #3  
Old 04-18-2010, 05:41 AM
tinyy tinyy is offline
Newcomer
 
Join Date: Oct 2009
Posts: 10
Default

to be honest ive fiddled with these numbers so much i have got a bit lost in my own code...i tested your solution and it didnt throw my usual error of index out of bounds but it did score a 3 of a kind when there wasnt a 3 of a kind...
Reply With Quote
  #4  
Old 04-18-2010, 05:42 AM
Guest0496 Guest0496 is offline
Newcomer
 
Join Date: Apr 2010
Posts: 15
Default

Quote:
Originally Posted by tinyy View Post
to be honest ive fiddled with these numbers so much i have got a bit lost in my own code...i tested your solution and it didnt throw my usual error of index out of bounds but it did score a 3 of a kind when there wasnt a 3 of a kind...
look again; i made a mistake the first time

Code:
For i as integer = 0 to 4
     For j as integer = 0 to 4
          if i =  j then
          'don't compare it's the same dice
          else
               If dice_value_array(i) = dice_value_array(j) Then
                    count += 1
               End If
          end if 
     next j
next i
That should do it for you.
Reply With Quote
  #5  
Old 04-18-2010, 05:55 AM
Guest0496 Guest0496 is offline
Newcomer
 
Join Date: Apr 2010
Posts: 15
Default

just thought of somthing else, after the loop do this:

if count = 0 then
'do nothing
else
Count = Count / 2
end if

thats to account for like

2/3 being the same, but also
3/2 being the same.

hope that helps.
Reply With Quote
  #6  
Old 04-18-2010, 06:27 AM
tinyy tinyy is offline
Newcomer
 
Join Date: Oct 2009
Posts: 10
Default

thanks very much for that. it works like a charm!

so for the count / 3 would that be better suited for working out fullhouse etc?
Reply With Quote
  #7  
Old 04-18-2010, 06:51 AM
tinyy tinyy is offline
Newcomer
 
Join Date: Oct 2009
Posts: 10
Default

hmmm after some further testing it seems it does not work all the time...

i am trying to debug it to see where its going wrong but it just looks like depending what the value is it will not score it when it isnt there but sometimes it will?

is it possible to have some code elsewhere in my solutio that is causing this?
Reply With Quote
  #8  
Old 04-19-2010, 12:40 PM
Guest0496 Guest0496 is offline
Newcomer
 
Join Date: Apr 2010
Posts: 15
Default

Quote:
Originally Posted by tinyy View Post
hmmm after some further testing it seems it does not work all the time...

i am trying to debug it to see where its going wrong but it just looks like depending what the value is it will not score it when it isnt there but sometimes it will?

is it possible to have some code elsewhere in my solutio that is causing this?
Easiest way to debug it is with message boxes; hopefully this will help you debug it:

Code:
For i as integer = 0 to 4
     For j as integer = 0 to 4
          if i =  j then
          'don't compare it's the same dice
          else
               msgbox("Comparing Dice " & i & " Value: " & dice_value_array(i) & " To Dice " & j & " Value: " & dice_value_array(j)
               If dice_value_array(i) = dice_value_array(j) Then
                    count += 1
                    msgbox ("Dice " & i & " And " & j & " are the same! Count: " & count)
               End If
          end if 
     next j
next i

if count = 0 then
'do nothing
else
Count = Count / 2
end if

msgbox ("Final Count: " & Count)
Reply With Quote
  #9  
Old 04-19-2010, 01:41 PM
Rockoon's Avatar
Rockoon Rockoon is offline
Joseph Koss

* Guru *
 
Join Date: Aug 2003
Location: Unfashionable End
Posts: 3,615
Default

Code:
dim count(6) as integer

for i as integer = 0 to 4
  count(dice(i)) += 1
next

for i as integer = 1 to 6
  if count(i) = 5 then msgbox("You rolled 5 " & i & "'s")
  if count(i) = 4 then msgbox("You rolled 4 " & i & "'s")
  if count(i) = 3 then msgbox("You rolled 3 " & i & "'s")
  if count(i) = 2 then msgbox("You rolled 2 " & i & "'s")
  if count(i) = 1 then msgbox("You rolled a " & i)
next
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
3 of a kind...
3 of a kind...
3 of a kind... 3 of a kind...
3 of a kind...
3 of a kind...
3 of a kind... 3 of a kind... 3 of a kind... 3 of a kind... 3 of a kind... 3 of a kind... 3 of a kind...
3 of a kind...
3 of a kind...
 
3 of a kind...
3 of a kind...
 
-->