> program a poker game in Prolog
Please post the exact task description.
Best wishes, Markus Triska.
>
>I have an assignment t program a poker game in Prolog can anyone help
>me ??
>
>Alok
Yes. Learn to play poker.
A.L.
(1) Learn to play poker. Watch what you do when you play.
Any variety of poker is apparently ok. :)
If you know what you're doing, you can write a program to do it, too.
Has interesting corollary. :)
Playing games with incomplete or (as in this case) deliberately and
maximally misleading info, or perhaps needing
the maniuplation of things like "I know X knows I may know Y" is not
really introductory Prolog stuff.
The theoretical underpins are things like probability and (shudder)
inductive logic. Setting up simple game theory-type tableaux is
also likely to be involved.
"If I do X and player A does Y and player B does Z,
then what is my expected/optimistic/pessimistic payoff?".
Then do what seems to maximise the metric chosen.
Some intro stuff on mathematical thy in poker was written by
"Johnny" von Neuman back in the 30s or 40s. It's still relevant, despite being
for "toy" draw poker.
The method I've used in one dark period in the past is
(i) build a computer cluster, (*)
(ii) write some distributed s/w to simulate intelligent agents
playing poker; add in some adaptive capability,
(iii) run for several 1000 hours and gather some statistically
significant data on strategy and (simulated) player populations.
Much of this is implicit in books written c 1980 by significant players. :)
Haven't looked at bridge(s), but played with 500, draw, Omaha & Texas.
It's all much the same kinds of techniques, both to play (if seriously --
I like more to just obviously cheat at 500) and to program.
===
(*) It had one or 2 other uses. Not just a poker cluster. :)
Is the prof's name Ada?
Dhu
--
???????????????????????????????????????
Open Systems Integration
Contact Fubar the Hack: fubar AT neotext.ca
Area code seven eight zero, Exchange four six six, Local zero one zero nine
Highland terms, Canadian workmanship.
All persons named herein are purely fictional victims
of the Canidian Bagle Breeder's Association.
Save the Bagle!
Sun Dhu
???????????????????????????????????????
On Fri, 29 Sep 2006, Alok wrote:
> The exact task description is,
> Prolog Cards
> Overview
> Help me convince my children's grandfather that gambling is a waste of
> time, by creating a prolog program to play cards. For this assignment
> you will implement a prolog predicate,
>
> wins(Hand1, Hand2).
>
> that succeeds when Hand1 is stronger than (wins over) Hand2, according
> to Texas Hold'em Poker Rules.
Right, so first lesson is that if you have a problem, you need to
provide a good specification for it.
What you originally wrote suggested you were being asked to write
a program which played poker i.e. made the tactical decisions which
are part of playing the game. This would be a big research problem,
there are people who have worked on it, papers you can read about
their work, but the actual language used to program the algorithms
and represent the data would be a minor issue.
Now you have made it clear all you want is a program which takes two
poker hands and say which one wins over the other. Fine - so why didn't
you say this in the first place?
> Friends I dont have experience in programming it is just that i cannot
> run away from te situation i have to take the course and get it done.it
> someone knows it thoroughly pls give some time on this and help me. it
> will be a great help
You have been set this exercise because it will help you learn Prolog
by doing it. If someone gives you the answer, you will have learnt
nothing. The person who gave yuou the answer will have been guilty of
aiding and abetting fraud - you will have fraudulently gained a
qualification saying you had a certain level of Prolog programming
ability when you hadn't.
Matthew Huntbach
> The exact task description is,
I suggest a different representation: Let a card be represented as a
term "card" of arity 2: first argument denotes rank, second its suit.
hand(Hs) :-
length(Hs, 5),
cards(Hs).
cards([]).
cards([card(Rank,Suit)|Cs]) :-
rank(Rank),
suit(Suit),
cards(Cs).
rank(R) :- member(R, [ace,king,queen,jack,10,9,8,7,6,5,4,3,2]).
suit(S) :- member(S, [spades,hearts,diamonds,clubs]).
We can use this for type checking as well as for generating hands
(with duplicates).
A royal flush:
royal_flush(RF) :-
memberchk(card(ace,S), RF),
memberchk(card(king,S), RF),
memberchk(card(queen,S), RF),
memberchk(card(jack,S), RF),
memberchk(card(10,S), RF).
Four of a kind:
all_dif([]).
all_dif([D|Ds]) :-
dif_from(Ds, D),
all_dif(Ds).
dif_from([], _).
dif_from([A|As], D) :-
dif(A, D),
dif_from(As, D).
four_of_a_kind(FOAK) :-
all_dif([S1,S2,S3,S4]),
member(card(R,S1), FOAK),
member(card(R,S2), FOAK),
member(card(R,S3), FOAK),
member(card(R,S4), FOAK).
We can generate a royal flush:
?- hand(H), royal_flush(H).
H = [card(ace, spades), card(king, spades), card(queen, spades),
card(jack, spades), card(10, spades)]
and four of a kind:
?- hand(H), four_of_a_kind(H).
H = [card(ace, spades), card(ace, spades), card(ace, hearts),
card(ace, diamonds), card(ace, clubs)]
Best wishes,
Markus Triska
Not exactly "playing poker", is it?
Since you're expecting a "yes/no" answer rather than a probability
this is a pretty simple problem. Just classify the hand into
the usual types -- 2-of-kind, 3-of-kind, 4-of-kind, full-house, etc,
along with a "paramter" that describes over cards, and then you know
4-of-kind beats 3-of-kind, etc.
Pretty much the way you'd write down the rules in English can be
translated line-to-line into Prolog.
Convincing your gradpa (a charming story :) will take more, I'm sure.
You might like to then drive your "wins" predicate to show how often
hand H wins, or generalise the "wins" to just work from lists of 2..7 cards.
Maybe wins should take 2 sets of hole cards, plus a list of 0..5 community cards.
Assignment:
> Help me convince my children's grandfather that gambling is a waste of
> time, by creating a prolog program to play cards. For this assignment
> you will implement a prolog predicate,
>
> wins(Hand1, Hand2).
>
> that succeeds when Hand1 is stronger than (wins over) Hand2, according
> to Texas Hold'em Poker Rules.
>
> Representation
> A hand is represented by a list of 5 cards.
Forget Texas Hold'em. A Texas Hold'em hand consists of 7 cards, 2 in
hand plus 5 shared cards.
Get out any old poker manual and translate the definitions of various
hands into Prolog. Certain types of hands beat other types. E. g., three
of a kind beats two pair. Within each type of hand some hands beat others.
E. g., Ace high beats King high. Translate the comparison rules into
Prolog.
Best wishes,
Bill
most prologs will accept either of
?- consult('/path/to/file').
or
?- ['/path/to/file']
cheers
jeh