;;; world-series.ss -- simulates sports championship playoffs ;;; John David Stone ;;; Department of Mathematics and Computer Science ;;; Grinnell College ;;; stone@math.grin.edu ;;; created September 17, 1997 ;;; last revised September 18, 1997 ;;; From the fan's point of view, one of the disadvantages of having a ;;; large number of teams at the top level of a professional sport is that ;;; a large number of playoff games must be played after the regular ;;; season. Chance plays a larger role in determining the outcomes of such ;;; playoffs than in determining who wins the most games in the regular ;;; season, and fans often feel that championships are won fortuitously by ;;; inferior teams. ;;; This program provides a way to estimate the role of chance in ;;; determining the outcome of a series of playoffs. Suppose that one of ;;; the teams entering the playoffs is markedly better than the others -- ;;; good enough to win sixty percent of its games against any playoff ;;; adversary. The program follows such a team through the playoffs, ;;; simulating the outcome of every game (with the help of a random-number ;;; generator) and recording whether the better team succeeds in winning ;;; the championship title. It then repeats the process (with different ;;; random numbers, and hence possibly a different outcome) until the ;;; playoffs have been staged ten thousand times and reports the number of ;;; championships won by the better team. The ratio of championships won ;;; to playoffs simulated is an estimate of the extent to which skill ;;; rather than chance determines the outcome. ;;; The BETTER-TEAM-WINS-GAME? procedure returns #T sixty percent of the ;;; time and #F forty percent. (define better-team-wins-game? (lambda () ;; Write the body for this procedure. )) ;;; The BETTER-TEAM-WINS-SERIES? procedure simulates the playing of a ;;; series of games between the better team and one of its adversaries. ;;; The argument WINS-NEEDED indicates the number of victories a team needs ;;; to win the series -- for example, WINS-NEEDED is 3 in a best-of-five ;;; series, 4 in a best-of-seven series. It returns #T if the better team ;;; accumulates the required number of wins before its adversary does, #F ;;; if the adversary reaches the required total first. ;;; BETTER-TEAM-WINS-SERIES? is actually just an interface procedure to ;;; BETTER-TEAM-WINS-SERIES?-KERNEL, which uses recursion to advance from ;;; one game to the next. Initially, neither team has won a game, so the ;;; additional arguments to BETTER-TEAM-WINS-SERIES?-KERNEL are both 0. (define better-team-wins-series? (lambda (wins-needed) (better-team-wins-series?-kernel wins-needed 0 0))) ;;; BETTER-TEAM-WINS-SERIES?-KERNEL takes three arguments -- the number of ;;; victories a team needs to win the series, the number of victories that ;;; the better team has accumulated so far, and the number of victories ;;; that the adversary has accumulated so far. It first checks to see ;;; whether either side has already achieved the required number of ;;; victories; if so, it reports whether the better team won. Otherwise, ;;; it stages a game between the better team and the adversary. If the ;;; better team wins, its victory total is incremented for the next ;;; recursive call, while that of the adversary is left unchanged; if the ;;; better team loses, the adversary's victory total is incremented ;;; instead. (define better-team-wins-series?-kernel (lambda (wins-needed better-team-so-far adversary-so-far) (cond ((= wins-needed better-team-so-far) #t) ((= wins-needed adversary-so-far) #f) ((better-team-wins-game?) (better-team-wins-series?-kernel wins-needed (+ better-team-so-far 1) adversary-so-far)) (else (better-team-wins-series?-kernel wins-needed better-team-so-far (+ adversary-so-far 1)))))) ;;; The BETTER-TEAM-WINS-CHAMPIONSHIP? procedure simulates a succession of ;;; playoff series (but abandons the simulation as soon as the better team ;;; loses a series). It returns #T if the better team wins all of the ;;; series, #F if it loses at any stage. ;;; The current version reflects the structure of playoffs for professional ;;; baseball in the U.S. Post-season play begins with best-of-five series ;;; between teams in different divisions of the same league. The winners ;;; of those division series advance to the best-of-seven league ;;; championship series, and the winners of the league championships ;;; advance to the best-of-seven World Series. ;;; This procedure can be adapted for other professional sports with ;;; slightly different playoff structures: Instead of Major League ;;; Baseball (3-4-4), one could simulate NBA basketball (3-3-4-4), WNBA ;;; basketball (1-1), NHL hockey (4-4-4-4), NFL football (1-1-1), and so ;;; on. (define better-team-wins-championship? (lambda () (and (better-team-wins-series? 3) ; division series (better-team-wins-series? 4) ; league championship series (better-team-wins-series? 4)))) ; World Series ;;; The CHAMPIONSHIPS-FOR-BETTER-TEAM procedure repeatedly stages simulated ;;; playoffs; the number of repetitions is specified by the parameter ;;; SEASONS. It reports the number of such simulations and the number of ;;; championships won by the better team. (define championships-for-better-team (lambda (seasons) (display "In ") (display seasons) (display " seasons of simulated playoffs, the better team won ") (display (championships-for-better-team-kernel seasons 0)) (display " times.") (newline))) ;;; The CHAMPIONSHIPS-FOR-BETTER-TEAM-KERNEL procedure takes two ;;; parameters -- the number of simulations yet to be run (SEASONS) and the ;;; number of championships so far achieved by the better team. When the ;;; number of simulations remaining has been reduced to zero, the procedure ;;; simply returns the number of championships won by the better team; ;;; until then, it calls BETTER-TEAM-WINS-CHAMPIONSHIP? to determine the ;;; outcome of one simulation, then invokes itself recursively, with the ;;; number of simulations remaining reduced by one and the number of ;;; championships won either increased by one (if the better team won) ;;; or left unchanged (if it lost). (define championships-for-better-team-kernel (lambda (seasons championships-so-far) ;; Write the body for this procedure. )) ;;; The following command directs Scheme to run the simulation ten thousand ;;; times and report the results. (championships-for-better-team 10000)