1 / 15

Implementing the Poker Game in Jess

Implementing the Poker Game in Jess. Vanmoerkerke Frederik Project APLAI. Aim of the project. Learn the rules of the Poker game Implement the rules of the game in Jess Practical example of the theory Interaction between Java and Jess Benefits of rule based systems.

Télécharger la présentation

Implementing the Poker Game in Jess

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

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 • Implement the rules of the game in Jess • Practical example of the theory • Interaction between Java and Jess • Benefits of rule based systems

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

  4. Video Poker • Single player game • Try to get a Poker hand • Poker hand: pair, double pair, three of a kind, ... • 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) (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 • Also trying to get a Poker hand • Winner = best Poker hand • Tasks Jess • What action the computer player should take • Which cards to hold • Finding the winner • 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 • 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))))

  12. Hold cards for computer player • 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 • Additional slots: Height1, Height2 • 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 • Better overview of rules than in a normal programming language like Java • Easy communication between Java and Jess

  15. Demo • Video Poker • Draw Poker

More Related