-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.rkt
94 lines (79 loc) · 2.29 KB
/
.rkt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
(define Musician 0)
(define Princess 1)
(define Spy 2)
(define Assassin 3)
(define Ambassador 4)
(define Wizard 5)
(define General 6)
(define Prince 7)
;; Design Recipe:
;; Pupose:
;; (braverats A B) consumes two natural numbers and produces the winner
;; of the battle as a symbol (capital ’A or ’B) or the symbol capital ’X to
;; indicate that the round of battle is “on hold”.
;; Contract:
;; braverats: Nat Nat -> Sym
;; Examples:
(check-expect (braverats 1 7) 'A)
(check-expect (braverats 1 5) 'B)
(define (braverats A B)
(cond
[(= A Musician)
(cond
[(= B Wizard) 'B]
[else 'X])]
[(= A Princess)
(cond
[(or (= B Princess) (= B Musician)) 'X]
[(or (= B General) (= B Wizard) (= B Ambassador) (= B Spy)) 'B]
[else 'A])]
[(= A Spy)
(cond
[(and (>= B Ambassador) (<= B Prince)) 'B]
[(or (= B Assassin) (= B Princess)) 'A]
[else 'X])]
[(= A Assassin)
(cond
[(or (= B Prince) (= B Ambassador) (= B Spy) (= B Princess)) 'B]
[(or (= B General) (= B Ambassador)) 'A]
[else 'X])]
[(= A Ambassador)
(cond
[(or (= B Prince) (= B General) (= B Wizard) (= B Assassin)) 'B]
[(or (= B Spy) (= B Princess)) 'A]
[else 'X])]
[(= A Wizard)
(cond
[(or (= B Prince) (= B General)) 'B]
[(= B Wizard) 'X]
[else 'A])]
[(= A General)
(cond
[(or (= B Prince) (= B Assassin)) 'B]
[(or (= B General) (= B Musician)) 'X]
[else 'A])]
[(= A Prince)
(cond
[(or (= B Prince) (= B Musician)) 'X]
[(= B Princess) 'B]
[else 'A])]))
;;Tests:
(check-expect (braverats 0 5) 'B)
(check-expect (braverats 0 4) 'X)
(check-expect (braverats 1 7) 'A)
(check-expect (braverats 1 0) 'X)
(check-expect (braverats 2 7) 'B)
(check-expect (braverats 2 3) 'A)
(check-expect (braverats 2 2) 'X)
(check-expect (braverats 3 7) 'B)
(check-expect (braverats 3 6) 'A)
(check-expect (braverats 4 5) 'B)
(check-expect (braverats 4 2) 'A)
(check-expect (braverats 5 7) 'B)
(check-expect (braverats 5 5) 'X)
(check-expect (braverats 5 1) 'A)
(check-expect (braverats 6 7) 'B)
(check-expect (braverats 6 4) 'A)
(check-expect (braverats 7 7) 'X)
(check-expect (braverats 7 6) 'A)
(check-expect (braverats 7 1) 'B)