;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; Human player: allows you to play against your programs ; ; Version 1.1 ; ; Copyright (c) 2000 Wesley H. Huang. All rights reserved ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; Well, this isn't pretty, but it works! ; ; You can't call the "set" and "assert" actions from your ; user-defined functions, so the alternative is to create your own ; global state by defining a variable and then using set! in your ; program. The terminal actions must be called directly from a rule, ; so what I do here is to set a global variable which a subsequent ; rule acts upon. ; ; Aside from this messiness, you can at least see all the variables ; available to you. I've only used the lo-hand and hi-hand functions ; here, but there are others available to you as described in the ; assignment handout. ; ; (define (print-info) (print "Here are all the variables:") (print "\n all/active-players = " all/active-players) (print "\n other/active-players = " other/active-players) (print "\n all/players = " all/players) (print "\n other/players = " other/players) (print "\n all/seated-players = " all/seated-players) (print "\n other/seated-players = " other/seated-players) (print "\n num-players = " num-players) (print "\n num-active-players = " num-active-players) (print "\n bet-round = " bet-round) (print "\n hand-number = " hand-number) (print "\n min-raise = " min-raise) (print "\n max-raise = " max-raise) (print "\n my/clams = " my/clams) (print "\n me = " me) (print "\n total-bet = " total-bet) (print "\n pot-total = " pot-total) (print "\n my/hand = " my/Hand) (print "\n my/hi-hand = " my/hi-hand) (print "\n my/lo-hand = " my/lo-hand) (print "\n call-amount = " call-amount) (print "\n\nYou have the cards:") (map (lambda (c) (print " " (card-string c))) (my/cards)) (print "\n\nHere's what you know about your opponents' hands:\n\n") (map (lambda (x) (print " " x " has the public cards") (map (lambda (c) (print " " (card-string c))) (public-cards x)) (print "\n lo-hand=" (lo-hand x) ", hi-hand=" (hi-hand x) "\n")) other/active-players)) ; global variables for the betting rules (define raise-amount) (define human-bet) ; a user defined action function used in the betting rules ; sets global state that is picked up by subsequent rules (define (get-human-bet) (define (get-bet) (print "\nWhat do you want to do: call, pass, or raise?\n") (let ((a (read))) (if (member a '(pass call raise)) a (get-bet)))) (define (get-raise) (print "\nHow much do you want to raise? (" min-raise " to " max-raise ")\n") (let ((r (read))) (if (<= min-raise r max-raise) r (get-raise)))) (print-info) (let ((b (get-bet))) (if (equal? b 'raise) (set! raise-amount (get-raise))) (set! human-bet b))) ; note that you don't use the "call" keyword as the original handout ; states (and that's becasue "call" is already being used by a ; terminal betting action! (define betting-rules '((#t ==> (get-human-bet)) ((equal? human-bet 'call) ==> (call)) ((equal? human-bet 'pass) ==> (pass)) ((equal? human-bet 'raise) ==> (raise raise-amount)))) ; global variable for declaration rules (define human-dec) ; user-defined action funtion for declaration rules (define (get-human-declaration) (define (get-dec) (print "\nDo you want to declare high or low?\n") (let ((d (read))) (if (member d '(high low)) d (get-dec)))) (print-info) (set! human-dec (get-dec))) (define declaration-rules '((#t ==> (get-human-declaration)) ((equal? human-dec 'high) ==> (declare-high)) ((equal? human-dec 'low) ==> (declare-low)))) (define poker-player (list 'human "W. Huang" betting-rules declaration-rules (lambda () '()))) ; This overrides the default settings for what information is printed ; to the screen so that only the public card information is printed. (print-only-public) ; record information about this player's playing to a file. this is ; provided so that you can record information for learning. ; ; specify a filename, a function to be called after each betting ; action, a function to be called after the declaration, and a ; function to be called after the showdown ; ; all functions should take one argument. the betting printing ; function will be passed the action returned by the player ; (e.g. (call), (pass), or (raise 10)). the declaration printing ; function will return the symbol corresponding to the declaration ; (high or low). the showdown printing function will be passed the ; amount of winnings for the player. ; ; these functions can just use the "print" function (or "display", ; "write", and "newline") which normally prints to the screen. this ; output will be redirected to the file when it is called. ; (define (bet-printing action) (print "(" action " (" call-amount " " pot-total " " my/clams ")\n")) (define (dec-printing dec) '()) (define (sho-printing winnings) '()) ; uncomment this definition to save data ; ; (define save-information ; (list "human.dat" ; bet-printing ; dec-printing ; sho-printing))