Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2009-09

exists "card game" library?

6 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

waldo kitty

i'm working on converting a TP6 "card game" application to FPC (to start with) and then to Lazarus for the graphical side... what i'm looking for, so as to not try to "recreate the wheel", is a "card object" such that i can create X "decks" of objects of 52 items with Y shuffle(s) of those X decks and/or similar... i have a method of keeping up with the decks and play but i'm looking for how to draw the cards and also be able to draw them fast... [see aside]

[aside: i ran the original DOS TP6 version along side the FPC windows version and the original version ran at one "lost hand" per second or so... the speed differences are hugely astounding... one item of contention may be that the DOS version uses "direct screen writes" and not "OS" screen writes...]

i need a way to select each card via mouse click or keyboard selection, add it to a "collection" that sums to one of a set of possible additions and then remove the selected cards to another card deck...

i have the base program written in basic CP850 characters and "colorations" but have nothing specific for drawing "graphical cards on a card playing table"...

advTHANXance

David W Noon
to waldo kitty

On Mon, 21 Sep 2009 23:15:44 -0400, waldo kitty wrote about [Lazarus] exists "card game" library?:

Show quoted text 7 lines
i'm working on converting a TP6 "card game" application to FPC (to start with) and then to Lazarus for the graphical side... what i'm looking for, so as to not try to "recreate the wheel", is a "card object" such that i can create X "decks" of objects of 52 items with Y shuffle(s) of those X decks and/or similar... i have a method of keeping up with the decks and play but i'm looking for how to draw the cards and also be able to draw them fast... [see aside]

Hi Mark,

I started thinking about this problem yesterday. It is actually quite difficult to solve satisfactorily on a 32-bit or 64-bit machine. I did some algebra (combinatorics, to be more precise) and immediately came to the conclusion that you will need to use 256-bit arithmetic for a statistically satisfactory solution. This is because the number of distinct permutations ("shuffles") of a 52-card deck is 52!, which evaluates to:

80658175170943878571660636856403766975289505440883277824000000000000

This number requires at least 226 bits for unsigned representation.

Many years ago I developed an algorithm to form permutations from ordinal numbers within the permutation space. [I have not seen this algorithm elsewhere, so it could well be original -- but it's nothing special.] Using this algorithm, I was able to generate several hundred shuffled decks per second, even on a 5-year-old Athlon MP box. This was running 256-bit arithmetic on a 32-bit processor.

To do this, I used the GMP (Gnu Multiple Precision) library. Since I do not [yet] have any Pascal bindings for this library, my test code is written in C. However, there are some arbitrary precision packages in the contributions area of the FPC Web site, any of which could be a viable alternative to GMP.

The alternative to using arbitrary precision arithmetic is to make multiple passes through your random number generator, which is both computationally more intensive and produces statistically less satisfactory results than using a 256-bit random number generator.

Show quoted text 5 lines
[aside: i ran the original DOS TP6 version along side the FPC windows version and the original version ran at one "lost hand" per second or so... the speed differences are hugely astounding... one item of contention may be that the DOS version uses "direct screen writes" and not "OS" screen writes...]

I'm not sure what you mean by "lost hand" in the above. Did you mean that you had 4 aces and the machine drew a straight flush? ... :-))

i need a way to select each card via mouse click or keyboard selection, add it to a "collection" that sums to one of a set of possible additions and then remove the selected cards to another card deck...

That is fairly easy to code in Lazarus classes.

i have the base program written in basic CP850 characters and "colorations" but have nothing specific for drawing "graphical cards on a card playing table"...

For pretty pictures that are fairly portable, I would recommend SVG (Scalable Vector Graphics), which are similar in philosophy, but rather different in implementation, to Windows and OS/2 metafiles.

You will also find a "dingbat" font quite handy, as the suit logos can be coded as characters from the dingbats in the font. On Windows, the "Wingdings" TrueType font is ubiquitous; on systems that prefer Postscript fonts (OS/2, MacOS, UNIX/Linux, etc.), the popular choice is "Zapf Dingbats".

HTH

Regards, Dave [RLU #314465] ======================================================================= (David W Noon) =======================================================================
Marco van de Voort
to David W Noon
David W Noon wrote 6 lines
To do this, I used the GMP (Gnu Multiple Precision) library. Since I do not [yet] have any Pascal bindings for this library, my test code is written in C. However, there are some arbitrary precision packages in the contributions area of the FPC Web site, any of which could be a viable alternative to GMP.

An initial GMP binding was committed to FPC on sept 7th.

I assume it would also compile with older (2.2) versions of FPC.

waldo kitty
to Marco van de Voort
Marco van de Voort wrote 10 lines
On Wed, Sep 23, 2009 at 04:53:30PM +0100, David W Noon wrote: > To do this, I used the GMP (Gnu Multiple Precision) library. Since I > do not [yet] have any Pascal bindings for this library, my test code > is written in C. However, there are some arbitrary precision packages > in the contributions area of the FPC Web site, any of which could be a > viable alternative to GMP. An initial GMP binding was committed to FPC on sept 7th. I assume it would also compile with older (2.2) versions of FPC.

i'm sure that will be appreciated... however, as i wrote to david, this seems to be a bit of overkill as my initial message left much to broad interpretation... all i'm basically wanting to do is to create a deck of playing cards and use them in a game... the current DOS TP6 version uses arrays for the value of each card... i'm wanting to find or create a "library" of card "decks" consisting of X cards... for a "standard poker game" this deck would consist of 52 cards... for some other Vegas type game, there might be a "shoe" consisting of Y decks shuffled together...

i already have a shuffling routine that i based on an array of items and i think i can account for a deck of items... the part that i'm having a problem with is converting over to using "objects of my own creation" instead of using an existing object library...

does that make sense?

Lee Jenkins
to waldo kitty: i'm working on converting a TP6 "card game" application to FPC (to start with) and then…
waldo kitty wrote 22 lines
i'm working on converting a TP6 "card game" application to FPC (to start with) and then to Lazarus for the graphical side... what i'm looking for, so as to not try to "recreate the wheel", is a "card object" such that i can create X "decks" of objects of 52 items with Y shuffle(s) of those X decks and/or similar... i have a method of keeping up with the decks and play but i'm looking for how to draw the cards and also be able to draw them fast... [see aside] [aside: i ran the original DOS TP6 version along side the FPC windows version and the original version ran at one "lost hand" per second or so... the speed differences are hugely astounding... one item of contention may be that the DOS version uses "direct screen writes" and not "OS" screen writes...] i need a way to select each card via mouse click or keyboard selection, add it to a "collection" that sums to one of a set of possible additions and then remove the selected cards to another card deck... i have the base program written in basic CP850 characters and "colorations" but have nothing specific for drawing "graphical cards on a card playing table"...

Interesting. I'm working on a Texas Hold'em application. This particular one is nothing special, just a tutoring software to help new holdem players learn how to recognize hands, count outs, percentage of hitting, pot odds, etc.

You'd think being a programmer I'd be fast in doing all that myself, but its tough when there are so many /other/ things going on in a hand. Considering your hand, position, action in front of you, likely action in back of you, patterns of betting behavior all while counting your outs, etc. I figured if I could get so good at doing to the point of not having to think about it, I'd do it more naturally at the table. Seems to work so I'm packaging it up as a small shareware app for people just starting to learn holdem. I've only been playing for about six month, but 4 weeks of playing with this software even in its earlier, rough form made a big difference. Now I have more time to concentrate on the other players.

Anywho, I ran across this very nice library/components for Delphi that seems to be pretty extensive. I ended up implementing the hand (and possible hand) parsing routines myself for the experience, but this looks very interesting. I believe it handles display of the cards as well, something else I did on my own, but probably can save you some time.

http://charlesappel.home.mindspring.com/wcpkste.html

Warm Regards, Lee
David W Noon
to Marco van de Voort: An initial GMP binding was committed to FPC on sept 7th. I assume it would also compile…

On Wed, 23 Sep 2009 19:46:19 +0200, Marco van de Voort wrote about Re: [Lazarus] exists "card game" library?:

Show quoted text 11 lines
On Wed, Sep 23, 2009 at 04:53:30PM +0100, David W Noon wrote: > > To do this, I used the GMP (Gnu Multiple Precision) library. Since I > do not [yet] have any Pascal bindings for this library, my test > code is written in C. However, there are some arbitrary precision > packages in the contributions area of the FPC Web site, any of > which could be a viable alternative to GMP. An initial GMP binding was committed to FPC on sept 7th. I assume it would also compile with older (2.2) versions of FPC.

Hi Marco,

I have installed 2.5.1 from a source snapshot and the GMP bindings work just fine. I tried compiling the unit with a 2.2.4 compiler; while the unit itself compiled, the program using the unit failed to compile with error messages like "impossible operator overload". As a result, I will stick to using the 2.5.1 compiler.

Regards, Dave [RLU #314465] ======================================================================= (David W Noon) =======================================================================