Has anyone ever created a deck of cards?

K.V.
24 Oct 2017, 10:56I was attempting to orchestrate a poker game.
...then I decided to just try for blackjack.
I ended up just trying to create a deck of cards with while
or foreach
.
(Grrr.)
Does anyone have a working script already?
I searched the forum, but I found nothing.
I can figure it out if an example doesn't exist. I just think the idea isn't all that original, so it has probably already been done.
hegemonkhan
24 Oct 2017, 11:54Not really, but there might be card games uploaded/published.
programming card games can be fun, as the programming required isn't too difficult, but still offers some challenge, as you got to be creative and think about how you want to do stuff and to to do the stuff you want.
personally, I'd create an Object for each type of card (?52 cards in a deck?), and for the suit types, you can use an Object Type / Type / Inherited Attribute, as then you can go from there... giving what attributes you want to the cards. Then, I'd create an Object for handling the various actions you want to do: shuffling, etc. Also, have an Object List Attribute with all 52 of your cards as its items, and you might want to have another Object List Attribute, for a 2nd pile of cards for whatever it might be needed for. Lastly, then create another Object (or use the same Object), for handling the game play and all of its actions and etc...
mrangel
24 Oct 2017, 12:06OK ... just wrote ~500 word reply. But "Sorry, you can't post that here." ... huh?

K.V.
24 Oct 2017, 19:52Sorry, you can't post that here.

K.V.
24 Oct 2017, 19:53That certainly does suck, mrangel.
I feel your pain. I hate it when that happens to me, and it's always a LONG post when it happens.

K.V.
24 Oct 2017, 23:48It won't let me post here either!
...but I refuse to accept that CENSORED !

K.V.
25 Oct 2017, 00:26I had a couple of mistakes in there.
Revised:
Here's the code (sorry, I can't post that here):
https://gist.github.com/KVonGit/4b25c9988fa2db117a10330a6fbcf75f#file-carddeck-md

K.V.
25 Oct 2017, 05:35It is okay to post about playing cards, right?
I assume it's blocking the posts because the content is the same as online gambling spam?

K.V.
25 Oct 2017, 07:10pair = false
threeOfAKind = false
straightFlush = false
flush = false
fullHouse = false
fourOfAKind = false
straightFlush = false
royalFlush = false
myCards = NewObjectList()
foreach (card, ScopeInventory()) {
list add (myCards, card)
}
myHand = FilterByType(myCards, "playingCardType")
if (not ListCount(myHand) = 5) {
error ("You don't have the correct amount of cards.")
}
names = NewStringList()
suits = NewStringList()
foreach (crd, myHand) {
list add (names, crd.cardname)
list add (suits, crd.suit)
}
Is there a function to count repeat entries in a list, or should I just foreach
it from here?
hegemonkhan
25 Oct 2017, 11:56no idea... you can always just create your own...
and, is this a built-in Function?: error ("XXX"), or did you mean to do: msg ("Error: XXX"), or did you mean for it to be a VARIABLE: error = "XXX" or error => { msg ("Error: XXX") }
(I'm sure your actual code is correct... just want to point this out... just in case)
mrangel
25 Oct 2017, 12:54Error() is a built-in function. Displays an error message and causes the current function to return immediately.
Unfortunately doesn't break out of the calling function, like it would in most languages.

K.V.
25 Oct 2017, 13:17Error("You can't do that on television!")
Yep, HK. Like mrangel said. I haven't tested it in this instance, but it should throw that error and exit the script.
Always feel free to point things out about my stuff, too. (It won't hurt my feeling.)
Half the reason I post is to share, and the other half is to get some constructive criticism.
https://gist.github.com/KVonGit/4b25c9988fa2db117a10330a6fbcf75f#file-carddeck-md
Since "I can't post that here," I've got the game's code on GitHub.
mrangel
25 Oct 2017, 13:18Is there a function to count repeat entries in a list
I think looking at the loop at the end of your code, I'd make names
and suits
dictionaries-of-objectlists rather than straight stringlists. So like
foreach (crd, myHand) {
if (not DictionaryContains (names, crd.cardname)) {
dictionary add (names, crd.cardname, NewObjectList())
}
list add (DictionaryItem(names, crd.cardname), crd)
if (not DictionaryContains (suits, crd.suit)) {
dictionary add (suits, crd.suit, NewObjectList())
}
list add (DictionaryItem(suits, crd.suit), crd)
}
Then you've got your hand indexed by name and by suit (assuming that cardname is "2", "jack", etc); so you can do:
if (ListCount(suits) = 1) {
flush = true
}
else {
foreach (n, names) {
num = ListCount(DictionaryItem(names, n))
}
if (num = 2) {
pair = true
}
else if (num = 3) {
threeOfAKind = true
}
else if (num = 4) {
fourOfAKind = true
}
}
if (threeOfAKind and pair) {
fullHouse = true
}
straightlength = 0
foreach (name, Split(-your list of all the suits again with A at both ends-)) {
if (DictionaryContains(names, name)) {
straightlength = straightlength + 1
}
else if (straightlength = 5) {
straight = true
if (flush) {
straightFlush = true
}
}
else {
straightlength = 0
}
}
if (straightlength = 5) {
royalFlush = true
}
(I think that's everything?)
mrangel
25 Oct 2017, 13:20Apparently it's the Split(list of numbers with a few strings in)
that's being censored; so I changed that and it let me post.
mrangel
25 Oct 2017, 13:29OK, that's a bit overkill. I was thinking of other games where the acceptable hands can be more complex.
Though it's still probably a simple way to count the number of pairs/threes/fours you've got. In any other language, I'd put names[crd.cardname] ++
so the dictionary contains a count for each different name. But in Quest, you'd have to remove the dictionary item and then add it again, which is a real pain. So making it a list is probably simpler (a list in a dictionary can be modified without having to add it again)
mrangel
25 Oct 2017, 13:48Depending on the game variant, I'd think about making a dictionary of results. So rather than pair = true
, you'd be doing dictionary add (result, "pair", objectlist_of_two_cards)
.
Then to find the winner from two hands, you call that function for each hand, and then iterate over a list "royalFlush;straightFlush;fourOfAKind;..."
or whatever order they come in. If one dictionary contains that element, you declare them the winner and return. If both do, you have two lists of cards that you can look at the values of to determine whose pair is higher.
(I've not played poker in years, and more often played games that are similar but not quite the same scoring; so my appologies if I've made any errors in the rules)

K.V.
25 Oct 2017, 13:52I was thinking about dictionaries...
I think that code is better than what I've got so far:
pair = false
threeOfAKind = false
straightFlush = false
flush = false
fullHouse = false
fourOfAKind = false
straightFlush = false
royalFlush = false
myCards = NewObjectList()
foreach (card, ScopeInventory()) {
list add (myCards, card)
}
myHand = FilterByType(myCards, "playingCardType")
if (not ListCount(myHand) = 5) {
error ("You don't have the correct amount of cards.")
}
names = NewStringList()
suits = NewStringList()
foreach (crd, myHand) {
list add (names, crd.cardname)
list add (suits, crd.suit)
}
combinedNames = ListCompact(names)
msg (combinedNames)
combinedSuits = ListCompact(suits)
if (ListCount(combinedSuits) = 1) {
flush = true
}
msg (combinedSuits)
> i
You are carrying the 2 of Hearts, the 2 of Clubs, the 9 of Hearts, the 9 of Clubs and the 9 of Diamonds.
> hand
List: two; nine;
List: Hearts; Clubs; Diamonds;
I've got to add a dictionary for the values.
Blackjack
J,Q,K = 10
A = 1 or 11
Poker
J = 11
Q = 12
K = 13
A = 1 or 14

K.V.
25 Oct 2017, 13:54Depending on the game variant, I'd think about making a dictionary of results.
Sounds like a good idea.
I could have a dictionary for each game, then have one library for card games. (I think so, anyway.)

K.V.
25 Oct 2017, 14:21I forgot 'five of a kind', but that will be easy. (This is just a reminder for later, when I'm trying to remember that one thing I was supposed to go back and add in.)
I've got THREE Jokers: red, black, and blue. (The blue one is for the German players. (You're welcome, Pertex!)
Inform 7 has an extension for playing cards, if I remember correctly. Maybe I'll go see what they did, too.
I'd like to make a library for everyone with a deck that you can play any game with. (And even two-deck blackjack.)
I'd REALLY like to end up with Dragon Poker, too. Where you have a six-card hand, and it matters what day it is, what time it is, which direction your facing, etc.
https://en.wikipedia.org/wiki/Dragon_Poker
(I love the early Myth Adventures books!)

K.V.
25 Oct 2017, 14:30I need to remember to add values for suits in poker games, too:
Spades
Hearts
Clubs
Diamonds
jmnevil54
25 Oct 2017, 14:32Is Poker like Rock Paper Scissors?
12341234....

K.V.
25 Oct 2017, 14:44https://en.wikipedia.org/wiki/Poker_probability
This may come in handy, too.
Is Poker like Rock Paper Scissors?
No, it's like a thumb war.
1, 2, 3, 4
I declare a thumb war!!!
(You don't want to go thumb to thumb, jmne! My thumb strong like bear! Fast like lightning!)
mrangel
25 Oct 2017, 15:00I think I missed one out.
if (num = 2) {
pair = true
}
should be
if (num = 2) {
if (pair) {
twoPairs = true
}
pair = true
}
Hmm… working out how to use the jokers. I'm guessing that as they don't have a suit, the jokers go into a separate list at the start.
In this case, I'm thinking that a card should probably have an attribute for its order (0-13), separate from its "cardname" or "value"; makes it easier to check for straights. Also gives the benefit that in a lot of cases, you could then have a list of values (quicker to enter).

K.V.
25 Oct 2017, 15:14mrangel,
I have the jokers in the deck from the jump. I was considering making their attributes all 0
. Then use that as wild somehow later.
The order attribute is a very good idea.
It just added a 'high card' check, too. Just in case no one has a pair or better.
This is the Inform 7 script, but it didn't really give me any new ideas:
https://gist.github.com/KVonGit/09329a3b6469cc341757505738d332af#file-tilt-inform-7-txt
mrangel
25 Oct 2017, 15:53I was thinking that if you have a function EvaluateHand(list_of_cards)
based on the script I posted earlier, that returns a dictionary (key is "pair" etc, value is an objectlist of the matching cards), then you'd have:
<function name="DetermineWinner" parameters="handA, handB" type="string">
resultsA = EvaluateHand(handA)
resultsB = EvaluateHand(handB)
dictionary add (resultsA, "nothing", NewObjectList())
dictionary add (resultsB, "nothing", NewObjectList())
foreach (handtype, Split("royalFlush;straightFlush;four;fullHouse;flush;straight;three;twoPair;pair;nothing",";") {
if (DictionaryContains(resultsA, handtype) and DictionaryContains(resultsA, handtype)) {
cardsA = DictionaryItem(resultsA, handtype)
cardsB = DictionaryItem(resultsB, handtype)
for (i, ListCount(cardsA)-1, 0, -1) {
if (ListItem(cardsA, i).value > ListItem(cardsB, i).value) {
return ("A wins")
}
else if (ListItem(cardsA, i).value < ListItem(cardsB, i).value) {
return ("B wins")
}
}
cardsA = ObjectListSortDescending(ListExclude(handA, cardsA), "value")
cardsB = ObjectListSortDescending(ListExclude(handB, cardsB), "value")
for (i, 0, ListCount(cardsA)-1) {
if (ListItem(cardsA, i).value > ListItem(cardsB, i).value) {
return ("A wins")
}
else if (ListItem(cardsA, i).value < ListItem(cardsB, i).value) {
return ("B wins")
}
}
}
else if (DictionaryContains(resultsA, handtype)) {
return ("A wins")
}
else if (DictionaryContains(resultsB, handtype)) {
return ("B wins")
}
}
return ("Tie")
</function>
(So in the case you both have a pair, it checks who has the highest pair, and then if it's still a tie it checks the remaining cards in your hands in descending order, which I think is correct behaviour. In the case of a full house, the list-of-cards should have the pair then the three; and for twoPair you should put the higher pair second, so that it's checked first)

K.V.
25 Oct 2017, 16:00Look at ya' go, mrangel!
I hope you don't mind me saying so, but you're one bad MOFO! (And I mean that in the American, blue-collar good way!)
mrangel
25 Oct 2017, 16:11Thanks :D
Getting that EvaluateHand to behave correctly when there might be jokers in the deck will be interesting :p I think I can see how to do it, though.

K.V.
25 Oct 2017, 16:47I bet we can find an artist to provide the fronts and backs of the cards. So, when you examine them, you get the picture (get the picture?).
Jay gave us some dice already, too:
https://textadventures.co.uk/attachment/722
https://textadventures.co.uk/attachment/723
Then, Pixie already gave us this to make the dice work:
http://docs.textadventures.co.uk/quest/functions/corelibrary/diceroll.html
And I assume a one-armed bandit will be simple, especially with the DiceRoll function. It will be just like the dice, only more of them.
There's a saloon in my spaghetti-western game I'm porting.
Seems like there should be a card game going on, you know?
Plus, it'd be nice for everyone to have a library like this.
I may just steal all of your code, mrangel.
All I'm doing at this point is saying, "hell yeah! This is better!" and pasting it in piece by piece anyway... Same difference.

DarkLizerd
25 Oct 2017, 17:15I've got a Basic game book that has a card game in it...
I'll check out how basis does it, and report back.
hegemonkhan
25 Oct 2017, 17:17ah, okay, I've learned of a new built-in 'error messaging' Function, hehe. Though I still use v550 (but it's before Pixie's updated versions), so not sure if the 'error ()' Function is new, or if it's been there awhile and I never knew of it.

K.V.
25 Oct 2017, 17:42DL,
I like Basic game books AND card games!
And codes!!!
I just remembered the royal flush from Draculaland!
Ha!
Has anyone played that?
mrangel
25 Oct 2017, 19:17The first one I did had a prototype card object for the others to be cloned off; with a changedparent
script that changes its alias to be "six of clubs" or whatever, or "a playing card", depending whether it's in ScopeReachable(). Means that if an NPC opponent's hand is a closed-but-transparent container, you can look at someone to see how many cards they're holding (could be useful in some games), but not what those cards are. You could use an open container or surface to represent an area of the table that has face-up cards in, in which case you can see the cards like in any other container.

K.V.
26 Oct 2017, 00:30mrangel,
Now you're thinking of awesome stuff I would have NEVER thought of. I'd have never come up with. which I would have NEVER thought up!
(Up isn't a preposition there. It's an adverb particle; right?)

DarkLizerd
26 Oct 2017, 02:01In Basic, using Quest code...
I would create a deck() variable... like:
Deck=Split("AS,AH,AD,AC,2S,2H,2D,2C.... ", ",")
then shuffle the deck with a loop
for(B,1,6){ loop 6 times
for(A,0,51){ loop for each card, yes, I could have done this 356 times, but this way, I can control the number of times through the deck, the more the better...
select the A'th card in the deck, copy it to a temp variable, delete it, then add it to the back of the list.
} loop for A
]loop for B
Now the cards are shuffled...
Then draw each card off the top (0 location) add that to player's hand and delete it from the list.
and do the same for each person.
IE: for poker, draw 5 cards each.
then the player's hand would look like:
player.hand("1,3,5,7,9")
but the #1 card would be 4C
#2= 9H
#3=AC
#4=JH
#5=4H
Then by comparing the cards to each other, you could determine pairs, 3 of a kind, 4 of a kind...
Or, if playing 21, the total count for each hand.
(Clear as mud, or do you need "real" code?)

Doctor Agon
26 Oct 2017, 06:31Is the player only using the cards they are first dealt, or are they able to discard cards and get new ones. Normally, you'd get 5 cards and then you can change upto 4.

DarkLizerd
26 Oct 2017, 06:45Yes, dealt off the top in the shuffled sequence...
(Actually, 2 player hands, alternating between the two players.)
Or draw one player's hand then the other... so:
player#1 gets cards 1,2,3,4,5
player#2 gets cards 6,7,8,9,10
Actual game play is up to you...
But if the player hands is in split variables, then the discard is as simple as just deleting the card, then adding it to the "bottom" of the shuffled deck.
and drawing a new card off the "top"...
But I think you get the idea...

Doctor Agon
26 Oct 2017, 08:27oh, so you're not alternating the dealt cards at the start:
player#1 gets cards: 1,3,5,7,9
player #2 gets cards: 2,4,6,8,10
mrangel
26 Oct 2017, 09:42I thought a bit about this earlier (in the first load of code it wouldn't let me post).
If you're playing "fair", there's really no need to shuffle the deck.
deck.dealCard => {
card = PickOneObject(this.cards)
list remove (this.cards, card)
MoveObject (card, destination)
}
On the other hand, if this is a card game in a saloon in a western game, it's entirely feasible your character might know how to cheat. Sneak a look at a few cards, or look what's on the bottom of the deck and have a command to deal off the bottom. Swap a card in your hand with the deck, so you know one of someone else's cards. In that case, you do need to remember the current order of the deck.
So for that case, a perfect shuffle:
deck.shuffle => {
shuffled = NewObjectList()
while (ListCount(this.cards) > 0) {
card = PickOneObject(this.cards)
list remove (this.cards, card)
list add (shuffled, card)
}
this.cards = shuffled
}
Or, of course, you could have some characters who don't know how to shuffle properly. You could build a version of this algorithm that takes 1-5 consecutive cards from the old deck, instead of just one; recognise the sloppy shuffler, and you might be able to make a better guess about what cards the other players have. (If you have a card that was in someone's hand before the shuffle, there's a good chance your opponents have one of the other cards from that hand). I'm not sure if it's worth implementing that degree of realism; but it could be done ^_^
mrangel
26 Oct 2017, 11:59Looking at DarkLizerd's shuffle algorithm ... am I right in thinking that if you went through a fresh deck twice rather than six times, that would leave the deck with all the clubs, then all the diamonds, then all the hearts, then all the spades, with each suit in order?
... no, my mental model is broken. It's only the clubs that are in order after 2 shuffles. Still, if you graph the distribution of red/black cards it makes some pretty patterns.
mrangel
26 Oct 2017, 13:22

DarkLizerd
26 Oct 2017, 17:16mrangel: No, My sort does not swap adjacent cards. It randomly selects 1 of the 52 cards and moves it to the back of the list.
!! OH!!... looking at my shuffle example, all it is doing is moving the top card to the bottom!!! (sorry)
I missed a GetRandomInt() to select a random card to be moved to the bottom of the deck...
Also, I like your card "image idea"...
Your shuffler does the "same" thing, you are just removing a random card and adding it to a new list.
DR Argon, Yes... or no...
The first example was with the cards being dealt alternating between 2 players, in the second one, player 1 gets his cards, then player 2.
The Poker game I have just randomly picks one of the 13 numbers, then 1 of the 4 suits... It doesn't look like there are and safeguards to prevent duplicate cards drawn. For a simple game and few cards used, I don't see where this would be a problem.
jmnevil54
26 Oct 2017, 19:35Mrangel, if I can't highlight and paste it, how can KV use it?
Stupid question.

K.V.
26 Oct 2017, 19:46I'm pretty sure he's rendering those cards via command line somehow...
...but I can still pick a card, any card:
mrangel
26 Oct 2017, 21:39I typed the cards in a reply, but it gave "you can't post that here" again; so I took a screenshot.
jmnevil54
26 Oct 2017, 22:30Oh, figures.

K.V.
27 Oct 2017, 04:58http://textadventures.co.uk/games/view/4t2f3vrome_hqz9jxjnc_a/gambling-hall
You can play craps, but no betting yet.
While testing the rolling of the dice online, I decided that a trip to the casino may be something to consider this evening...

K.V.
27 Oct 2017, 07:37Okay...
I think it may save all sorts of work by changing the way the createDeck
function names the cards.
NOTE: [2-10] is actually those numbers, listed out, and separated by commas.
names = Split("[2-10],Jack,Queen,King,Ace", ",")
suits = Split("Hearts,Clubs,Diamonds,Spades", ",")
foreach (n, names) {
foreach (s, suits) {
if (not IsNumeric(n)) {
card = n[0] +""+ s[0]
nstring = n
}
else {
card = ToString(n) + s[0]
nstring = ToString(n)
}
create (card, "playingCardType")
newcard = (GetObject(card))
MoveObject (newcard, deck)
newcard.take = true
newcard.suit = s
newcard.alias = nstring +" of "+s
if (IsNumeric(n)) {
newcard.value = ToInt(n)
newcard.cardname = ToWords(newcard.value)
}
else {
newcard.cardname = n
switch (n) {
case ("Jack"){
newcard.poker_value = 11
newcard.blackjack_value = 10
}
case("Queen"){
newcard.poker_value = 12
newcard.blackjack_value = 10
}
case("King"){
newcard.poker_value = 13
newcard.blackjack_value = 10
}
case ("Ace") {
newcard.poker_value = 14
newcard.blackjack_value = 11
}
}
}
}
}
This gives me 2H -10H, JH, QH, KH, AH in hearts. (You see the pattern, I'm sure.)
The Jokers shall remain "Joker".
Shouldn't this make functions a little easier and eliminate an attribute or two? Or do I just need a nap?

K.V.
27 Oct 2017, 08:26I can't tell if these are free to use or not:
https://en.wikipedia.org/wiki/Playing_cards_in_Unicode#Playing_cards_deck

K.V.
27 Oct 2017, 08:34I can't figure out how mrangel rendered his cards. (KV wipes a tear from his cheek.)
jmnevil54
27 Oct 2017, 09:53I've never understood the pull/desire of gambling, well, a little, if it's one of those "knock over quarters" machines. But I don't understand why people would spend some $2000 and up at a casino in Las Vegas, or why someone's gambling addiction would be so serious they lost their own house. I did enjoy poker the one time I played it, however.
mrangel
27 Oct 2017, 10:06If you want to do fake ascii-art cards, it might actually be easier making each card a <table>
. A border round the edge is easy, then you give it 5 cells, each the full height of the card. The first has its content vertically aligned to the top, and contains ♥<br/>7
or whatever; the last has its content aligned to the bottom. Then three cells for the actual suits, which have their line-spacing set to (card height÷number of spots in column), and vertically centred.
The ones I typed out in this 'reply' box are a little ugly, because the spots on the 10 aren't arranged right (it would have needed an extra row, meaning that all the others aren't vertically centred). A correct 10 should have 2-1-2-2-1-2 dots per line; same for the 9 (should be 2-1-2-2-0-2)
mrangel
27 Oct 2017, 10:13Just a thought; would it be legal to give an object the alias 🂹, for example? (that's 🂹
) There's a whole deck between 1F0A0 and 1F0DF.
jmnevil54
27 Oct 2017, 10:47+-9------------+
I I
I I
I I
I I
I I
I I
I I
I I
+------------9-+
I wish I was as skilled as those people who make portraits in letters and signs!
THIS WORKS A WHOLE LOT BETTER IN MY ORIGINAL EDIT/TYPING!

K.V.
27 Oct 2017, 10:53would it be legal to give an object the alias 🂹
I just had those posted earlier, but edited them out of the post because I wondered the same thing.
...and what about these? (I'm liking these.)
https://github.com/notpeter/Vector-Playing-Cards
If you want to do fake ascii-art cards...
Cool! Thank you!
I updated the game a little.
You can play the one-armed bandit now.
http://textadventures.co.uk/games/view/4t2f3vrome_hqz9jxjnc_a/gambling-hall

K.V.
27 Oct 2017, 10:58I've never understood the pull/desire of gambling, well, a little, if it's one of those "knock over quarters" machines. But I don't understand why people would spend some $2000 and up at a casino in Las Vegas, or why someone's gambling addiction would be so serious they lost their own house. I did enjoy poker the one time I played it, however.
Some people are crazy.
I live about 20 minutes from the casinos, and I've had to confiscate my friends' ATM and credit cards a few times.
hegemonkhan
28 Oct 2017, 02:16I guess it's the 'thrill of risk takers/taking', in the impossible hope of being lucky, same as with the lottery ticket buying... sighs. A lot of people are risk takers, gambling with their actual-physical lives, so gambling with your indirect (financial) life, is no big deal.
The other aspect involved with risk takers/taking, is the addiction/high of the adrenaline and euphoria (when you don't die/lose, lol) of it as well, that further feeds the risk taker/taking.
Risk Takers are vital to survival, a risk taker can bring back salvation (food/etc) for his family and tribe, whereas non-risk takers, their families, and their tribes, just die off (starve to death/etc). This is why females love risk takers, yes, it's not the greatest odds that they'll survive, but not taking the risk, is even worse odds, of ZERO chance of success/survival. The male is specialized in risk taking, he is made to handle exterior, the physical world, he has to survive and bring back not only food for himself, but his wife, and children (or soon-to-be-birthed/coming-children). He is expected to risk his own life to protect his wife and children, as he is only risking his own life, whereas a female is risking her own life as well as that of her children in her belly/womb. This is what the male-sex specialization is, what we're made as, and thus expected to be, risk takers. We're the protectors and providers, as that's how we're made/built/designed, as the male-sex specialization. Males are specialized to deal with all the exterior threats/issues. The power and genius of specialization, what we call 'the sexes' and of sex, meiosis reproduction, which exploded life upon the world, compared to it's trickle-stagnancy of lack of frequency and extremity of mutation, via cloning, aka mitosis reproduction, prior to the cambrium era, where finally such a mutation, gave us meiosis (sexual) organisms, and the resultant explosion of life, in what we call the cambrium era.
The science of odds is 33%+, humans innately/universally consider 1/3 the minimum for acceptable odds. A 1/3 chance is worth the risk for the acceptable 1/3 odds of the payoff. Though, mathematically/statistically, it should be 50%+, but we consider 33%+ the minimum.
The Pixie
28 Oct 2017, 07:11Though, mathematically/statistically, it should be 50%+, but we consider 33%+ the minimum.
It depends on the outcomes. If you risk losing $1 but stand to gain $11, then a 10% chance is worth taking, mathematically. The "expected" outcome (the average outcome after an infinite number of tries) is $1.1, which is a profit.
The problem is that casinos ensure that that is not the case; the house always wins because the expected outcome is always less.

K.V.
28 Oct 2017, 08:08the house always wins
Pixie, you ain't just whistlin' Dixie!

K.V.
30 Oct 2017, 09:59I'm still working on the poker.
It seems to be coming along, though.
> i
You are carrying a 7 of Hearts, a 7 of Diamonds, a 8 of Spades, an Ace of Hearts, an Ace of Spades and a token.
> hand
PAIR
pokerFunction complete
> i
You are carrying a 6 of Spades, a 7 of Spades, a 8 of Spades, a 9 of Spades, a 10 of Spades and a token.
> hand
FLUSH
pokerFunction complete
> i
You are carrying a 10 of Spades, a Jack of Spades, a Queen of Spades, a King of Spades, an Ace of Spades and a token.
> hand
FLUSH
pokerFunction complete
> i
You are carrying a King of Hearts, a King of Clubs, an Ace of Hearts, an Ace of Clubs and an Ace of Diamonds.
> hand
THREE OF A KIND
pokerFunction complete
pair = false
threeOfAKind = false
straightFlush = false
flush = false
fullHouse = false
fourOfAKind = false
straightFlush = false
royalFlush = false
myCards = NewObjectList()
foreach (card, ScopeInventory()) {
list add (myCards, card)
}
myHand = FilterByType(myCards, "playingCardType")
if (not ListCount(myHand) = 5) {
error ("You don't have the correct amount of cards.")
}
names = NewDictionary()
suits = NewDictionary()
foreach (crd, myHand) {
if (not DictionaryContains (names, crd.cardname)) {
dictionary add (names, crd.cardname, NewObjectList())
}
list add (DictionaryItem(names, crd.cardname), crd)
if (not DictionaryContains (suits, crd.suit)) {
dictionary add (suits, crd.suit, NewObjectList())
}
list add (DictionaryItem(suits, crd.suit), crd)
}
if (ListCount(suits) = 1) {
flush = true
msg ("FLUSH")
}
foreach (n, names) {
num = ListCount(DictionaryItem(names, n))
}
if (num = 2) {
if (pair) {
twoPairs = true
msg ("TWO PAIRS")
}
pair = true
msg ("PAIR")
}
else if (num = 3) {
threeOfAKind = true
msg ("THREE OF A KIND")
}
else if (num = 4) {
fourOfAKind = true
msg ("FOUR OF A KIND")
}
if (threeOfAKind and pair) {
fullHouse = true
msg ("FULL HOUSE")
}
straightlength = 0
foreach (name, Split("Sorry, you can't post that here.")) {
if (DictionaryContains(names, name)) {
straightlength = straightlength + 1
}
else if (straightlength = 5) {
straight = true
msg ("STRAIGHT")
if (flush) {
straightFlush = true
msg ("STRAIGHT FLUSH")
}
}
else {
straightlength = 0
}
}
if (straightlength = 5) {
royalFlush = true
msg ("ROYAL FLUSH")
}
msg ("pokerFunction complete")

K.V.
30 Oct 2017, 10:03Here's my deckLib.xml:
CLICK HERE FOR A LOT OF CODE
<library>
<!--
The Deck of Cards (with 3 Jokers)
-->
<object name="deck">
<inherit name="editor_object" />
<inherit name="container_open" />
<alias>deck of cards</alias>
<feature_container />
<open type="boolean">false</open>
<close type="boolean">false</close>
<hidechildren />
<listchildren />
<take />
<shuffled type="boolean">false</shuffled>
<displayverbs type="stringlist">
<value>Look at</value>
<value>Take</value>
</displayverbs>
<inventoryverbs type="stringlist">
<value>Look at</value>
<value>Drop</value>
</inventoryverbs>
<shuffle type="script"><![CDATA[
shuffledList = NewObjectList()
this.cards = NewObjectList()
foreach (o, GetDirectChildren(this)) {
list add (this.cards, o)
}
while (ListCount(this.cards) > 0) {
card = PickOneObject(this.cards)
list remove (this.cards, card)
list add (shuffledList, card)
}
this.cards = shuffledList
this.shuffled = true
msg ("Done.")
]]></shuffle>
<deal type="script">
dealPokerHand (this, 1, player)
</deal>
<object name="Red Joker">
<inherit name="editor_object" />
<inherit name="playingCardType" />
<alias>Red Joker</alias>
<cardname>Joker</cardname>
<attr name="poker_value" type="int">0</attr>
<attr name="blackjack_value" type="int">0</attr>
</object>
<object name="Black Joker">
<inherit name="editor_object" />
<inherit name="playingCardType" />
<alias>Black Joker</alias>
<cardname>Joker</cardname>
<attr name="poker_value" type="int">0</attr>
<attr name="blackjack_value" type="int">0</attr>
</object>
<object name="Blue Joker">
<inherit name="editor_object" />
<inherit name="playingCardType" />
<alias>Blue Joker</alias>
<cardname>Joker</cardname>
<attr name="poker_value" type="int">0</attr>
<attr name="blackjack_value" type="int">0</attr>
</object>
<object name="2H">
<inherit name="playingCardType" />
<hasbeenmoved />
<take />
<suit>Hearts</suit>
<alias>2 of Hearts</alias>
<attr name="poker_value" type="int">2</attr>
<attr name="blackjack_value" type="int">2</attr>
<cardname>two</cardname>
</object>
<object name="2C">
<inherit name="playingCardType" />
<hasbeenmoved />
<take />
<suit>Clubs</suit>
<alias>2 of Clubs</alias>
<attr name="poker_value" type="int">2</attr>
<attr name="blackjack_value" type="int">2</attr>
<cardname>two</cardname>
</object>
<object name="2D">
<inherit name="playingCardType" />
<hasbeenmoved />
<take />
<suit>Diamonds</suit>
<alias>2 of Diamonds</alias>
<attr name="poker_value" type="int">2</attr>
<attr name="blackjack_value" type="int">2</attr>
<cardname>two</cardname>
</object>
<object name="2S">
<inherit name="playingCardType" />
<hasbeenmoved />
<take />
<suit>Spades</suit>
<alias>2 of Spades</alias>
<attr name="poker_value" type="int">2</attr>
<attr name="blackjack_value" type="int">2</attr>
<cardname>two</cardname>
</object>
<object name="3H">
<inherit name="playingCardType" />
<hasbeenmoved />
<take />
<suit>Hearts</suit>
<alias>3 of Hearts</alias>
<attr name="poker_value" type="int">3</attr>
<attr name="blackjack_value" type="int">3</attr>
<cardname>three</cardname>
</object>
<object name="3C">
<inherit name="playingCardType" />
<hasbeenmoved />
<take />
<suit>Clubs</suit>
<alias>3 of Clubs</alias>
<attr name="poker_value" type="int">3</attr>
<attr name="blackjack_value" type="int">3</attr>
<cardname>three</cardname>
</object>
<object name="3D">
<inherit name="playingCardType" />
<hasbeenmoved />
<take />
<suit>Diamonds</suit>
<alias>3 of Diamonds</alias>
<attr name="poker_value" type="int">3</attr>
<attr name="blackjack_value" type="int">3</attr>
<cardname>three</cardname>
</object>
<object name="3S">
<inherit name="playingCardType" />
<hasbeenmoved />
<take />
<suit>Spades</suit>
<alias>3 of Spades</alias>
<attr name="poker_value" type="int">3</attr>
<attr name="blackjack_value" type="int">3</attr>
<cardname>three</cardname>
</object>
<object name="4H">
<inherit name="playingCardType" />
<hasbeenmoved />
<take />
<suit>Hearts</suit>
<alias>4 of Hearts</alias>
<attr name="poker_value" type="int">4</attr>
<attr name="blackjack_value" type="int">4</attr>
<cardname>four</cardname>
</object>
<object name="4C">
<inherit name="playingCardType" />
<hasbeenmoved />
<take />
<suit>Clubs</suit>
<alias>4 of Clubs</alias>
<attr name="poker_value" type="int">4</attr>
<attr name="blackjack_value" type="int">4</attr>
<cardname>four</cardname>
</object>
<object name="4D">
<inherit name="playingCardType" />
<hasbeenmoved />
<take />
<suit>Diamonds</suit>
<alias>4 of Diamonds</alias>
<attr name="poker_value" type="int">4</attr>
<attr name="blackjack_value" type="int">4</attr>
<cardname>four</cardname>
</object>
<object name="4S">
<inherit name="playingCardType" />
<hasbeenmoved />
<take />
<suit>Spades</suit>
<alias>4 of Spades</alias>
<attr name="poker_value" type="int">4</attr>
<attr name="blackjack_value" type="int">4</attr>
<cardname>four</cardname>
</object>
<object name="5H">
<inherit name="playingCardType" />
<hasbeenmoved />
<take />
<suit>Hearts</suit>
<alias>5 of Hearts</alias>
<attr name="poker_value" type="int">5</attr>
<attr name="blackjack_value" type="int">5</attr>
<cardname>five</cardname>
</object>
<object name="5C">
<inherit name="playingCardType" />
<hasbeenmoved />
<take />
<suit>Clubs</suit>
<alias>5 of Clubs</alias>
<attr name="poker_value" type="int">5</attr>
<attr name="blackjack_value" type="int">5</attr>
<cardname>five</cardname>
</object>
<object name="5D">
<inherit name="playingCardType" />
<hasbeenmoved />
<take />
<suit>Diamonds</suit>
<alias>5 of Diamonds</alias>
<attr name="poker_value" type="int">5</attr>
<attr name="blackjack_value" type="int">5</attr>
<cardname>five</cardname>
</object>
<object name="5S">
<inherit name="playingCardType" />
<hasbeenmoved />
<take />
<suit>Spades</suit>
<alias>5 of Spades</alias>
<attr name="poker_value" type="int">5</attr>
<attr name="blackjack_value" type="int">5</attr>
<cardname>five</cardname>
</object>
<object name="6H">
<inherit name="playingCardType" />
<hasbeenmoved />
<take />
<suit>Hearts</suit>
<alias>6 of Hearts</alias>
<attr name="poker_value" type="int">6</attr>
<attr name="blackjack_value" type="int">6</attr>
<cardname>six</cardname>
</object>
<object name="6C">
<inherit name="playingCardType" />
<hasbeenmoved />
<take />
<suit>Clubs</suit>
<alias>6 of Clubs</alias>
<attr name="poker_value" type="int">6</attr>
<attr name="blackjack_value" type="int">6</attr>
<cardname>six</cardname>
</object>
<object name="6D">
<inherit name="playingCardType" />
<hasbeenmoved />
<take />
<suit>Diamonds</suit>
<alias>6 of Diamonds</alias>
<attr name="poker_value" type="int">6</attr>
<attr name="blackjack_value" type="int">6</attr>
<cardname>six</cardname>
</object>
<object name="6S">
<inherit name="playingCardType" />
<hasbeenmoved />
<take />
<suit>Spades</suit>
<alias>6 of Spades</alias>
<attr name="poker_value" type="int">6</attr>
<attr name="blackjack_value" type="int">6</attr>
<cardname>six</cardname>
</object>
<object name="7H">
<inherit name="playingCardType" />
<hasbeenmoved />
<take />
<suit>Hearts</suit>
<alias>7 of Hearts</alias>
<attr name="poker_value" type="int">7</attr>
<attr name="blackjack_value" type="int">7</attr>
<cardname>seven</cardname>
</object>
<object name="7C">
<inherit name="playingCardType" />
<hasbeenmoved />
<take />
<suit>Clubs</suit>
<alias>7 of Clubs</alias>
<attr name="poker_value" type="int">7</attr>
<attr name="blackjack_value" type="int">7</attr>
<cardname>seven</cardname>
</object>
<object name="7D">
<inherit name="playingCardType" />
<hasbeenmoved />
<take />
<suit>Diamonds</suit>
<alias>7 of Diamonds</alias>
<attr name="poker_value" type="int">7</attr>
<attr name="blackjack_value" type="int">7</attr>
<cardname>seven</cardname>
</object>
<object name="7S">
<inherit name="playingCardType" />
<hasbeenmoved />
<take />
<suit>Spades</suit>
<alias>7 of Spades</alias>
<attr name="poker_value" type="int">7</attr>
<attr name="blackjack_value" type="int">7</attr>
<cardname>seven</cardname>
</object>
<object name="8H">
<inherit name="playingCardType" />
<hasbeenmoved />
<take />
<suit>Hearts</suit>
<alias>8 of Hearts</alias>
<attr name="poker_value" type="int">8</attr>
<attr name="blackjack_value" type="int">8</attr>
<cardname>eight</cardname>
</object>
<object name="8C">
<inherit name="playingCardType" />
<hasbeenmoved />
<take />
<suit>Clubs</suit>
<alias>8 of Clubs</alias>
<attr name="poker_value" type="int">8</attr>
<attr name="blackjack_value" type="int">8</attr>
<cardname>eight</cardname>
</object>
<object name="8D">
<inherit name="playingCardType" />
<hasbeenmoved />
<take />
<suit>Diamonds</suit>
<alias>8 of Diamonds</alias>
<attr name="poker_value" type="int">8</attr>
<attr name="blackjack_value" type="int">8</attr>
<cardname>eight</cardname>
</object>
<object name="8S">
<inherit name="playingCardType" />
<hasbeenmoved />
<take />
<suit>Spades</suit>
<alias>8 of Spades</alias>
<attr name="poker_value" type="int">8</attr>
<attr name="blackjack_value" type="int">8</attr>
<cardname>eight</cardname>
</object>
<object name="9H">
<inherit name="playingCardType" />
<hasbeenmoved />
<take />
<suit>Hearts</suit>
<alias>9 of Hearts</alias>
<attr name="poker_value" type="int">9</attr>
<attr name="blackjack_value" type="int">9</attr>
<cardname>nine</cardname>
</object>
<object name="9C">
<inherit name="playingCardType" />
<hasbeenmoved />
<take />
<suit>Clubs</suit>
<alias>9 of Clubs</alias>
<attr name="poker_value" type="int">9</attr>
<attr name="blackjack_value" type="int">9</attr>
<cardname>nine</cardname>
</object>
<object name="9D">
<inherit name="playingCardType" />
<hasbeenmoved />
<take />
<suit>Diamonds</suit>
<alias>9 of Diamonds</alias>
<attr name="poker_value" type="int">9</attr>
<attr name="blackjack_value" type="int">9</attr>
<cardname>nine</cardname>
</object>
<object name="9S">
<inherit name="playingCardType" />
<hasbeenmoved />
<take />
<suit>Spades</suit>
<alias>9 of Spades</alias>
<attr name="poker_value" type="int">9</attr>
<attr name="blackjack_value" type="int">9</attr>
<cardname>nine</cardname>
</object>
<object name="TH">
<inherit name="playingCardType" />
<hasbeenmoved />
<take />
<suit>Hearts</suit>
<alias>10 of Hearts</alias>
<attr name="poker_value" type="int">10</attr>
<attr name="blackjack_value" type="int">10</attr>
<cardname>ten</cardname>
</object>
<object name="TC">
<inherit name="playingCardType" />
<hasbeenmoved />
<take />
<suit>Clubs</suit>
<alias>10 of Clubs</alias>
<attr name="poker_value" type="int">10</attr>
<attr name="blackjack_value" type="int">10</attr>
<cardname>ten</cardname>
</object>
<object name="TD">
<inherit name="playingCardType" />
<hasbeenmoved />
<take />
<suit>Diamonds</suit>
<alias>10 of Diamonds</alias>
<attr name="poker_value" type="int">10</attr>
<attr name="blackjack_value" type="int">10</attr>
<cardname>ten</cardname>
</object>
<object name="TS">
<inherit name="playingCardType" />
<hasbeenmoved />
<take />
<suit>Spades</suit>
<alias>10 of Spades</alias>
<attr name="poker_value" type="int">10</attr>
<attr name="blackjack_value" type="int">10</attr>
<cardname>ten</cardname>
</object>
<object name="JH">
<inherit name="playingCardType" />
<hasbeenmoved />
<take />
<suit>Hearts</suit>
<alias>Jack of Hearts</alias>
<cardname>Jack</cardname>
<attr name="poker_value" type="int">11</attr>
<attr name="blackjack_value" type="int">10</attr>
</object>
<object name="JC">
<inherit name="playingCardType" />
<hasbeenmoved />
<take />
<suit>Clubs</suit>
<alias>Jack of Clubs</alias>
<cardname>Jack</cardname>
<attr name="poker_value" type="int">11</attr>
<attr name="blackjack_value" type="int">10</attr>
</object>
<object name="JD">
<inherit name="playingCardType" />
<hasbeenmoved />
<take />
<suit>Diamonds</suit>
<alias>Jack of Diamonds</alias>
<cardname>Jack</cardname>
<attr name="poker_value" type="int">11</attr>
<attr name="blackjack_value" type="int">10</attr>
</object>
<object name="JS">
<inherit name="playingCardType" />
<hasbeenmoved />
<take />
<suit>Spades</suit>
<alias>Jack of Spades</alias>
<cardname>Jack</cardname>
<attr name="poker_value" type="int">11</attr>
<attr name="blackjack_value" type="int">10</attr>
</object>
<object name="QH">
<inherit name="playingCardType" />
<hasbeenmoved />
<take />
<suit>Hearts</suit>
<alias>Queen of Hearts</alias>
<cardname>Queen</cardname>
<attr name="poker_value" type="int">12</attr>
<attr name="blackjack_value" type="int">10</attr>
</object>
<object name="QC">
<inherit name="playingCardType" />
<hasbeenmoved />
<take />
<suit>Clubs</suit>
<alias>Queen of Clubs</alias>
<cardname>Queen</cardname>
<attr name="poker_value" type="int">12</attr>
<attr name="blackjack_value" type="int">10</attr>
</object>
<object name="QD">
<inherit name="playingCardType" />
<hasbeenmoved />
<take />
<suit>Diamonds</suit>
<alias>Queen of Diamonds</alias>
<cardname>Queen</cardname>
<attr name="poker_value" type="int">12</attr>
<attr name="blackjack_value" type="int">10</attr>
</object>
<object name="QS">
<inherit name="playingCardType" />
<hasbeenmoved />
<take />
<suit>Spades</suit>
<alias>Queen of Spades</alias>
<cardname>Queen</cardname>
<attr name="poker_value" type="int">12</attr>
<attr name="blackjack_value" type="int">10</attr>
</object>
<object name="KH">
<inherit name="playingCardType" />
<hasbeenmoved />
<take />
<suit>Hearts</suit>
<alias>King of Hearts</alias>
<cardname>King</cardname>
<attr name="poker_value" type="int">13</attr>
<attr name="blackjack_value" type="int">10</attr>
</object>
<object name="KC">
<inherit name="playingCardType" />
<hasbeenmoved />
<take />
<suit>Clubs</suit>
<alias>King of Clubs</alias>
<cardname>King</cardname>
<attr name="poker_value" type="int">13</attr>
<attr name="blackjack_value" type="int">10</attr>
</object>
<object name="KD">
<inherit name="playingCardType" />
<hasbeenmoved />
<take />
<suit>Diamonds</suit>
<alias>King of Diamonds</alias>
<cardname>King</cardname>
<attr name="poker_value" type="int">13</attr>
<attr name="blackjack_value" type="int">10</attr>
</object>
<object name="KS">
<inherit name="playingCardType" />
<hasbeenmoved />
<take />
<suit>Spades</suit>
<alias>King of Spades</alias>
<cardname>King</cardname>
<attr name="poker_value" type="int">13</attr>
<attr name="blackjack_value" type="int">10</attr>
</object>
<object name="AH">
<inherit name="playingCardType" />
<hasbeenmoved />
<take />
<suit>Hearts</suit>
<alias>Ace of Hearts</alias>
<cardname>Ace</cardname>
<attr name="poker_value" type="int">14</attr>
<attr name="blackjack_value" type="int">11</attr>
</object>
<object name="AC">
<inherit name="playingCardType" />
<hasbeenmoved />
<take />
<suit>Clubs</suit>
<alias>Ace of Clubs</alias>
<cardname>Ace</cardname>
<attr name="poker_value" type="int">14</attr>
<attr name="blackjack_value" type="int">11</attr>
</object>
<object name="AD">
<inherit name="playingCardType" />
<hasbeenmoved />
<take />
<suit>Diamonds</suit>
<alias>Ace of Diamonds</alias>
<cardname>Ace</cardname>
<attr name="poker_value" type="int">14</attr>
<attr name="blackjack_value" type="int">11</attr>
</object>
<object name="AS">
<inherit name="playingCardType" />
<hasbeenmoved />
<take />
<suit>Spades</suit>
<alias>Ace of Spades</alias>
<cardname>Ace</cardname>
<attr name="poker_value" type="int">14</attr>
<attr name="blackjack_value" type="int">11</attr>
</object>
</object>
</library>
mrangel
30 Oct 2017, 11:22

K.V.
30 Oct 2017, 11:37Yes, sirree.
Wait...
See that?
I have "2" through "10", not "two" through "ten".
Ha!
Be right back...

K.V.
30 Oct 2017, 11:46> i
You are carrying a 2 of Hearts, a 3 of Clubs, a 4 of Diamonds, a 5 of Spades and a 6 of Clubs.
> hand
STRAIGHT
STRAIGHT
STRAIGHT
STRAIGHT
STRAIGHT
STRAIGHT
STRAIGHT
STRAIGHT
ROYAL FLUSH
pokerFunction complete
> i
You are carrying a 4 of Hearts, a 4 of Clubs, a 8 of Spades, a 9 of Diamonds and a King of Diamonds.
> hand
pokerFunction complete
> i
You are carrying a 4 of Hearts, a 4 of Clubs, a 4 of Spades, a 8 of Spades and a King of Diamonds.
> hand
pokerFunction complete
Now, lookie there...
I've probably messed up something else simple, too.
Maybe I'll have the straight check the card's poker_value...

K.V.
30 Oct 2017, 12:09I think I can redo it where it only checks for poker_value
and suit
.
2 = 2
...
j = 11
q = 12
k = 13
a = 14
joker = 0
I think I fixed the FLUSH:
if (ListCount(DictionaryItem(suits, crd.suit)) = 5) {
flush = true
msg ("FLUSH")
}
It was:
if (ListCount(suits) = 1) {
flush = true
msg ("FLUSH")
}

K.V.
30 Oct 2017, 12:33> i
You are carrying a 6 of Hearts, a 7 of Hearts, a 8 of Hearts, a 9 of Hearts and a 10 of Hearts.
> hand
List: Object: 6H; Object: 7H; Object: 8H; Object: 9H; Object: TH;
FLUSH
Dictionary: 6 = List: Object: 6H; ;7 = List: Object: 7H; ;8 = List: Object: 8H; ;9 = List: Object: 9H; ;10 = List: Object: TH;
pair = false
threeOfAKind = false
straightFlush = false
flush = false
fullHouse = false
fourOfAKind = false
straightFlush = false
royalFlush = false
myCards = NewObjectList()
foreach (card, ScopeInventory()) {
list add (myCards, card)
}
myHand = FilterByType(myCards, "playingCardType")
if (not ListCount(myHand) = 5) {
error ("You don't have the correct amount of cards.")
}
names = NewDictionary()
suits = NewDictionary()
foreach (crd, myHand) {
x = ToString(crd.poker_value)
if (not DictionaryContains (names, x)) {
dictionary add (names, x, NewObjectList())
}
list add (DictionaryItem(names, x), crd)
if (not DictionaryContains (suits, crd.suit)) {
dictionary add (suits, crd.suit, NewObjectList())
}
list add (DictionaryItem(suits, crd.suit), crd)
}
msg (DictionaryItem(suits, crd.suit))
if (ListCount(DictionaryItem(suits, crd.suit)) = 5) {
flush = true
msg ("FLUSH")
}
foreach (n, names) {
num = ListCount(DictionaryItem(names, n))
}
if (num = 2) {
if (pair) {
twoPairs = true
msg ("TWO PAIRS")
}
pair = true
msg ("PAIR")
}
else if (num = 3) {
threeOfAKind = true
msg ("THREE OF A KIND")
}
else if (num = 4) {
fourOfAKind = true
msg ("FOUR OF A KIND")
}
if (threeOfAKind and pair) {
fullHouse = true
msg ("FULL HOUSE")
}
straightlength = 0
foreach (name, Split(see below)) {
if (DictionaryContains(names, name)) {
straightlength = straightlength + 1
}
if (straightlength = 5) {
straight = true
msg ("STRAIGHT")
if (flush) {
straightFlush = true
msg ("STRAIGHT FLUSH")
}
}
else {
straightlength = 0
msg (names)
}
}
if (straightlength = 5) {
if (flush) {
royalFlush = true
msg ("ROYAL FLUSH")
}
}
msg ("pokerFunction complete")
Here's my Split "14,2,3,4,5,6,7,8,9,10,11,12,13,14", ","
mrangel
30 Oct 2017, 13:42In the straight loop, you need to set the straightlength back to 0 after printing "STRAIGHT" so that it doesn't trigger the royal flush check as well.
mrangel
30 Oct 2017, 13:46(Edited for silly mistakes)
(another edit for a misplaced paste)
What was wrong with the flush? It worked in your previous example. I noticed only after I posted it that I had carelessly done ListCount(some_dictionary)
; but when your output looked right, I assumed maybe that's legal.
I'll need to look into that again.
(is there really not any function to find the size of a dictionary?)
Here's my first attempt (not properly tested) to make it behave almost right with jokers wild.
<function name="EvaluateHand" parameters="cards" type="dictionary">
if (TypeOf(cards) = "object") {
cards = GetDirectChildren(cards)
}
if (TypeOf(cards) = "objectlist") {
cards = FilterByType(cards, "playingCardType")
}
else {
Error ("That's not an objectlist!")
}
result = NewDictionary()
names = NewDictionary()
suits = NewDictionary()
jokers = NewObjectList()
foreach (crd, cards) {
if (crd.cardname = "Joker") {
crd.poker_value = 0
list add (jokers, crd) {
}
else {
if (not DictionaryContains (names, crd.cardname)) {
dictionary add (names, crd.cardname, NewObjectList())
}
list add (DictionaryItem(names, crd.cardname), crd)
if (not DictionaryContains (suits, crd.suit)) {
dictionary add (suits, crd.suit, NewObjectList())
}
list add (DictionaryItem(suits, crd.suit), crd)
}
}
if (ListCount(suits) = 1) {
foreach (suit, suits) {
switch (suit) {
case ("spades", "clubs") {
if (not ListContains(cards, Red Joker)) {
dictionary add (result, "flush", ObjectListSort(cards, "poker_value"))
msg ("FLUSH")
}
}
case ("diamonds", "hearts") {
if (not ListContains(cards, Red Joker)) {
dictionary add (result, "flush", ObjectListSort(cards, "poker_value"))
msg ("FLUSH")
}
}
}
}
}
foreach (n, names) {
num = ListCount(DictionaryItem(names, n))
if (num = 2) {
if (DictionaryContains(result, "pair")) {
dictionary add (result, "twoPair", ObjectListSort(DictionaryItem(result, "pair") + DictionaryItem(names, n), "poker_value"))
msg ("TWO PAIRS")
}
else {
dictionary add (result, "pair", DictionaryItem(names, n))
msg ("PAIR")
}
}
else if (num = 3) {
dictionary add (result, "three", DictionaryItem(names, n))
msg ("THREE OF A KIND")
}
else if (num = 4) {
dictionary add (result, "four", DictionaryItem(names, n))
msg ("FOUR OF A KIND")
}
}
if (DictionaryContains(result, "three") and DictionaryContains(result, "pair")) {
dictionary add (result, "twoPair", DictionaryItem(result, "pair") + DictionaryItem(result, "three"))
msg ("FULL HOUSE")
}
foreach (j, jokers) {
if (ListCount(result) = 0) {
// 4 different cards and a joker can be a pair, right?
halfpair = NewObjectList()
list add (halfpair, ListItem (cards, ListCount(cards)-1))
dictionary add (result, "halfPair", halfpair)
}
resultTypes = Split("fullHouse;twoPair;WTF;five;four;three;pair;halfPair")
for (i, 1, ListCount(resultTypes)-1) {
if (DictionaryContains (result, ListItem(resultTypes, i))) {
if ((DictionaryContains (result, ListItem(resultTypes, i-1))) {
Error ("How can we have both a "+ListItem(resultTypes, i)+" and a "+ListItem(resultTypes, i-1)+"?")
}
changing = DictionaryItem (result, ListItem(resultTypes, i))
// I'm temporarily assigning the joker a value, which I think works?
// otherwise we'd have to mess around putting the joker at the beginning
// of the lists in result, which would be a pain.
j.poker_value = ListItem(changing, ListCount(changing)-1).poker_value
list add (changing, j)
dictionary remove (result, ListItem(resultTypes, i))
dictionary add (result, ListItem(resultTypes, i-1), changing)
msg (GetDisplayName(j)+": CHANGING "+ListItem(resultTypes, i)+" TO "+ListItem(resultTypes, i-1))
}
}
}
straight = NewObjectList()
// The "END" at the end is to make finding a royal flush easier
straightlist = Split("Cant post that here - list which includes cardnames of all valid straights;END", ";")
usejokers = false
for (i, 0, ListCount(straightlist)-1) {
name = ListItem (straightlist, i)
if (i + ListCount(cards) = ListCount(straightlist) - 1) {
usejokers = true
}
if (DictionaryContains(names, name)) {
list add (straight, ListItem(DictionaryItem(names, name), 0))
usejokers = true
}
else if (usejokers and (ListCount(jokers) > 0)) {
j = ListItem(jokers, 0)
list remove (jokers, j)
j.poker_value = i + 1
list add (straight, j)
}
else {
if (ListCount(straight) >= 5) {
if (ListContains(result, "flush")) {
if (name = "END") {
dictionary add (result, "royalFlush", straight)
msg ("ROYAL FLUSH")
}
else {
dictionary add (result, "straightFlush", straight)
msg ("STRAIGHT FLUSH")
}
}
else {
dictionary add (result, "straight", straight)
msg ("STRAIGHT")
}
}
straight = NewObjectList()
}
}
return (result)
</function>

K.V.
30 Oct 2017, 13:58The flush works. (It's just hidden between two object lists' output.)
I flipped to Arch Linux for a bit, but I'll be back in Windows shortly. Once I am, I'll check it out with your Joker addition.
In the end, I want the player to be able to enter THREES ARE WILD, or whatever they choose. I figure that will be smooth sailing though, once the Jokers work. The wild cards can just have their value switched to 0 somewhere in the script, and they'd be treated just like Jokers. (I'm thinking this may be true, anyway.)

K.V.
30 Oct 2017, 14:18>I noticed only after I posted it that I had carelessly done ListCount(some_dictionary); but when your output looked right, I assumed maybe that's legal.
I fixed that one.
http://textadventures.co.uk/forum/quest/topic/qj5flx_bmkwusr-jhiybcw/has-anyone-ever-created-a-deck-of-cards#94edfc82-916a-4c8b-9fb5-dfcb75d5f509
mrangel
30 Oct 2017, 14:26I think I fixed the FLUSH:
Your fix would break the joker version.
When did you fix it? Because it appeared to work in the first set of results you posted, but not the second.
I'm on mobile now, so it's hard to test if using ListCount() on a dictionary is legal. If not, given that I used it a few times, I think it would be simpler to throw together a DictionaryCount() function than to rearrange the logic.
In the end, I want the player to be able to enter THREES ARE WILD, or whatever they choose.
I think I'm working my head around a way to do that; that would work with wild cards, half-wild, or bugs; as well as having flags to allow wrap-around straights.
(In my original code, you could allow a wrap-around by adding JQK to the beginning of that censored list. But that currently breaks the joker again. I see another way to do it, though)

K.V.
30 Oct 2017, 14:33When did you fix it? Because it appeared to work in the first set of results you posted, but not the second.
The last time I fooled with it.
http://textadventures.co.uk/forum/quest/topic/qj5flx_bmkwusr-jhiybcw/has-anyone-ever-created-a-deck-of-cards#e7b511c6-4cac-439d-9d2b-32f9a73c0dc3
I think it worked when I had the string list setup in the beginning, then I switched to the dictionary method (which I entered incorrectly), and the flush quit working.
Honestly, there's no telling what I'd done. I've changed things so many times...
I'm about to put this on GitHub so I can see my previous versions. (Hehehe. I'm old. I used to remember EVERYTHING. Now, not so much.)

K.V.
30 Oct 2017, 14:35I wonder if the player should be prompted to choose what a Joker is...
mrangel
30 Oct 2017, 14:49I just checked with a couple of test cases; ListCount() works fine on a dictionary, so if (ListCount(suits) = 1) {
should work fine to test for a flush.
That's worth knowing :D
hegemonkhan
30 Oct 2017, 16:16there's also 'DictionaryCount(DICT)' too... but that's interesting that 'ListCount()' works on dictionaries, lol