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.
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"