• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

VB6 Yahtzee game

 
Rancher
Posts: 1170
18
IntelliJ IDE Hibernate Firefox Browser MySQL Database Spring Tomcat Server Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I come from a java background, but start a new job tommorow, where everything still is written in vb6.
To get myself a bit familierd with the language I started to make a simple yathzee game.
Everything works great, but somethings take way more could as they should.
For example I included the code I use to check if the player has a three of a kind...



Take note of the second if statement, there most be a easier way to do this...?
 
Saloon Keeper
Posts: 3439
149
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not familiar with yahtzee, but in poker I make a frequency table of a hand. If the table has 3 keys, and one of the key values = 3, then it is three of a kind. (the other two keys must have values 1). The points is then simply 3 times the value of the card, ot in your case the caption of your label.

By the way: in your current routine, must you not also check that the other two cards are not a pair? You would have full house in that case (if applicable to yahtzee).
 
Daniel Demesmaecker
Rancher
Posts: 1170
18
IntelliJ IDE Hibernate Firefox Browser MySQL Database Spring Tomcat Server Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A full house is still three of a kind, if the player chooses to put it at three of a kind instead of full house, cause for example he already has filled in full house, he should be able to.
Poker and yahtzee are about the same, one is with dice, the other with cards...
 
Piet Souris
Saloon Keeper
Posts: 3439
149
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I see.

If the values of the table contain a 3, then if there are three keys, it's three of a kind, otherwise it's full house.. This made it very easy for me to characterize a hand of poker, keeping away from all those ifs in the code, and reducing the methods that check for a certain combination. How many subs รก la lblThreeOfPl1_Click do you have?

Edit: switched three of  a kind and full house into their correct places.
 
Daniel Demesmaecker
Rancher
Posts: 1170
18
IntelliJ IDE Hibernate Firefox Browser MySQL Database Spring Tomcat Server Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There would be six
 
Piet Souris
Saloon Keeper
Posts: 3439
149
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Less than in poker, I guess there is no such thing as a street flush or two pairs. Well, I hope that such a ft makes the coding of yahtzee easier, wit much less if's. If not, let me know where an ft fails for yahtzee.
 
And then we all jump out and yell "surprise! we got you this tiny ad!"
professionally read, modify and write PDF files from Java
https://products.aspose.com/pdf/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!