Presentation is loading. Please wait.

Presentation is loading. Please wait.

Implementing the Poker Game in Jess Vanmoerkerke Frederik Project APLAI.

Similar presentations


Presentation on theme: "Implementing the Poker Game in Jess Vanmoerkerke Frederik Project APLAI."— Presentation transcript:

1 Implementing the Poker Game in Jess Vanmoerkerke Frederik Project APLAI

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

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

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

5 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)))

6 Assert the card facts Deftemplate cardtemp = engine.findDeftemplate("card"); Fact card1 = new Fact(cardtemp); card1.setSlotValue("number",new Value(0,RU.INTEGER)); card1.setSlotValue("value",new Value(value[0],RU.INTEGER)); card1.setSlotValue("suit",new Value(suit[0],RU.INTEGER)); engine.assertFact(card1);

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

8 Get the result fact Fact fact = new Fact(engine.findDeftemplate("result")); String factName=""; Iterator it = engine.listFacts(); while (it.hasNext()&&!factName.endsWith("result")) { fact = (Fact) it.next(); factName = fact.getName() ; } vindex = fact.getSlotValue("index"); index = vindex.intValue(engine.getGlobalContext()); score += index*bet;

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

10 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 height1) (slot height2)) (deffacts CARDS::indexnumber "Initiate the indexnumbers and a random number" (HOLD::index (number 0)) (ACTION::index (number 0) (height1 0) (height2 0)) (ACTION::rand (round (* 10 (/ (random) 65536)))))

11 Action of computer player Choice of action depends of the cards Choice of action depends of the cards Getting index from same rules as in Video Poker Getting index from same rules as in Video Poker Example rule 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))))

12 Hold cards for computer player Example rule when having four of a kind 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)))))

13 Finding Winner Same rules as in Video Poker Same rules as in Video Poker Additional slots: Height1, Height2 Additional slots: Height1, Height2 Example rule for checking two pairs Example rule for checking two pairs (defrule CARDS::check-two-pair (CARDS::card (number ?n1) (value ?v1)) (CARDS::card (number =(+ ?n1 1)) (value ?v1)) (CARDS::card (number ?n2&~?n1) (value ?v2&~?v1)) (CARDS::card (number =(+ ?n2 1)) (value ?v2)) ?oldindex <- (ACTION::index (number ?i&:(< ?i 2))) => (retract ?oldindex) (assert (ACTION::index (number 2) (height1 ?v1) (height2 ?v2))))

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

15 Demo Video Poker Video Poker Draw Poker Draw Poker


Download ppt "Implementing the Poker Game in Jess Vanmoerkerke Frederik Project APLAI."

Similar presentations


Ads by Google