Well, just as in Java, this would be easier if the cards had a single index you could access them by. Say the cards had a "card-number" slot. Then to deal a card, you'd have to do the following steps (there are other ways to do this, but this might be the easiest for you to do right now.
1) Initialize a counter variable to 0. 2) Pick a random number from 1-52. 3) Fetch the given fact using a query 4) If the fact belongs to "dealer", modify the fact and increment the counter. 5) Repeat if the counter is less than five. On line 2, you need a function to pick a random number; this works just as in any other language. Call (random), multiply by the size of the range, add the first value in the range, cast to int. (deffunction pick-a-card() (return (integer (+ 1 (* (random) 52))))) On line 3, you need a query; given the "card-number" slot it would look like (defquery find-a-card (declare (variables ?n)) (card (card-number ?n))) I think Peder Jakobsen wrote: [Charset iso-8859-1 unsupported, filtering to ASCII...] > Hi, I'm continuing my quest for the JESS poker game, but (random) is not > doing it for me unless i can get a random number between 1 and 52. Your > suggestions are most appreciated: > > (clear) > (reset) > (watch all) > > (deftemplate card > "A Card in a Deck" > (slot suit) > (slot rank (type INTEGER)) > (slot player) > ) > > (deftemplate deck (slot card)) > > (foreach ?suit (create$ Clubs Diamonds Hearts Spades) > > (foreach ?rank (create$ 1 2 3 4 5 6 7 8 9 10 11 12 13) > ;; assign each card to the dealer by default > (assert (card (suit ?suit) (rank ?rank) (player dealer))) > > ) > > ;; assign a card to a player by modifying a random fact > (modify 5 (player Joe)) > > ;; now assign a random card to a player by modifying a random fact > ;; ??? help ??? > > -------------------------------------------------------------------- > To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]' > in the BODY of a message to [EMAIL PROTECTED], NOT to the list > (use your own address!) List problems? Notify [EMAIL PROTECTED] > -------------------------------------------------------------------- > --------------------------------------------------------- Ernest Friedman-Hill Science and Engineering PSEs Phone: (925) 294-2154 Sandia National Labs FAX: (925) 294-2234 PO Box 969, MS 9012 [EMAIL PROTECTED] Livermore, CA 94550 http://herzberg.ca.sandia.gov -------------------------------------------------------------------- To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]' in the BODY of a message to [EMAIL PROTECTED], NOT to the list (use your own address!) List problems? Notify [EMAIL PROTECTED] --------------------------------------------------------------------
