Hello, im pretty new to Godot (2nd project) and Im trying to make a balatro type game but with farkle which is a dice game and it uses similar combos to poker like straights, 3 of a kind, 4 of a kind etc. I thought this wouldn't be too difficult as its just dice but I underestimated how complicated (at least in my opinion) poker type game logic would be to create. I feel like this topic isn't talked upon much because when searching for a tutorial I can't find anything and I tried to use Chat GPT to help me which just led to more problems and confusion. If anybody could lead me to a tutorial or lead me in the right direction I would be very thankful!
#Poker/Card Game Logic Help
1 messages · Page 1 of 1 (latest)
Balatro mentioned
Anyway
I think the the easiest to understand way of detecting hands is to just iterate over every card in the hand and compare it to a list of possible hands
But that's definitely not the most efficient way
I think a way to make it take less comparisons is to sort the cards by rank
That way for a straight, you can start at the beginning of the array and look for lower ranks
And you don't have to worry about there being higher ranks
Uhh what other hands does farkle have?
depends some people include different combos but the ones im planning to include are straights, 3 pairs, 2 three of a kinds. Also in farkle you can play ones and fives with any combo or just alone for standard points.
Okay I found the Wikipedia article on farkle
Okay so if you take the dice array and sort it in ascending order, then I think you can get all the combos after one iteration
So every one and five is its own combo
yes you can play ones and fives normally ones are 100 points and 5's are 50
okay thanks 🙂
also this isn't necessary and I could try to figure this out on my own later as long as I get the fundamentals down first but in this game called kingdom come deliverence 2 you can play farkle and the 3 of a kind combo multiplys with each additional value afterwards. I wanted to implement this too but it isn't urgent.
I do have this right now in a script called score manager and it adds and erases the scores to an array when the dice are selected I just dont have a function to calculate the score yet
okay so here's my logic for detecting three of a kind
var dice := [1, 1, 1, 3, 4, 5]
dice.sort()
var combos := []
var current_combo_count := 0
var current_combo_number := 0
for die in dice:
if current_combo_number == 0 or not die == current_combo_number:
current_combo_number = die
current_combo_count = 1
elif die == current_combo_number:
current_combo_count += 1
if current_combo_count == 3:
combos.append("three of a kind %s" % die)
detecting straights would be similar
except you only increment the combo count if the current die is one greater than the previous die
I see
maybe there's a more visually pleasing way to write the code? let me see
yeah I put it into my script just created a basic function for it to visualize it better
okay i think this looks better (it also includes straights)
extends Node
func _ready() -> void:
var dice := [1, 2, 2, 3, 4, 5]
dice.sort()
var combos := []
var previous_die := 0
var combo_count := 1
var straight_count := 1
for die in dice:
if die == previous_die:
combo_count += 1
if combo_count == 3:
combos.append("three of a kind %s" % die)
elif die - 1 == previous_die:
combo_count = 1
straight_count += 1
if straight_count == 5:
combos.append("straight five")
else:
combo_count = 1
straight_count = 1
previous_die = die
print(combos)
okay thank you very much! 😊
I managed to use the array I made previously with the script you made and it detected the three of a kind which is great progress
yay
sorry to bother if you could help me with one last thing regarding the ones and fives (totally understand if you don't want to).
ok
I added some lines which add the required amount of points if there is also a one or a five selected but say if its a 3 of a kind of ones instead of giving me only 1000 points it gives me 1,300 because it also runs those few lines of code
the dice shouldnt be able to be scored if they are in a combo I tried to come up with some solutions but wasn't able to fix the issue