Skip to main content

Dice Evaluationevaluation in a Yahtzee Type Game-type game

I just started using Godot, and I am attempting to build a Yahtzee type-type game on my own. I created a function to evaluate the dice/roll and have it working correctly, I believe. I was hoping to get some more experienced eyes to look over my solution and provide some helpful feedback/criticism.

Instead of storing each die as an individual value, my first instinct was to group values, kind of tallying the total of each side rolled. I'm mainly curious if this is efficient enough and if someone can spot andan edge case. But I'm also interested in improving it, so anything helpful is appreciated.

Edit: Noticed
I noticed this as well.: When I duplicate the array in the chunk, I evaluating for "Pairs" and remove at that index. Using .Find(2).Find(2) instead of .Any().Any() in the following Ifif statement will return true in cases where it shouldn't (only 1 pair). I Lookedlooked at both functions in the class definition, and I am still confused about why that actsthey act like it doesthey do. Maybe someone can explain?

Dice Evaluation in a Yahtzee Type Game

I just started using Godot, and I am attempting to build a Yahtzee type game on my own. I created a function to evaluate the dice/roll and have it working correctly I believe. I was hoping to get some more experienced eyes to look over my solution and provide some helpful feedback/criticism.

Instead of storing each die as an individual value, my first instinct was to group values, kind of tallying the total of each side rolled. I'm mainly curious if this is efficient enough and if someone can spot and edge case. But I'm also interested in improving it, so anything helpful is appreciated.

Edit: Noticed this as well. When I duplicate the array in the chunk evaluating for "Pairs" and remove at that index. Using .Find(2) instead of .Any() in the following If statement will return true in cases where it shouldn't (only 1 pair). I Looked at both functions in the class definition and I am still confused why that acts like it does. Maybe someone can explain?

Dice evaluation in a Yahtzee-type game

I just started using Godot, and I am attempting to build a Yahtzee-type game on my own. I created a function to evaluate the dice/roll and have it working correctly, I believe. I was hoping to get some more experienced eyes to look over my solution and provide some helpful feedback/criticism.

Instead of storing each die as an individual value, my first instinct was to group values, kind of tallying the total of each side rolled. I'm mainly curious if this is efficient enough and if someone can spot an edge case. But I'm also interested in improving it, so anything helpful is appreciated.

Edit:
I noticed this as well: When I duplicate the array in the chunk, I evaluating for "Pairs" and remove at that index. Using .Find(2) instead of .Any() in the following if statement will return true in cases where it shouldn't (only 1 pair). I looked at both functions in the class definition, and I am still confused about why they act like they do. Maybe someone can explain?

added 373 characters in body
Source Link

Edit: Noticed this as well. When I duplicate the array in the chunk evaluating for "Pairs" and remove at that index. Using .Find(2) instead of .Any() in the following If statement will return true in cases where it shouldn't (only 1 pair). I Looked at both functions in the class definition and I am still confused why that acts like it does. Maybe someone can explain?

Edit: Noticed this as well. When I duplicate the array in the chunk evaluating for "Pairs" and remove at that index. Using .Find(2) instead of .Any() in the following If statement will return true in cases where it shouldn't (only 1 pair). I Looked at both functions in the class definition and I am still confused why that acts like it does. Maybe someone can explain?

Rollback to Revision 5
Source Link
var ones: int = 0
var twos: int = 0
var threes: int = 0
var fours: int = 0
var fives: int = 0
var sixes: int = 0
var straightIndex: = 0

func evalute_roll(): 

var roll: Array[int] = [ones,twos,threes,fours,fives,sixes]

if roll.any(func(number): return number == 5): # Yatzhee
    rollText.text = "Yatzee!"

elif roll.any(func(number): return number == 4): # 4 of a Kind
    rollText.text = "4 of a Kind!"

elif roll.any(func(number): return number == 3): # Trips or Full House
    if roll.any(func(number): return number == 2):
        rollText.text = "Full House!"
    else:
        rollText.text = "3 of a Kind!"

elif roll.any(func(number): return number == 2): # Pair or 2Pair, Identify Pair Type.
    var side: String = ""
    var tempArray = roll.duplicate() 
    var index: int = tempArray.find(2)
    tempArray.remove_at(index)

    if tempArray.any(func(number): return number == 2):
        rollText.text = "2 Pair!"
    else:
        match index:
            0: side = "Ones"
            1: side = "Twos"
            2: side = "Threes"
            3: side = "Fours"
            4: side = "Fives"
            5: side = "Sixes"
        rollText.text = "Pair of " + side

elif roll.any(func(number): return number == 1): # Small and Large Straight
    for n in roll.size():
         if roll[n] == 1: 
              straightIndex += 1 
         else:
             if straightIndex === 04: 
    if straightIndex == 4: 
           rollText.text = "Small Straight!"
              elif straightIndex == 5: 
                  rollText.text = "Large Straight!" 

    else     elif roll[n] == 0 and straightIndex != 0:
              straightIndex -= 1
else:
    rollText.text = "Scratch"
var ones: int = 0
var twos: int = 0
var threes: int = 0
var fours: int = 0
var fives: int = 0
var sixes: int = 0
var straightIndex: = 0

func evalute_roll(): 

var roll: Array[int] = [ones,twos,threes,fours,fives,sixes]

if roll.any(func(number): return number == 5): # Yatzhee
    rollText.text = "Yatzee!"

elif roll.any(func(number): return number == 4): # 4 of a Kind
    rollText.text = "4 of a Kind!"

elif roll.any(func(number): return number == 3): # Trips or Full House
    if roll.any(func(number): return number == 2):
        rollText.text = "Full House!"
    else:
        rollText.text = "3 of a Kind!"

elif roll.any(func(number): return number == 2): # Pair or 2Pair, Identify Pair Type.
    var side: String = ""
    var tempArray = roll.duplicate() 
    var index: int = tempArray.find(2)
    tempArray.remove_at(index)

    if tempArray.any(func(number): return number == 2):
        rollText.text = "2 Pair!"
    else:
        match index:
            0: side = "Ones"
            1: side = "Twos"
            2: side = "Threes"
            3: side = "Fours"
            4: side = "Fives"
            5: side = "Sixes"
        rollText.text = "Pair of " + side

elif roll.any(func(number): return number == 1): # Small and Large Straight
    for n in roll.size():
         if roll[n] == 1: 
              straightIndex += 1 
         else:
              straightIndex = 0
    if straightIndex == 4: 
          rollText.text = "Small Straight!"
    elif straightIndex == 5: 
         rollText.text = "Large Straight!"
    else:
         rollText.text = "Scratch"
var ones: int = 0
var twos: int = 0
var threes: int = 0
var fours: int = 0
var fives: int = 0
var sixes: int = 0
var straightIndex: = 0

func evalute_roll(): 

var roll: Array[int] = [ones,twos,threes,fours,fives,sixes]

if roll.any(func(number): return number == 5): # Yatzhee
    rollText.text = "Yatzee!"

elif roll.any(func(number): return number == 4): # 4 of a Kind
    rollText.text = "4 of a Kind!"

elif roll.any(func(number): return number == 3): # Trips or Full House
    if roll.any(func(number): return number == 2):
        rollText.text = "Full House!"
    else:
        rollText.text = "3 of a Kind!"

elif roll.any(func(number): return number == 2): # Pair or 2Pair, Identify Pair Type.
    var side: String = ""
    var tempArray = roll.duplicate() 
    var index: int = tempArray.find(2)
    tempArray.remove_at(index)

    if tempArray.any(func(number): return number == 2):
        rollText.text = "2 Pair!"
    else:
        match index:
            0: side = "Ones"
            1: side = "Twos"
            2: side = "Threes"
            3: side = "Fours"
            4: side = "Fives"
            5: side = "Sixes"
        rollText.text = "Pair of " + side

elif roll.any(func(number): return number == 1): # Small and Large Straight
    for n in roll.size():
         if roll[n] == 1: 
              straightIndex += 1 
              if straightIndex == 4: 
                  rollText.text = "Small Straight!"
              elif straightIndex == 5: 
                  rollText.text = "Large Straight!" 

         elif roll[n] == 0 and straightIndex != 0:
              straightIndex -= 1
else:
    rollText.text = "Scratch"
deleted 68 characters in body
Source Link
Loading
added 8 characters in body
Source Link
Loading
added 22 characters in body
Source Link
Loading
deleted 15 characters in body; edited tags; edited title
Source Link
toolic
  • 6.2k
  • 4
  • 20
  • 75
Loading
edited tags
Link
Loading
Source Link
Loading