473,761 Members | 4,082 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

selecting and working with appropriate data type

I'm trying to figure out what data type is appropriate to represent a
card in a game. The idea that I thought was going to work was a
struct, foo, with two integer fields and two fields of char arrays:
index cardno description suit
( 1, 1,Two of clubs ,'c')
( 2, 2,Three of clubs ,'c')
( 3, 3,Four of clubs ,'c')
( 4, 4,Five of clubs ,'c')
( 5, 5,Six of clubs ,'c')
Dec 19 '06
13 2206

pete wrote:
lane straatman wrote:

pete wrote:
LS: fishing for hints on representing a poker game
Consider the hand as an array.
Sort the array, and check for equality in consecutive elements.
Paul Hsieh wrote a program that I like,
which fully evaluates poker hands and scores them.
Does Paul's version come up with a number for a hand that would inform
a decision? LS

Yes.

I deleted some unused variables and did very little reformatting.
This is pretty close to what he posted:
[post downloaded but snipped for brevity]
pete
#include <stdio.h>
#define LU_RAND(S) ((S) * 69069 + 362437 & 0xffffffffLU)
int main(void)
{
/** #define LU_RAND_SEED 1124021992
** 1124021815
** 1141904096
** 1141906091
** 1143411367
** 123456789LU */
unsigned long seed;
int i;
seed = 1124021992;
printf("%lu\n", seed);
for (i = 1; i < 1000; ++ i)
{
seed = LU_RAND(seed);
printf("%lu\n", seed);

}
return 0;
}
end source
This prog is heavily snipped from pete's upthread post. He circumvents
a rand() call with the macro, and I've been trying to find cracks in
it, but have only succeeded in finding cracks in my own knowledge of
C. With his choice of 69069, 362437 and mask, he never busts his data
type. Nor can I find a non-randomness mod some smallish number.

I don't understand the mask. If I remove f's, I lose 2 digits on the
number, yet there seems to be an extra f to my thinking. If I add an
f, I get the following warning that doesn't turn out to be true:
warning C4244: '=' : conversion from 'unsigned __int64 ' to 'unsigned
long '. What give's?

I was "certain" that the results for 5 card stud was **way** heavy on
pairs and trips until I took out a deck of cards and got empirical.
For Hold 'Em enthusiasts, you can look at it as the community cards.
You'll be less inclined to pull the trigger with a pocket pair.

Poker is a great way to sharpen up one's syntax. Familiar and hands
on. I've been down the hall at comp.lang.fortr an, using Metcalf, Reid
& Cohen. I've yet to assail interoperabilit y with C, and one reason
for that is that I don't see types I recognize. Are the following
kosher types: int_least32_t , int_fast64_t , long double _Complex ,
_Bool ? LS

Dec 27 '06 #11

lane straatman <gr**********@n etzero.netwrote in message
news:11******** **************@ n67g2000cwd.goo glegroups.com.. .
Bill Reid wrote:
lane straatman <gr**********@n etzero.netwrote in message
news:11******** **************@ 79g2000cws.goog legroups.com...
pete wrote:
LS: fishing for hints on representing a poker game
>
As is usually the case, it turns out he was looking to solve
Fermat's Last Theorum and asked how to add 2+2...
It was only a century back that logicians proclaimed that "arithmetic
teeters."
Math can be pretty wacky...read the history of "probabilit y theory"
and compare it to what we know now for some good laughs, and those
comedians are/were the renowned mathematicians of their day...
Consider the hand as an array.
Sort the array, and check for equality in consecutive elements.
Paul Hsieh wrote a program that I like,
which fully evaluates poker hands and scores them.

This is one that I wrote:

/* BEGIN shuffle.c */

#include <stdio.h>
[main and beyond snipped for brevity]
Thanks all for replies and in particular pete for his generous post.
I'm a mile away from a compiler now, so I can't step through it, but
it
looks as clean as a whistle.
>
Well, as one of my "mentors" on one of my first jobs said, "if it
looks good, it must be good"...

I really do prefer my object-oriented C++ card-playing classes
myself...
What is it that you gain from OO?
The ability to write simulators for new games without re-creating all
the code for "cards", "deck of cards", "card table", "dealer", "players",
etc. Basically, I can just write a new "game" class with some new
"strategy" tables and I'm done...
One thing I want to do is to be able to calculate is how much of a
difference it makes in the odds when a card gets flipped up, which
happens fairly frequently in real life, and on which I have no numeric
handle. A card flipped up during the deal--in Western
Michigan--becomes the burn card. I'm unaware of how universal this
practice is. An upturned burn card would differ from the usual, I
should think.
>
It's just a card that can never be drawn to the community cards or
to a player's hand, so you remove it from the deck remainder that
you evaluate using combinatorial analysis...oh wait, are you writing
a combinatorial analyzer, or a "Monte Carlo" simulator, or
perhaps a simulator that can call in a combinatorial analysis
at any time, or what?
Monte Carlo is the short answer. I'm only able to do combo with pen
and paper. It's nice to have a computer tell you that you've got the
correct answer.
Ah, yes, once again, check the history of "probabilit y theory" and
note it only really "gelled" as the result of empirical studies, which is
greatly aided these days by high-speed computer simulations. Las
Vegas exists because of the laws of probability but the casino owners
didn't (and still largely don't!) know the laws, they only kind of know
"what works" (note that even after Dr. Thorp calculated the "odds"
of a hand of blackjack, they STILL didn't really understand the
game they were offering)...

Of course, if you able to do the calculation with "pen and paper",
you can do it with a computer, but you admit you don't really trust
your math skills. So you want to simulate the game and compile
the statistics to see what really happens. So what you really want
is not a full poker simulator, but a more limited simulator that just
checks the hand completion results after a particular card is "seen".
Be aware that you'll have to run many billions of trials for each
of the possible combinations of your dealt cards and the "seen"
card in order for the varying results to resolve to a statistically-valid
"expectatio n" number.
More than anything though, I like to see a scenario,
say, that you're dealt a pocket pair and see how the bidding might go
given tight/loose players, short/tall stacks and position.
OK, that's a full simulator. You're dealing with a lot more variables
there, and getting into some of the more "intangible/chaotic" aspects of
poker, given that in real life, "tightness" and "looseness" can and do
vary themselves as player "psychology " changes. The "bidding"
itself is dependant on YOUR "tightness" or "looseness" in many
situations.

In addition to biting off more than you can chew coding- and
game theory-wise, you may be asking a question that already
has a better strategic answer, if your goal is just to learn how
to win at poker...
Right now,
I array the cards and "players" on my desk and try to do the odds
analysis.
Of course, you can "see" the other player's cards, which is a tremendous
advantage you only sometimes get in a real game!
In real life, I'm having trouble playing with loose players
on tall stacks in cash games. The burning question there is usually
just when to push all in.
Yeah, those pesky "real-life" players will do it to you every time!
Here's a well-known clue: NOBODY can win in a truly "loose"
game. Here's the (duh!) strategy: DON'T PLAY IN THOSE
GAMES. Problem solved!

Of course, it is also impossible to win in a truly "tight" game
either. The general strategy for winning consistently at poker
thus reduces down to choosing your opponents (ideally,
"loose/scared"), not trying to figure out how to win in games
where nobody has a chance of winning.

---
William Ernest Reid

Dec 29 '06 #12
lane straatman wrote:
>
pete wrote:
lane straatman wrote:
>
pete wrote:
LS: fishing for hints on representing a poker game
>
Consider the hand as an array.
Sort the array, and check for equality in consecutive elements.
Paul Hsieh wrote a program that I like,
which fully evaluates poker hands and scores them.
Does Paul's version come up with
a number for a hand that would inform
a decision? LS
Yes.

I deleted some unused variables and did very little reformatting.
This is pretty close to what he posted:
[post downloaded but snipped for brevity]
pete

#include <stdio.h>
#define LU_RAND(S) ((S) * 69069 + 362437 & 0xffffffffLU)
int main(void)
{
/** #define LU_RAND_SEED 1124021992
** 1124021815
** 1141904096
** 1141906091
** 1143411367
** 123456789LU */
unsigned long seed;
int i;
seed = 1124021992;
printf("%lu\n", seed);
for (i = 1; i < 1000; ++ i)
{
seed = LU_RAND(seed);
printf("%lu\n", seed);

}
return 0;
}
end source
This prog is heavily snipped from pete's upthread post.
He circumvents
a rand() call with the macro, and I've been trying to find cracks in
it, but have only succeeded in finding cracks in my own knowledge of
C. With his choice of 69069, 362437 and mask, he never busts his data
type. Nor can I find a non-randomness mod some smallish number.
There are three prng's that I use,
which I call "the fast one", "the good one" and "the standard one"
LU_RAND(S) yields alternating odd and even values,
which is why it's not "the good one".

The stamdard one is in the standard.
The good one is RAND_32LU(S), located here:
http://www.mindspring.com/~pfilandr/...istributions.c

The algorithms are not original ones of mine.
What I've gleaned over the years of reading this newgroup
and comp.programmin g, is that until you become expert in prng's,
it's best to leave the prng algorithms to the experts.
"The good one" is adapted from something posted by
George Marsaglia who I believe is an expert on the topic.

The purpose of the mask, is to keep the results
portable in case of long having more than 32 bits.

Purpose of using the prng's instead of rand(),
is to make the results duplicatable across different C paltforms.

--
pete
Jan 2 '07 #13

"pete" <pf*****@mindsp ring.comwrote in message
news:45******** **@mindspring.c om...
There are three prng's that I use,
which I call "the fast one", "the good one" and "the standard one"
LU_RAND(S) yields alternating odd and even values,
which is why it's not "the good one".

The stamdard one is in the standard.
The good one is RAND_32LU(S), located here:
http://www.mindspring.com/~pfilandr/...istributions.c

The algorithms are not original ones of mine.
What I've gleaned over the years of reading this newgroup
and comp.programmin g, is that until you become expert in prng's,
it's best to leave the prng algorithms to the experts.
"The good one" is adapted from something posted by
George Marsaglia who I believe is an expert on the topic.

The purpose of the mask, is to keep the results
portable in case of long having more than 32 bits.

Purpose of using the prng's instead of rand(),
is to make the results duplicatable across different C paltforms.
It takes me a bit to play with these, but that will be easier now that I'm
hooked up to the net again.
http://www.mindspring.com/~pfilandr/...istributions.h has
prototypes. LS
Jan 9 '07 #14

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1680
by: budgie | last post by:
Hi, I have a table with availability of rooms which has the htlrm_id: hotel room id avl_date: date this room is available avl_qty: quantity of this room available avl_rate: rate at which these rooms can be booked an example of the data in the table is:
5
3358
by: Axial | last post by:
Question: How to select columns from Excel-generated XML when some cells are empty. I've found examples where rows are to be selected, but I can't seem to extrapolate from that to selecting columns when some cells are empty. Is there a way to use the ss:Index to account for the missing <Cell elements? Thank you for any suggestions. ====================
4
2683
by: Chris Jones | last post by:
Does anyone know of a C#/ASP.NET Open File dialog that I can use in an aspx page that allows multiselect? I need to be able to select and upload numerous files. Is there a reason why MS has made this so difficult? I am willing to pay for such a control.
6
2057
by: aaj | last post by:
Hi all I use a data adapter to read numerous tables in to a dataset. The dataset holds tables which in turn holds full details of the records i.e. keys, extra colums etc.. In some cases I need to use parts of the tables in datagrids, and here is where my problem lies
5
1799
by: fakeprogress | last post by:
For a homework assignment in my Data Structures/C++ class, I have to create the interface and implementation for a class called Book, create objects within the class, and process transactions that manipulate (and report on) members of the class. Interface consists of: - 5 private variables char author; char title; char code;
1
1550
by: jdhcards | last post by:
Hello, I've been banging my head against a problem all day without a solution, and I'm hoping you all can help. I've got a piece of XML that defines a set of elements in a flat list. Each of these elements has an attribute "Id" which has a unique value. Some of these elements have a parent-child relationship, specified with a "ResultId" attribute in one of the child nodes. <element id=1>
4
26707
by: Tomasz Jastrzebski | last post by:
Hello Everyone, I have a GridView control bound to a plain DataTable object. AutoGenerateEditButton is set to true, Edit button gets displayed, and RowEditing event fires as expected.
4
2107
by: darrel | last post by:
I have a DDL list along these lines: item value="1" text="a" item value="2" text="b" item value="3" text="c" item value="2" text="d" item value="2" text="e" item value="1" text="f" item value="1" text="g"
1
2055
by: Mark B | last post by:
This is my first try at using AJAX. I want the calendars to be enabled if the user checks CheckBox1. It works OK for a normal all page refresh but once I introduced the AJAX code it stopped working. Any ideas? <%@ Page Language="VB" AutoEventWireup="false" CodeFile="default-ajax.aspx.vb" Inherits="pages_verify_groups_Default" Debug="true" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
0
9522
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9336
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10111
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9948
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9902
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9765
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7327
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5215
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5364
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.