IRIX and Software

blackjack simulation

So I mentioned in another thread that I used nekochan's prodigious downtime to get started on something I've wanted to do since forever, which is to recreate the pioneering blackjack simulations that were done by Julian Braun at IBM in the 1960s and published in Lawrence Revere's classic 1969 book "Playing Blackjack as a Business." Braun did his sims in fortran and later wrote several papers and a book or two about it, but he died rather suddenly in 2000 and his source code is apparently lost for all time.

Anyway I thought I'd do the simplest simulation first, which is how many times a player will get each dealt hand versus the dealer's up card in 100,000 hands. I wanted to watch the numbers click up in real time so I called XtSetValues each time a hand was dealt, and to make sure each widget updated on the screen immediately I called XFlush after every deal. It didn't work. if you want to make X crawl, if you want to make X puke and die just call XtSetValues a hundred thousand times. Actually, it's not the calls themselves, they go into the server queue and complete pretty fast, it's the server trying to update the widgets that kills it. On my 3.2 GHz Linux box, it takes several minutes for the server to work it's way through the queue. No wonder the Unix Hater's Manual has a chapter titled The X Windows Disaster. So yeah, this isn't going to work and I've got to try something else. But if you'd like to witness the hilarity, source code is attached. I haven't tried this on IRIX yet but since I haven't done anything with X resources it uses the motif defaults which on IRIX always look like da sheet. Oh, and I haven't coded the line for the totals on the bottom either. So what you see is the player's two card totals down the left side versus the dealer's upcard at the top, and how many times you will get each hand in 100,000 deals. Braun ran the simulation innumerable times and then averaged them, which is what I'll do too eventually. So if you've read all the way to the end of this ridiculously long post, thanks! Post back if you actually try this. Compilation instructions are at the top of the file... 8-)
Project:
Temporarily lost at sea...
Plan:
World domination! Or something...
yay you did it hehe. gonna try it later today :D
r-a-c.de
Outstanding, thanks! It's kinda laughable tho compared with what I wanted it to do... 8-)
Project:
Temporarily lost at sea...
Plan:
World domination! Or something...
I tried to compile it with the g++ on my O2 and it works. It's only a little too big for my 1600x1024 screen..

It needed few minutes (5 or so) for run. :-) Sorry for using the FVWM on the IRIX ;-)

vishnu wrote: So I mentioned in another thread that I used nekochan's prodigious downtime to get started on something I've wanted to do since forever, which is to recreate the pioneering blackjack simulations that were done by Julian Braun at IBM in the 1960s and published in Lawrence Revere's classic 1969 book "Playing Blackjack as a Business."
:O2: :Indy: :Indy:
jirka wrote: I tried to compile it with the g++ on my O2 and it works.
Thanks for taking it for a test drive! :D

jirka wrote: It's only a little too big for my 1600x1024 screen..
Your motif is defaulting to a much bigger font than mine. It's really my fault for not providing an app-defaults file or (worse) hard coding a middle of the road font to try to accommodate all screen sizes.

jirka wrote: It needed few minutes (5 or so) for run. :-)
Actually the program is done in only a few seconds, when the run button reactivates the simulation is over, the remaining time is all the X server going through the 100,000 queued screen updates. Really, five minutes to clear a queue only a hundred thousand long? X; the first fully modular software disaster... :|

jirka wrote: Sorry for using the FVWM on the IRIX ;-)
Heresy heresy! :twisted:
Project:
Temporarily lost at sea...
Plan:
World domination! Or something...
just tried it on osx and it's working fine. irix coming up ...
r-a-c.de
foetz wrote: just tried it on osx and it's working fine. irix coming up ...
Top notch! How 'bout a Fresca? 8-)
Project:
Temporarily lost at sea...
Plan:
World domination! Or something...
here's a small update. slight changes here and there such as making it fit at 1280x1024 and a few tweaks. see notes in the source file's head for details. build for 6.2 included.
r-a-c.de
foetz wrote: here's a small update. slight changes here and there such as making it fit at 1280x1024 and a few tweaks. see notes in the source file's head for details. build for 6.2 included.

Wow, thanks! Did you run a code prettifier on it? Because if you did it must be one that likes long lines because the line in reset() that rezeros all the labels now goes out to column 4,648... :shock:

Also you prefer to include stdlib.h instead of cstdio? Although I suppose on IRIX 6.2 that makes sense. Should probably ifdef that and the STL3 includes with _sgi and if it's not defined include the regular ones. And the <iostream> stuff was just in there for debugging from the console, if we're not using it the setValues() count variable is unecessary. And since X obviously won't let us watch all the numbers fly up individually I should remove all the calls to XtSetValues inside the simulation for() loop, that would take care of the ridiculous 5 minute lag... :|

EDIT: Still need to include <iostream> for the call to time() in the random number seed...
Project:
Temporarily lost at sea...
Plan:
World domination! Or something...
vishnu wrote: Wow, thanks! Did you run a code prettifier on it? Because if you did it must be one that likes long lines because the line in reset() that rezeros all the labels now goes out to column 4,648... :shock:

haha yes, partially. the long lines shouldn't be a problem tho for the compiler or the user thanks to line wrapping all decent editors have

Also you prefer to include stdlib.h instead of cstdio? Although I suppose on IRIX 6.2 that makes sense.

exactly, i had to on 6.2. that was before c++98 so no namespaces either and such. but that's of course not meant to be better for all compilers and system having the "official" c++ headers.

Should probably ifdef that and the STL3 includes with _sgi and if it's not defined include the regular ones.

well as i wrote in my comment that's just how i called that dir on my box. there was no stl at all for 6.2. it had to be downloaded by the user and then you could put it anywhere and call it anything. having a more recent os as target that's of course not practical but was the only way getting it done on 6.2.

And the <iostream> stuff was just in there for debugging from the console, if we're not using it the setValues() count variable is unecessary. And since X obviously won't let us watch all the numbers fly up individually I should remove all the calls to XtSetValues inside the simulation for() loop, that would take care of the ridiculous 5 minute lag... :|

hehe yeah sounds good :)

EDIT: Still need to include <iostream> for the call to time() in the random number seed...

oh seems i missed that then :P
r-a-c.de
Done! The whole thing now runs in a fraction of a second. I ifdefed the 6.2 parts so it should compile on both IRIX 6.2 and Linux, also, I cast the fallback resources to (char *) to prevent the ubiquitous g++ warning about deprecated conversions, and you changed my use of XtOpenApplication() to XtVaAppInitialize() which is deprectated in X11 7-point whatever, but I left it. New version attached!

EDIT: Just noticed a bug in setValues(), the data array member still has ++ so all the simulated values will be off by one. I'll fix it in the next version if there is one. :lol:

Otherwise just delete line 1648 (which says data[a]++; )
Project:
Temporarily lost at sea...
Plan:
World domination! Or something...
vishnu wrote: Done! The whole thing now runs in a fraction of a second.

great :D

I ifdefed the 6.2 parts so it should compile on both IRIX 6.2 and Linux

see above :P

you changed my use of XtOpenApplication() to XtVaAppInitialize() which is deprectated in X11 7-point whatever, but I left it.

oh sorry, i didn't know. if there're any benefits please do change it again by all means. sorry for the extra hassle
r-a-c.de
foetz wrote: oh sorry, i didn't know. if there're any benefits please do change it again by all means. sorry for the extra hassle

Not a problem, not sure why they deprecated it because they've said they can never remove it without breaking 87 million programs that are already out there...
Project:
Temporarily lost at sea...
Plan:
World domination! Or something...
and here comes v1.3 :D
array increment removed, fixed one new bug and added a timer to simulate().

working like a charm now without the instant label updates. the whole thing takes less than 2 seconds on an r4400 indigo2 :-)
updated source and the resulting build for 6.2 included.
r-a-c.de
Awesome, thanks! :P

Trying to compile it on my Sun at work but the bastards in IT seem to have removed the X11 and Motif includes, WTF... :cry:

EDIT: I wonder if there's another defined symbol in IRIX 6.2 that we can use other than __sgi, that's not defined in IRIX 6.5 so the existing ifdef would work automagically, without users having to see your note and edit the source code for use in IRIX 6.5? Not that I expect anyone other than the two of us to actually show enough interest to do that... :lol:
Project:
Temporarily lost at sea...
Plan:
World domination! Or something...