-
Notifications
You must be signed in to change notification settings - Fork 0
/
the-stack.ss
executable file
·202 lines (180 loc) · 6.92 KB
/
the-stack.ss
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
#|
File : the stack
Author : Wouter Van Rossem
|#
#!r6rs
(library
(the-stack)
(export stack-spell/abi% the-stack%)
(import (rnrs base (6))
(rnrs io simple)
(scheme class)
(prefix (scheme base) s:)
(prefix (magicthegathering datastructures stack linked) stack:)
(magicthegathering abilities)
(magicthegathering permanents)
(magicthegathering non-permanents))
; Class name: stack-spell/abi
; Superclass: object%
; Description: This is a decorator class for cards being announced or on the stack
; Attributes: - public: spell/abi, owner, state-played, card, targets, mc
; - private: mana-payed, nr-of-targets
; Methods:
; - public:
; * check-target:
; arguments: target, owner
; output : bool
; description: check if the target is good for the spell/abi
; * select-target:
; arguments: target
; output : none
; description: select a target for the spell/abi
; * targets-done,:
; arguments: none
; output : bool
; description: are all the targets chosen?
; * pay-mana:
; arguments: none
; output : none
; description: pay-mana of a color
; * set-x:
; arguments: x
; output : none
; description: set the x of the mana-cost
; * mana-payed?:
; arguments: none
; output : bool
; description: has all the mana been payed?
; * determine-mana-cost:
; arguments: none
; output : none
; description: determine the total cost of this spell
; (not yet implemented - not needed at the moment)
; * revert-mana-cost:
; arguments: none
; output : none
; description: when the announced spell is canceled
; return all the spent mana to the owner's mana-pool
; * reset-mana-cost:
; arguments: none
; output : none
; description: after we payed all the mana, we reset the mana
; for later use
; - private: none
(define stack-spell/abi%
(class object%
(init-field spell/abi)
(init-field owner)
(init-field state-played)
(init-field card)
(super-new)
(field (mc (if (is-a? spell/abi activated-ability%) (get-field cost spell/abi) (get-field mana-cost spell/abi))))
(define mana-payed '())
(field (targets '()))
(define nr-of-targets 0)
; ( object% player% -> bool )
(define/public (check-target target owner)
((get-field target? spell/abi) target owner))
; ( object% -> )
(define/public (select-target target)
(set! targets (cons target targets))
(set! nr-of-targets (+ nr-of-targets 1)))
; ( -> bool )
(define/public (targets-done?)
(= nr-of-targets (get-field targets spell/abi)))
; ( symbol -> )
(define/public (pay-mana color)
(begin
(case color
((white) (if (= (get-field white mc) 0) (send mc pay-mana 'colorless 1) (send mc pay-mana 'white 1)))
((blue) (if (= (get-field blue mc) 0) (send mc pay-mana 'colorless 1) (send mc pay-mana 'blue 1)))
((black) (if (= (get-field black mc) 0) (send mc pay-mana 'colorless 1) (send mc pay-mana 'black 1)))
((red) (if (= (get-field red mc) 0) (send mc pay-mana 'colorless 1) (send mc pay-mana 'red 1)))
((green) (if (= (get-field green mc) 0) (send mc pay-mana 'colorless 1) (send mc pay-mana 'green 1)))
((colorless) (send mc pay-mana 'colorless 1)))
(set! mana-payed (cons color mana-payed))))
; ( number -> )
(define/public (set-x x)
(send mc set-x x))
; ( -> bool )
(define/public (mana-payed?)
(send mc mana-payed?))
; ( -> )
(define/public (determine-mana-cost)
'ok)
; ( -> )
(define/public (revert-mana-payed)
(for-each (lambda (c) (send (get-field mana-pool owner) inc-mana 1 c)) mana-payed))
; ( -> )
(define/public (reset-mana-cost)
(send mc reset))))
; Class name: cardstack
; Superclass: object%
; Attributes: - public: none
; - private: stack
; Methods:
; - public:
; * empty?:
; arguments: none
; output : bool
; description: check if the-stack is empty
; * announce-spell/abi:
; arguments: spell/abi owner state-played, card wfor abilities
; output : none
; description: announce a spell/abi
; * put-ability-on-stack:
; arguments: ability owner state card
; output : none
; description: put an ability on the stack
; * resolve-top:
; arguments: none
; output: stack-spell%
; description: remolve the top card of the-stack
; * look-top:
; arguments: none
; output: stack-spell%
; description: look at the top card of the-stack
; * remove-announced:
; arguments: none
; output: none
; description: cancel the announced-spell/abi
; * lock-announced:
; arguments: none
; output: none
; description: put the announced-spell/abi on the stack
; - private: none
(define the-stack%
(class object%
(super-new)
(define stack (stack:new))
(field (announced-spell/abi 0))
; ( -> bool )
(define/public (empty?)
(stack:empty? stack))
; ( card%/ability% player% -> )
(define/public (announce-spell/abi spell/abi owner state-played . card)
(set! announced-spell/abi (new stack-spell/abi% (spell/abi spell/abi) (owner owner) (state-played state-played) (card (if (null? card) '() (s:car card))))))
; ( card%/ability% player% -> )
(define/public (put-ability-on-stack ability owner state . card)
(stack:push! (new stack-spell/abi% (spell/abi ability) (owner owner) (state-played state) (card (if (null? card) '() (s:car card))))))
; ( -> stack-spell%)
(define/public (resolve-top)
(if (empty?)
(error "THE-STACK -- remove-top from empty cardstack" stack)
(stack:pop! stack)))
; ( -> stack-spell% )
(define/public (look-top)
(if (empty?)
(error "THE-STACK-- look-top from empty cardstack" stack)
(stack:top stack)))
; ( -> )
(define/public (remove-announced)
(begin
(send announced-spell/abi revert-mana-payed)
(send announced-spell/abi reset-mana-cost)
(set! announced-spell/abi 0)))
; ( card% player% pair -> )
(define/public (lock-announced)
(stack:push! stack announced-spell/abi)
(send announced-spell/abi reset-mana-cost)
(set! announced-spell/abi 0)))))