Five-Card Draw
HOLD
HOLD
HOLD
HOLD
HOLD
Balance
Bet
Deal
Draw
Bet -1
Bet +1
Bet -10
Bet +10
loc(card(2, clubs), deck) loc(card(2, diamonds), deck) loc(card(2, hearts), deck) loc(card(2, spades), deck) loc(card(3, clubs), deck) loc(card(3, diamonds), deck) loc(card(3, hearts), deck) loc(card(3, spades), deck) loc(card(4, clubs), deck) loc(card(4, diamonds), deck) loc(card(4, hearts), deck) loc(card(4, spades), deck) loc(card(5, clubs), deck) loc(card(5, diamonds), deck) loc(card(5, hearts), deck) loc(card(5, spades), deck) loc(card(6, clubs), deck) loc(card(6, diamonds), deck) loc(card(6, hearts), deck) loc(card(6, spades), deck) loc(card(7, clubs), deck) loc(card(7, diamonds), deck) loc(card(7, hearts), deck) loc(card(7, spades), deck) loc(card(8, clubs), deck) loc(card(8, diamonds), deck) loc(card(8, hearts), deck) loc(card(8, spades), deck) loc(card(9, clubs), deck) loc(card(9, diamonds), deck) loc(card(9, hearts), deck) loc(card(9, spades), deck) loc(card(10, clubs), deck) loc(card(10, diamonds), deck) loc(card(10, hearts), deck) loc(card(10, spades), deck) loc(card(11, clubs), deck) loc(card(11, diamonds), deck) loc(card(11, hearts), deck) loc(card(11, spades), deck) loc(card(12, clubs), deck) loc(card(12, diamonds), deck) loc(card(12, hearts), deck) loc(card(12, spades), deck) loc(card(13, clubs), deck) loc(card(13, diamonds), deck) loc(card(13, hearts), deck) loc(card(13, spades), deck) loc(card(14, clubs), deck) loc(card(14, diamonds), deck) loc(card(14, hearts), deck) loc(card(14, spades), deck) img(card(2, clubs), "https://i.imgur.com/mlCxjMw.png") img(card(2, diamonds), "https://i.imgur.com/EuyNuwb.png") img(card(2, hearts), "https://i.imgur.com/gPntX0b.png") img(card(2, spades), "https://i.imgur.com/bmNZHC8.png") img(card(3, clubs), "https://i.imgur.com/4QnrUqt.png") img(card(3, diamonds), "https://i.imgur.com/JAqnQWW.png") img(card(3, hearts), "https://i.imgur.com/e8sD0qt.png") img(card(3, spades), "https://i.imgur.com/N771E9k.png") img(card(4, clubs), "https://i.imgur.com/HUViSUb.png") img(card(4, diamonds), "https://i.imgur.com/clXUvPx.png") img(card(4, hearts), "https://i.imgur.com/i6cMhM4.png") img(card(4, spades), "https://i.imgur.com/6ukw8oM.png") img(card(5, clubs), "https://i.imgur.com/GdsWYO9.png") img(card(5, diamonds), "https://i.imgur.com/gGSlA7X.png") img(card(5, hearts), "https://i.imgur.com/Vh0rhU0.png") img(card(5, spades), "https://i.imgur.com/NoCtYLF.png") img(card(6, clubs), "https://i.imgur.com/2i6X7Q1.png") img(card(6, diamonds), "https://i.imgur.com/leThklw.png") img(card(6, hearts), "https://i.imgur.com/WV9bDp1.png") img(card(6, spades), "https://i.imgur.com/sWXnrl1.png") img(card(7, clubs), "https://i.imgur.com/Yhi7F0k.png") img(card(7, diamonds), "https://i.imgur.com/fGsAMXn.png") img(card(7, hearts), "https://i.imgur.com/dbpo5O1.png") img(card(7, spades), "https://i.imgur.com/YyDbldD.png") img(card(8, clubs), "https://i.imgur.com/IsiCS3b.png") img(card(8, diamonds), "https://i.imgur.com/FUC8y6q.png") img(card(8, hearts), "https://i.imgur.com/qLygexz.png") img(card(8, spades), "https://i.imgur.com/bWT1ZbE.png") img(card(9, clubs), "https://i.imgur.com/cuVL8U1.png") img(card(9, diamonds), "https://i.imgur.com/ktK2loY.png") img(card(9, hearts), "https://i.imgur.com/IJqFNEE.png") img(card(9, spades), "https://i.imgur.com/h0USG7r.png") img(card(10, clubs), "https://i.imgur.com/0BXPVJ4.png") img(card(10, diamonds), "https://i.imgur.com/9byYpeX.png") img(card(10, hearts), "https://i.imgur.com/nKuY3gC.png") img(card(10, spades), "https://i.imgur.com/iCEOMTY.png") img(card(11, clubs), "https://i.imgur.com/XRceQwC.png") img(card(11, diamonds), "https://i.imgur.com/kGnkf2c.png") img(card(11, hearts), "https://i.imgur.com/9QVjPPw.png") img(card(11, spades), "https://i.imgur.com/qkCfEoL.png") img(card(12, clubs), "https://i.imgur.com/q9HMVgj.png") img(card(12, diamonds), "https://i.imgur.com/75zoE2n.png") img(card(12, hearts), "https://i.imgur.com/PiSTtXn.png") img(card(12, spades), "https://i.imgur.com/OYCoEzB.png") img(card(13, clubs), "https://i.imgur.com/Pp5pYyQ.png") img(card(13, diamonds), "https://i.imgur.com/vsLk2AS.png") img(card(13, hearts), "https://i.imgur.com/rxuHAJz.png") img(card(13, spades), "https://i.imgur.com/x05rpuc.png") img(card(14, clubs), "https://i.imgur.com/XFcO4Co.png") img(card(14, diamonds), "https://i.imgur.com/Y2Eb7Bz.png") img(card(14, hearts), "https://i.imgur.com/CiUEZIP.png") img(card(14, spades), "https://i.imgur.com/o7jtA9T.png") balance(100) bet(10) last_multi(0) tickinterval(300) state(betting)
style(HandElement, "background-image", UrlText) :- loc(Card, HandElement) & img(Card, ImageUrl) & stringappend("url(", ImageUrl, ")", UrlText) has_card(HandElement) :- loc(Card, HandElement) style(HandElement, "background-image", none) :- ~has_card(HandElement) new_card(I) :- plus(I, 1, I1) & state(dealing(I1)) new_card(I) :- plus(I, 1, I1) & state(drawing(I1)) & ~held(I) skip_card(I) :- plus(I, 1, I1) & state(drawing(I1)) & held(I) style(slot(I), "background-color", "lightblue") :- new_card(I) style(slot(I), "background-color", "lightgray") :- skip_card(I) style(slot(I), "background-color", "white") :- ~new_card(I) & ~skip_card(I) % BETTING innerhtml(balance, X) :- balance(X) innerhtml(bet, X) :- bet(X) can_up(X) :- state(betting) & balance(Bal) & bet(Bet) & plus(Bet, X, BetX) & max(Bal, BetX, Bal) attribute(betup1, "disabled", "false") :- can_up(1) attribute(betup1, "disabled", "true") :- ~can_up(1) attribute(betup10, "disabled", "false") :- can_up(10) attribute(betup10, "disabled", "true") :- ~can_up(10) can_down(X) :- state(betting) & bet(B) & plus(X, 1, X1) & max(B, X1, B) attribute(betdown1, "disabled", "false") :- can_down(1) attribute(betdown1, "disabled", "true") :- ~can_down(1) attribute(betdown10, "disabled", "false") :- can_down(10) attribute(betdown10, "disabled", "true") :- ~can_down(10) click(betup1) & bet(B) & plus(B, 1, B1) ==> ~bet(B) & bet(B1) click(betup10) & bet(B) & plus(B, 10, B10) ==> ~bet(B) & bet(B10) click(betdown1) & bet(B) & minus(B, 1, B1) ==> ~bet(B) & bet(B1) click(betdown10) & bet(B) & minus(B, 10, B10) ==> ~bet(B) & bet(B10) % DEALING can_deal :- state(betting) & balance(Bal) & bet(Bet) & max(Bal, Bet, Bal) & max(Bal, 1, Bal) attribute(deal, "disabled", "false") :- can_deal attribute(deal, "disabled", "true") :- ~can_deal click(deal) & balance(Bal) & bet(Bet) & minus(Bal, Bet, Bal_) & last_multi(M) ==> ~last_multi(M) & ~balance(Bal) & balance(Bal_) & ~state(betting) & state(dealing(0)) click(deal) & loc(C, L) ==> ~loc(C, L) & loc(C, deck) tick & state(dealing(I)) & min(I, 4, I) & evaluate(choose(X, loc(X, deck)), C) ==> loc(C, hand(I)) & ~loc(C, deck) tick & state(dealing(I)) & min(I, 4, I) & plus(I, 1, I1) ==> ~state(dealing(I)) & state(dealing(I1)) tick & state(dealing(5)) ==> ~state(dealing(5)) & state(holding) % HOLDING style(hold(I), "visibility", "visible") :- held(I) style(hold(I), "visibility", "hidden") :- ~held(I) attribute(hand(I), "onclick", "modbutton(this)") :- state(holding) attribute(hand(I), "onclick", "") :- ~state(holding) click(hand(I)) & state(holding) & ~held(I) ==> held(I) click(hand(I)) & state(holding) & held(I) ==> ~held(I) % DRAWING attribute(draw, "disabled", "false") :- state(holding) attribute(draw, "disabled", "true") :- ~state(holding) click(draw) ==> ~state(holding) & state(drawing(0)) tick & state(drawing(I)) & minus(I, 1, I1) & held(I1) ==> ~held(I1) tick & state(drawing(I)) & min(I, 4, I) & ~held(I) & loc(C, hand(I)) & evaluate(choose(X, loc(X, deck)), C_) ==> ~loc(C, hand(I)) & loc(C_, hand(I)) & ~loc(C_, deck) tick & state(drawing(I)) & min(I, 4, I) & plus(I, 1, I1) ==> ~state(drawing(I)) & state(drawing(I1)) tick & state(drawing(5)) & actual_multi(X) & payout(Y) ==> ~tickinterval(300) & tickinterval(50) & last_multi(X) & payout_to_go(Y) & ~state(drawing(5)) & state(scoring) % SCORING permutation(C0, C1, C2, C3, C4) :- loc(C0, hand(I0)) & loc(C1, hand(I1)) & distinct(I1, I0) & loc(C2, hand(I2)) & distinct(I2, I1) & distinct(I2, I0) & loc(C3, hand(I3)) & distinct(I3, I2) & distinct(I3, I1) & distinct(I3, I0) & loc(C4, hand(I4)) & distinct(I4, I3) & distinct(I4, I2) & distinct(I4, I1) & distinct(I4, I0) multi("Royal Flush", 800) multi("Straight Flush", 50) multi("Four of a Kind", 25) multi("Full House", 9) multi("Flush", 6) multi("Straight", 4) multi("Three of a Kind", 3) multi("Two Pair", 2) multi("Jacks or Better", 1) % royal flush hand_type(card(10, S), card(11, S), card(12, S), card(13, S), card(14, S), "Royal Flush") % straight flush hand_type(C0, C1, C2, C3, C4, "Straight Flush") :- hand_type(C0, C1, C2, C3, C4, "Straight") & hand_type(C0, C1, C2, C3, C4, "Flush") % four of a kind hand_type(card(V, _), card(V, _), card(V, _), card(V, _), _, "Four of a Kind") % full house hand_type(card(V0, _), card(V0, _), card(V0, _), card(V1, _), card(V1, _), "Full House") % flush hand_type(card(_, S), card(_, S), card(_, S), card(_, S), card(_, S), "Flush") % straight hand_type(card(V0, _), card(V1, _), card(V2, _), card(V3, _), card(V4, _), "Straight") :- plus(V0, 1, V1) & plus(V1, 1, V2) & plus(V2, 1, V3) & plus(V3, 1, V4) hand_type(card(14, _), card(2, _), card(3, _), card(4, _), card(5, _), "Straight") % three of a kind hand_type(card(V, _), card(V, _), card(V, _), _, _, "Three of a Kind") % two pair hand_type(card(V0, _), card(V0, _), card(V1, _), card(V1, _), _, "Two Pair") % jacks or better hand_type(card(V, _), card(V, _), _, _, _, "Jacks or Better") :- max(V, 11, V) max_multi(X) :- setofall(M, permutation(C0, C1, C2, C3, C4) & hand_type(C0, C1, C2, C3, C4, T) & multi(T, M), Xs) & maximum(Xs, X) & max(X, 1, X) actual_multi(X) :- max_multi(X) actual_multi(0) :- ~max_multi(X) payout(X) :- bet(B) & actual_multi(M) & times(B, M, X) style(balance, "color", "green") :- state(scoring) style(balance, "color", "black") :- ~state(scoring) tick & payout_to_go(P) & distinct(P, 0) & minus(P, 1, P_) & balance(Bal) & plus(Bal, 1, Bal_) ==> ~balance(Bal) & balance(Bal_) & ~payout_to_go(P) & payout_to_go(P_) payout_to_go(0) & last_multi(X) ==> ~tickinterval(50) & tickinterval(300) & ~payout_to_go(0) & ~state(scoring) & state(betting) payout_to_go(0) & bet(Bet) & balance(Bal) & plus(Bal, 1, Bal1) & max(Bet, Bal1, Bet) ==> ~bet(Bet) & bet(Bal) % Hand Type Display order("Royal Flush", 0) order("Straight Flush", 1) order("Four of a Kind", 2) order("Full House", 3) order("Flush", 4) order("Straight", 5) order("Three of a Kind", 6) order("Two Pair", 7) order("Jacks or Better", 8) innerhtml(handtype(I), T) :- order(T, I) innerhtml(multi(I), X) :- order(T, I) & multi(T, M) & bet(B) & times(B, M, X) is_best_hand(I) :- last_multi(X) & multi(T, X) & order(T, I) style(handtype(I), "background-color", "lightgreen") :- is_best_hand(I) style(handtype(I), "background-color", "white") :- ~is_best_hand(I)