Blame


1 12687dd9 2023-08-04 jrmu ;; The first three lines of this file were inserted by DrScheme. They record metadata
2 12687dd9 2023-08-04 jrmu ;; about the language level of this file in a form that our tools can easily process.
3 12687dd9 2023-08-04 jrmu #reader(lib "htdp-intermediate-reader.ss" "lang")((modname 17.6.2-2) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "dir.ss" "teachpack" "htdp") (lib "hangman.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "dir.ss" "teachpack" "htdp") (lib "hangman.ss" "teachpack" "htdp")))))
4 12687dd9 2023-08-04 jrmu ;A word is either
5 12687dd9 2023-08-04 jrmu ;1. empty or
6 12687dd9 2023-08-04 jrmu ;2. (cons s w)
7 12687dd9 2023-08-04 jrmu ;where s is a one-letter symbol ('a, 'b, ...) and '_, and w is a word.
8 12687dd9 2023-08-04 jrmu ;
9 12687dd9 2023-08-04 jrmu ;reveal-list : word word symbol -> word
10 12687dd9 2023-08-04 jrmu ;Given chosen (word), status (word), and guess (one-letter symbol), return the new status word. A status word represents the progress of the hangman game. If guess matches a letter in chosen, replace '_ in status with the letter. Otherwise, return the same status word.
11 12687dd9 2023-08-04 jrmu ;ASSUMPTION: both chosen and status are the same length.
12 12687dd9 2023-08-04 jrmu
13 12687dd9 2023-08-04 jrmu ;Examples
14 12687dd9 2023-08-04 jrmu ;(reveal-list '(b r e a d) '(b r e _ _) 'a)
15 12687dd9 2023-08-04 jrmu ;'(b r e a _)
16 12687dd9 2023-08-04 jrmu ;
17 12687dd9 2023-08-04 jrmu ;(reveal-list '(b r e a d) '(b r e _ _) 'x)
18 12687dd9 2023-08-04 jrmu ;'(b r e _ _)
19 12687dd9 2023-08-04 jrmu ;
20 12687dd9 2023-08-04 jrmu ;(reveal-list '(m o o n) '(_ _ _ n) 'o)
21 12687dd9 2023-08-04 jrmu ;'(_ o o n)
22 12687dd9 2023-08-04 jrmu
23 12687dd9 2023-08-04 jrmu (define (reveal-list chosen status guess)
24 12687dd9 2023-08-04 jrmu (cond
25 12687dd9 2023-08-04 jrmu [(empty? chosen) empty]
26 12687dd9 2023-08-04 jrmu [(cons? chosen)
27 12687dd9 2023-08-04 jrmu (cond
28 12687dd9 2023-08-04 jrmu [(symbol=? guess (first chosen))
29 12687dd9 2023-08-04 jrmu (cons (first chosen) (reveal-list (rest chosen) (rest status) guess))]
30 12687dd9 2023-08-04 jrmu [else (cons (first status) (reveal-list (rest chosen) (rest status) guess))])]))