Created
May 2, 2020 18:25
-
-
Save sparr/7f98a9cf8e8b1cbd3769c34f8957a0b9 to your computer and use it in GitHub Desktop.
Convert 3d6 to a playing card
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# original idea and base logic from https://www.reddit.com/r/tinycode/comments/gap2jw/6bit_playing_card_deck/ | |
dice_to_card(a,b,y) { | |
suits = {2:'H', 3:'C', 4:'D', 5:'S'} | |
if (y>1 and y<6) { | |
# number cards | |
rank = ceil(a/2) + (ceil(b/2)-1)*3 | |
if rank==1 rank = 10 | |
return rank, suits[y] | |
} | |
elif ((a==1 or a==6) and (b==1 or b==6)) { | |
# jokers | |
if y==1 return 'joker', 'lil' | |
else return 'joker', 'big' | |
} | |
else { | |
# face cards | |
ranks = ['J','Q','K','A'] | |
suitnum = 2 + floor(y/3) + ((a==1 or a==6 or b==1 or b==6)?1:0) | |
return ranks[(a-b)%4], suits[suitnum] | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment