PDA

View Full Version : optimal11.ash



Dractyl
12-17-2009, 09:30 AM
Optimal11 by dractyl (#1889124)
Inspiring thread: http://forums.kingdomofloathing.com:8080/vb/showthread.php?t=178758

I basically wanted to have script that would automate the desperate scramble for crimbux using the good information developed in the above mentioned thread.

This is my first ash script, so I'm sure I've done a ton wrong. That said, I've been programming a long time, so you should find it well commented and easy to follow. It's based on a lookup table, so the main routines are very clean.


Sample output:



Visiting the Crimbo Cartel in Crimbo Town
Round 1 of 3

[3304] Crimbo 11 Table
You bet 11 Crimbux
Opponent has 2 (2). You have 42 (6).
Doubling down...
You bet an additional 11 Crimbux
You acquire Crimbuck (44)
Opponent has 3225 (12). You have 423 (9).
You won! :D
You have won 22 delicious crimbux over 1 rounds (22.0 per adv.)

Round 2 of 3

[3305] Crimbo 11 Table
You bet 11 Crimbux
Opponent has 3 (3). You have k4 (9).
Standing...
Opponent has 33k (11). You have k4 (9).
You lost. :(
You have won 11 delicious crimbux over 2 rounds (5.5 per adv.)

Round 3 of 3

[3306] Crimbo 11 Table
You bet 11 Crimbux
You acquire Crimbuck (55)
Opponent has 2 (2). You have ka (11).
You won! :D
You have won 55 delicious crimbux over 3 rounds (18.33 per adv.)

--- Final statistics ---
Rounds: 3

Rounds Won: 2 (66.67%)
- by natural 11: 1 (33.33%)
- by double down: 1 (33.33%)

Rounds Lost: 1 (33.33%)
- by double down: 0 (0.0%)

Rounds Drawn: 0 (0.0%)
- by double down: 0 (0.0%)

Starting Crimbux: 7660
Crimbux won: 55
Crimbux/adv: 18.33
Ending Crimbux: 7715

Script completed.



Note:
- Auxiliary routines (basically 6 lines) stolen from Alhifar (#1189456) and RoyalTonberry (#1161513)
- If there is an issue there, I will happily rewrite them
- Strategy unabashedly lifted from "empty inferences" spading


Enjoy!

--

The current version is 4.1

Change log

New in 2.0:
- Corrected a cosmetic problem where doubledown was falsely declared
- Added improved statistics
- Corrected bug where the program would fail if the user did not specify the number of rounds
- Cleaned up code
- Cleaned up output
- Added detection for insufficient crimbux at the start and during each round


New in 3.0 - contribution by mysyzygy
- Re-ordered entries in the actions map so they're in the same order as the optimal play table in the wiki (http://kol.coldfront.net/thekolwiki/index.php/The_Crimbo_11_Table) and are easier to proofread
- Added missing 1334 entry when dealer has Ace
- Added missing 1113 entry when dealer has Ace


New in 4.0
- Minor code refactoring
- Added crimbux/adv to final output
- Detects insufficient funds when doubling down
- Added Bale-style round syntax (-40 means "use all but 40 rounds")
- Counts card totals

4.1 was released under the same name as v4, correcting a bug where totals were incorrectly calculated under some conditions. Hand totals are only used for display purposes so this is strictly a cosmetic bug. Six people downloaded the affected version.

Bale
12-17-2009, 09:51 AM
Good work.


This is my first ash script, so I'm sure I've done a ton wrong. Shouganai, ne.
You may learn something about alternate solutions to your scripting issues if you check out this thread (http://kolmafia.us/showthread.php?t=3114). Several other people have posted their own variants of this script there.

Dractyl
12-19-2009, 01:34 AM
I've made an update to my script. It's had a few more days of testing. It works fine in terms of the actual gameplay and acquisition of Crimbux, but there were some cosmetic issues and some corner cases that have been fixed up.

New since 1.0:
- Corrected a cosmetic problem where doubledown was falsely declared
- Added improved statistics
- Corrected bug where the program would fail if the user did not specify the number of rounds
- Cleaned up code
- Cleaned up output
- Added detection for insufficient crimbux at the start and during each round


Todo:
- Add Bale-style round specification (-40 to mean "all but 40 turns")
- Count up the card totals or extract from page
- Add crimbux/adv to final stats (printed for each hand, but not at the end)
- Check if there are enough crimbux to double the bet and if not, hit instead


Here is an example of new final stats:


Rounds: 127

Rounds Won: 53 (41.73%)
- by natural 11: 15 (11.81%)
- by double down: 3 (2.36%)

Rounds Lost: 46 (36.22%)
- by double down: 1 (0.79%)

Rounds Drawn: 28 (22.05%)
- by double down: 0 (0.0%)

Starting Crimbux: 6253
Crimbux won: 594
Ending Crimbux: 6847


Dractyl

fewyn
12-19-2009, 03:48 AM
You have won 990 delicious crimbux over 233 rounds (4.25 per adv.)
--- Final statistics ---
Rounds: 233

Rounds Won: 107 (45.92%)
- by natural 11: 24 (10.3%)
- by double down: 9 (3.86%)

Rounds Lost: 95 (40.77%)
- by double down: 3 (1.29%)

Rounds Drawn: 31 (13.3%)
- by double down: 1 (0.43%)

Starting Crimbux: 7945
Crimbux won: 990
Ending Crimbux: 8935

Hot stuff :) Thanks

mysyzygy
12-20-2009, 12:02 AM
This is my favorite script 11 tables script because its by far the easiest to verify the code. I'm uploading a new version where I re-ordered entries
in the actions map so they're in the same order as the optimal play table in the wiki which makes the script easier to proofread.
http://kol.coldfront.net/thekolwiki/index.php/The_Crimbo_11_Table

I found two differences with the wiki although I don't think either of them are mistakes.

1) The following line was missing for the condition where the dealer has an ace and the player has A334. Since A334 is an 11 I don't think this entry needs to be there but the code lists lots of other soft elevens so I added it anyway.
actions [ '1' , '1334' ] = 1;

2) Another difference: When the dealer has 5 and the player has A224, the wiki says to stand and the script says to hit. Since the other 3 similar cases say to hit, I think the wiki is wrong.
actions [ '5' , '1224' ] = 2;

My version of the script doesn't fix any problems or add new features, it just makes it easier to verify that the right logic is being used.

Unfortunately, now that I finally have a script that I'm confident is working correctly, I think I'll stop playing elevens and switch to slots. I think theoretically 11's should pay better but I've played hundreds of turns with 3 characters for a few days and I've pretty crappy averages. The first time I played I got over 6 bux per turn but since then I haven't had any sessions over 4/turn and most have been under 3.

Happy Crimbo!

StorellaDeville
12-20-2009, 03:15 AM
I ran optimal11v2.ash for 200 adventures. It took less than 10 minutes (maybe less than 5; I was in a hurry before rollover!) and gave this output:

Starting Crimbux: 4899
Crimbux won: 1089
Ending Crimbux: 5988

So that's a little more than 5 Crimbux per adventure. Did it bet 11 every time because that's what I had last bet? Maybe if I read it I'll see the answer within. Anyway, thank you very much for my first ASH script! I really needed to use those 200 turns!

morgad
12-20-2009, 09:45 AM
I got about 3 to 5 bux a turn using this :-)
perfect to burn up turns after penguin farming

tnx
Dave

Ethelred
12-20-2009, 10:45 PM
I encountered aa3a while the dealer was showing a and the script when into a loop. Stopped the script and hit stand (because I saw it was 11) and the dealer also had 11, so it was a push. Only then did I realize I could have hit for a 5 card wind. :-( Oh, well, that's life. I didn't look at the tables, but maybe an entry is missing?

StorellaDeville
12-21-2009, 06:29 AM
I have seen v2 stand on an 8 (a34), and v3 take a hit on a 9 (which made me bust). Is there anything I can do to help?

adeyke
12-21-2009, 07:40 AM
I have seen v2 stand on an 8 (a34), and v3 take a hit on a 9 (which made me bust). Is there anything I can do to help?

Standing on A34 is optimal if the dealer has 2 or 3, and hitting on a 9 is optimal in all soft hands and some hards hands. So the information you've given is consistent with optimal play and doesn't indicate a problem.

Spiny
12-21-2009, 08:55 AM
Standing on A34 is optimal if the dealer has 2 or 3, and hitting on a 9 is optimal in all hard hands and some soft hands. So the information you've given is consistent with optimal play and doesn't indicate a problem.

Um, hitting on soft 9 is optimal and on some hard 9 hands you mean?
http://85.234.150.79/~mark/eleven.parsed.html

Dractyl
12-21-2009, 03:15 PM
Hi everyone,

I've released version 4. Instead of placing the file here, I put it back in the original post (at the beginning of this thread) so new downloaders won't have to go searching for it. Please download from there.

Dractyl

--

New in 4.0
- Minor code refactoring
- Added crimbux/adv to final output
- Detects insufficient funds when doubling down
- Added Bale-style round syntax (-40 means "use all but 40 rounds")
- Counts card totals

Dractyl
12-21-2009, 03:25 PM
I encountered aa3a while the dealer was showing a and the script when into a loop. Stopped the script and hit stand (because I saw it was 11) and the dealer also had 11, so it was a push. Only then did I realize I could have hit for a 5 card wind. :-( Oh, well, that's life. I didn't look at the tables, but maybe an entry is missing?

There was an entry missing. mysyzygy caught it when he made version 3. Download the latest and you should be ok.



I have seen v2 stand on an 8 (a34), and v3 take a hit on a 9 (which made me bust). Is there anything I can do to help?

Please check your result against the table located here (http://kol.coldfront.net/thekolwiki/index.php/The_Crimbo_11_Table). If there is a discrepancy, let me know in this thread by posting the dealers hand, your hand and the result. Better yet, the output from the script of the round in question would be ideal.

Thank you to everyone for your feedback.

Dractyl

adeyke
12-21-2009, 03:47 PM
Um, hitting on soft 9 is optimal and on some hard 9 hands you mean?
http://85.234.150.79/~mark/eleven.parsed.html

Right, sorry for the mixup.

Dractyl
12-21-2009, 04:07 PM
Did it bet 11 every time because that's what I had last bet?

Hi Storella,

In version 1 it asks you what you'd like to bet each time you run the script.

In version 2 the bet is always 11 unless you set it to a different value at the top of the script. Just edit it near the top and you're set.

Dractyl

mysyzygy
12-21-2009, 05:31 PM
There was an entry missing. mysyzygy caught it when he made version 3. Download the latest and you should be ok.
Dractyl

That's what I thought too except the hand he looped on was aa3a and that's not the hand I added. Maybe he mis-remembered the hand?

Also, is it true that its a win any time you pull a fifth card? If so then shouldn't we always hit on all four card hands? This should be an instant win because you have 5 cards but if you stand then you might lose if the dealer draws a better hand.

mysyzygy
12-21-2009, 05:47 PM
Hi everyone,

I've released version 4. Instead of placing the file here, I put it back in the original post so new downloaders won't have to go searching for it. Please download from there.



In what original thread? I don't see it in "the11tablesASH ~I DID NOT MAKE THIS~ ".

adeyke
12-21-2009, 06:56 PM
That's what I thought too except the hand he looped on was aa3a and that's not the hand I added. Maybe he mis-remembered the hand?

Also, is it true that its a win any time you pull a fifth card? If so then shouldn't we always hit on all four card hands? This should be an instant win because you have 5 cards but if you stand then you might lose if the dealer draws a better hand.

It's a guaranteed win if you have five cards without a bust. If the fifth card brings you over 11, you've lost. In some cases, it's correct to hit on four cards, but in other cases, it's correct to stand.


In what original thread? I don't see it in "the11tablesASH ~I DID NOT MAKE THIS~ ".

Not original thread; original post (i.e. the first post in this thread).

Dractyl
12-21-2009, 07:22 PM
That's what I thought too except the hand he looped on was aa3a and that's not the hand I added. Maybe he mis-remembered the hand?


I checked v2 and there was no entry for '1','1113', but there was one in v3, so I'm assuming it's yours. Maybe the Crimbo elves are afoot... ;)

Dractyl

MsNicole
12-22-2009, 03:28 PM
Very cool! Thank you for this! :)

Turtle Juice
12-22-2009, 03:57 PM
I love the total won over x rounds and per adv. totals!

Rax
12-23-2009, 09:19 PM
Thanks for this!

Vengeful Chicken
12-26-2009, 05:58 AM
for some reason its not letting me downlad... keeps thinking i'm not logged in.
wtf?

Object X
12-26-2009, 04:23 PM
Ok so I downloaded it and got it working, but with little computer experience I am having a problem.

What goes in the box where it says: "Please input value for int rounds". I mean, I know a number, but what does the number mean etc. ? Is it how many crimbux to spend, how many turns or what?

Thanks for a reply :)

Muhandes
12-26-2009, 04:51 PM
Ok so I downloaded it and got it working, but with little computer experience I am having a problem.

What goes in the box where it says: "Please input value for int rounds". I mean, I know a number, but what does the number mean etc. ? Is it how many crimbux to spend, how many turns or what?

Thanks for a reply :)

As the name suggests, the number of rounds to play

Object X
12-26-2009, 05:52 PM
Makes sense, thanks :-)

Still no idea what int. means though, I thought it might be initial, but probably not.

lostcalpolydude
12-26-2009, 06:24 PM
If it's asking for two numbers, the first one should be how much you're betting, which really should just be hardcoded at 11. If it's only asking for one number, then it's the number of turns. That's all that matters really.

adeyke
12-26-2009, 06:51 PM
The "int" means integer. The dialogue box isn't specially made for the script. The script just uses an integer named "rounds" and what you see is the interface for inputting that variable.

Dractyl
12-26-2009, 07:26 PM
If it's asking for two numbers, the first one should be how much you're betting, which really should just be hardcoded at 11. If it's only asking for one number, then it's the number of turns. That's all that matters really.

Version 1 of the script asked for bets and rounds. Version 2 and later only asks for rounds with the bet being configurable at the top of he script.

Dractyl