Created
January 4, 2014 03:31
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; player クラス | |
(define-class player ((money 5000) (tofu 0)) | |
() | |
(money () money) | |
(money-set! (arg) (set! money arg)) | |
(show-tofu () tofu) | |
(make-tofu (num env) (let ((maxnum | |
(maximum (get-tofu env) (get-player env)))) | |
(cond ((> num maxnum) (set! tofu maxnum)) | |
((< num 0) (set! tofu 0)) | |
(else (set! tofu num))) | |
tofu))) | |
;;; computer クラス | |
(define-class computer ((money 5000) (tofu 0)) | |
() | |
(money () money) | |
(money-set! (arg) (set! money arg)) | |
(show-tofu () tofu) | |
(make-tofu (env) (letrec ((calc | |
(lambda (num) | |
(let ((maxnum | |
(quotient money (cost (get-tofu env))))) | |
(if (> num maxnum) | |
maxnum | |
num))))) | |
; body | |
(cond ((> (cdr | |
(assq 'rainy | |
(weather-report (get-weather env)))) | |
30) | |
(set! tofu | |
(is-rainy (get-tofu env)))) | |
((> (cdr | |
(assq 'sunny | |
(weather-report (get-weather env)))) | |
49) | |
(set! tofu (calc (is-sunny (get-tofu env))))) | |
(else | |
(set! tofu (calc (is-cloudy (get-tofu env)))))) | |
tofu))) | |
(define-method money) | |
(define-method money-set!) | |
(define-method show-tofu) | |
(define-method make-tofu) | |
;;; トーフクラス | |
(define-class tofu ((cost 40) | |
(price 50) | |
(sunny 500) | |
(cloudy 300) | |
(rainy 100)) | |
() | |
(cost () cost) | |
(price () price) | |
(is-sunny () sunny) | |
(is-cloudy () cloudy) | |
(is-rainy () rainy) | |
(maximum (player) (quotient (money player) cost))) | |
(define-method cost) | |
(define-method price) | |
(define-method is-sunny) | |
(define-method is-cloudy) | |
(define-method is-rainy) | |
(define-method maximum) | |
;;; 天候クラス | |
(define-class weather ((sunny 0) | |
(cloudy 0) | |
(rainy 0)) | |
() | |
; 天気予報の計算 | |
(calc-weather-report () (let ((prob0 (random-integer 100)) | |
(prob1 (random-integer 100))) | |
; body | |
(cond ((> prob0 prob1) | |
(set! sunny (- 100 prob0)) | |
(set! rainy prob1)) | |
(else (set! sunny (- 100 prob1)) | |
(set! rainy prob0))) | |
(set! cloudy (- 100 sunny rainy)))) | |
; 天気予報 | |
(weather-report () `((sunny . ,sunny) | |
(cloudy . ,cloudy) | |
(rainy . ,rainy))) | |
; 実際の天気 | |
(actual-weather () (let ((r (random-integer 100))) | |
(cond ((<= r rainy) (values is-rainy 'rainy)) | |
((<= r (+ rainy cloudy)) (values is-cloudy 'cloudy)) | |
(else (values is-sunny 'sunny)))))) | |
(define-method calc-weather-report) | |
(define-method weather-report) | |
(define-method actual-weather) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment