• 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
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

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...?
 
Bartender
Posts: 4103
156
  • 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
Bartender
Posts: 4103
156
  • 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
Bartender
Posts: 4103
156
  • 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.
 
I don't like that guy. The tiny ad agrees with me.
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic