0 votes

i want to make a turn base card game,suppose there are four players, each player gets 13 random cards without repeating, i can program in python,

import random
cards = ['club1' , 'club2',  'club3',  'club4', 'club5', 'club6','club7','club8','club9','club10' ,'club11','club12','club13','heart1', 'heart2', 'heart3',  'heart4', 'heart5', 'heart6', 'heart7',  
'heart8', 'heart9','heart10',  'heart11', 'heart12','heart13',  'diamond1','diamond2','diamond3', 'diamond4', 'diamond5','diamond6', 'diamond7','diamond8','diamond9','diamond10','diamond11',  'diamond12', 'diamond13', 'spades1','spades2', 'spades3', 'spades4', 'spades5', 'spades6', 'spades7', 'spades8', 'spades9','spades10','spades11', 'spades12', 'spades13' ]


num_to_selects = 13
player1 = random.sample(cards,num_to_selects)



remainingcardsset1 = list(set(cards)-set(player1))

player2 = random.sample(remainingcardsset1,num_to_selects)
remainingcardsset2 = list(set(remainingcardsset1)-set(player2))
player3 = random.sample(remainingcardsset2,num_to_selects)
player4 = list(set(remainingcardsset2)-set(player3))

print (player1)
print("\n")
print(player2)
print("\n")
print(player3)
print("\n")
print(player4)

i am new to gdscript, i tried with set method, but set not working in gdscript, how to allocate 13 cards to each player without repeating?

in Engine by (12 points)
reshown by

1 Answer

0 votes

Check out this answer.

by (10,465 points)

That answer did not return remaining cards list,

That answer did not return remaining cards list,

Yes it did? The last snippet maintains two disjoint sets cards and picked_cards. Actually the only comments under that answer are precisely about your problem...

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.