Implementing the Poker Game in Jess Vanmoerkerke Frederik

  • Slides: 15
Download presentation
Implementing the Poker Game in Jess Vanmoerkerke Frederik Project APLAI

Implementing the Poker Game in Jess Vanmoerkerke Frederik Project APLAI

Aim of the project Learn the rules of the Poker game n Implement the

Aim of the project Learn the rules of the Poker game n Implement the rules of the game in Jess n Practical example of theory n Interaction between Java and Jess n Benefits of rule based systems n

Structure of the program Java Applet for Graphical User Interface n Jess for implementing

Structure of the program Java Applet for Graphical User Interface n Jess for implementing the rules of the game n

Video Poker Single player game n Try to get a Poker hand n Poker

Video Poker Single player game n Try to get a Poker hand n Poker hand: pair, double pair, three of a kind, . . . n Task Jess: check if we have a Poker hand n

deftemplates + deffacts (deftemplate card "The number, value and suit of the card" (slot

deftemplates + deffacts (deftemplate card "The number, value and suit of the card" (slot number) (slot value) (slot suit)) (deftemplate result "Payout index" (slot index)) (deffacts indexnumber "Initiate the indexnumber" (result (index 0)))

Assert the card facts Deftemplate cardtemp = engine. find. Deftemplate("card"); Fact card 1 =

Assert the card facts Deftemplate cardtemp = engine. find. Deftemplate("card"); Fact card 1 = new Fact(cardtemp); card 1. set. Slot. Value("number", new Value(0, RU. INTEGER)); card 1. set. Slot. Value("value", new Value(value[0], RU. INTEGER)); card 1. set. Slot. Value("suit", new Value(suit[0], RU. INTEGER)); engine. assert. Fact(card 1);

Example rule n Check if we have a full house (pair and three of

Example rule n Check if we have a full house (pair and three of a kind) (defrule check-full-house (card (number ? n 1) (value ? v 1)) (card (number =(+ ? n 1 1))(value ? v 1)) (card (number ? n 2&~? n 1) (value ? v 2&~? v 1)) (card (number =(+ ? n 2 1)) (value ? v 2)) (card (number =(+ ? n 2 2)) (value ? v 2)) ? oldindex <- (result (index ? i&: (< ? i 8))) => (retract ? oldindex) (assert (result (index 8))))

Get the result fact Fact fact = new Fact(engine. find. Deftemplate("result")); String fact. Name="";

Get the result fact Fact fact = new Fact(engine. find. Deftemplate("result")); String fact. Name=""; Iterator it = engine. list. Facts(); while (it. has. Next()&&!fact. Name. ends. With("result")) { fact = (Fact) it. next(); fact. Name = fact. get. Name() ; } vindex = fact. get. Slot. Value("index"); index = vindex. int. Value(engine. get. Global. Context()); score += index*bet;

Draw Poker Multiplayer game n Also trying to get a Poker hand n Winner

Draw Poker Multiplayer game n Also trying to get a Poker hand n Winner = best Poker hand n Tasks Jess n What action the computer player should take n Which cards to hold n Finding the winner n n Different modules: CARDS, ACTION, HOLD

deftemplates en deffacts (deftemplate CARDS: : card "The value and suit of the card"

deftemplates en deffacts (deftemplate CARDS: : card "The value and suit of the card" (slot number) (slot value) (slot suit)) (deftemplate HOLD: : hold "number card to hold" (slot number)) (deftemplate HOLD: : index "index to be sure that highest rank is holded" (slot number)) (deftemplate CARDS: : dealer "show if dealer had has his turn" (slot state)) (deftemplate ACTION: : action "action: Fold, Pass/Call, Bet/Raise" (slot text)) (deftemplate ACTION: : index "index to know what action to take and height of the cards" (slot number) (slot height 1) (slot height 2)) (deffacts CARDS: : indexnumber "Initiate the indexnumbers and a random number" (HOLD: : index (number 0)) (ACTION: : index (number 0) (height 1 0) (height 2 0)) (ACTION: : rand (round (* 10 (/ (random) 65536)))))

Action of computer player n n n Choice of action depends of the cards

Action of computer player n n n Choice of action depends of the cards Getting index from same rules as in Video Poker Example rule (defrule ACTION: : action-raise (CARDS: : dealer (state "false")) (or (and (ACTION: : index (number ? i&: (> ? i 3))) (ACTION: : rand ? j&: (> ? j 1)) ) (and (ACTION: : index (number ? i&: (> ? i 0)&: (< ? i 4))) (ACTION: : rand ? j&: (> ? j 4)) ) ) => (assert (ACTION: : action (text Bet/Raise))))

Hold cards for computer player n Example rule when having four of a kind

Hold cards for computer player n Example rule when having four of a kind (defrule HOLD: : hold-four-of-a-kind (CARDS: : card (number ? n) (value ? v)) (CARDS: : card (number =(+ ? n 1)) (value ? v)) (CARDS: : card (number =(+ ? n 2)) (value ? v)) (CARDS: : card (number =(+ ? n 3)) (value ? v)) ? oldindex <- (HOLD: : index (number ? i&: (< ? i 7))) => (retract ? oldindex) (assert (HOLD: : index (number 7))) (assert (HOLD: : hold (number ? n))) (assert (HOLD: : hold (number (+ ? n 1)))) (assert (HOLD: : hold (number (+ ? n 2)))) (assert (HOLD: : hold (number (+ ? n 3)))))

Finding Winner n n n Same rules as in Video Poker Additional slots: Height

Finding Winner n n n Same rules as in Video Poker Additional slots: Height 1, Height 2 Example rule for checking two pairs (defrule CARDS: : check-two-pair (CARDS: : card (number ? n 1) (value ? v 1)) (CARDS: : card (number =(+ ? n 1 1)) (value ? v 1)) (CARDS: : card (number ? n 2&~? n 1) (value ? v 2&~? v 1)) (CARDS: : card (number =(+ ? n 2 1)) (value ? v 2)) ? oldindex <- (ACTION: : index (number ? i&: (< ? i 2))) => (retract ? oldindex) (assert (ACTION: : index (number 2) (height 1 ? v 1) (height 2 ? v 2))))

Conclusion Very easy to implement rules in Jess n Better overview of rules than

Conclusion Very easy to implement rules in Jess n Better overview of rules than in a normal programming language like Java n Easy communication between Java and Jess n

Demo Video Poker n Draw Poker n

Demo Video Poker n Draw Poker n