Help with Yahtzee Program

This is a discussion on Help with Yahtzee Program within the C++ Programming forums, part of the General Programming Boards category; I am writing a c++ yahtzee program for my programming class, and i am having trouble with the small straights. ...

  1. #1
    Registered User
    Join Date
    Mar 2009
    Posts
    1

    Help with Yahtzee Program

    I am writing a c++ yahtzee program for my programming class, and i am having trouble with the small straights. I have no idea how to tell if the player has rolled a small straight, can anyone give me a clue as to where to start?

  2. #2
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    I have no idea what small straigt is. You should learn first ask questions...
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  3. #3
    Resu Deretsiger Nightowl's Avatar
    Join Date
    Nov 2008
    Location
    /dev/null
    Posts
    186
    As much as I have to agree, I'd say that the Wikipedia page has some good info on that kind of thing.

    Simply put, it's not difficult. Just check if the maximum difference between the lowest and highest dies is 4, and that no dice are equal to each other.

    (There's probably a simpler solution, but that's the first thing that springs to mind, besides sorting the die values. )
    Do as I say, not as I do . . .

    Experimentation is the essence of programming. Just remember to make a backup first.

    "I'm a firm believer that <SomeGod> gave us two ears and one mouth for a reason - we are supposed to listen, twice as much as we talk." - LEAF

    Questions posted by these guidelines are more likely to be answered.

    Debian GNU/Linux user, with the awesome window manager, the git version control system, and the cmake buildsystem generator.

  4. #4
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,598
    A small straight can be:

    1234
    2345
    3456

    A large straight can be:

    12345
    23456

    What nightowl said is a good way to check for both a small and a large straight with the exception of a large straight having a max difference of 4 and a small straight a max difference of 3 between the dies.

  5. #5
    Resu Deretsiger Nightowl's Avatar
    Join Date
    Nov 2008
    Location
    /dev/null
    Posts
    186
    But of course. My apologies.

    An example could be something like this . . .

    Code:
    /* assuming here that rolled[] is an array of size 6 (int[6]) */
    int max = 0, min = 7;
    int x = 0;
    for(x = 0; x < 6; x ++) {
        if(rolled[x] > max) max = rolled[x];
        if(rolled[x] < min) min = rolled[x];
    }
    
    if(max-min == 3 || max-min == 4) {
        bool same = false;
        for(x = 0; x < 6 && !same; x ++) {
            for(int y = x; y < 6 && !same; y ++) {
                if(x == y) continue;
                if(rolled[x] == rolled[y]) same = true;
        }
        if(same) /* then it's not a straight */
    }
    And so on. Yes, I know that the x loop could be < 5, but this is easier to follow.
    Do as I say, not as I do . . .

    Experimentation is the essence of programming. Just remember to make a backup first.

    "I'm a firm believer that <SomeGod> gave us two ears and one mouth for a reason - we are supposed to listen, twice as much as we talk." - LEAF

    Questions posted by these guidelines are more likely to be answered.

    Debian GNU/Linux user, with the awesome window manager, the git version control system, and the cmake buildsystem generator.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Issue with program that's calling a function and has a loop
    By tigerfansince84 in forum C++ Programming
    Replies: 9
    Last Post: 11-12-2008, 01:38 PM
  2. Need help with a program, theres something in it for you
    By engstudent363 in forum C Programming
    Replies: 1
    Last Post: 02-29-2008, 01:41 PM
  3. Replies: 4
    Last Post: 02-21-2008, 10:39 AM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 11:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21