Count gate activations and only close when equal deactivations occur.
This commit is contained in:
parent
6053727ee4
commit
be21e4a6c0
1 changed files with 11 additions and 4 deletions
|
@ -436,6 +436,7 @@
|
|||
(define (^gate bcom x y)
|
||||
(define position (vector x y 1))
|
||||
(define open? (spawn ^cell))
|
||||
(define activations (spawn ^cell 0))
|
||||
(match-lambda*
|
||||
(('type) 'gate)
|
||||
(('position) position)
|
||||
|
@ -444,11 +445,17 @@
|
|||
(('enter obj grid-info) #f)
|
||||
(('exit obj grid-info) #f)
|
||||
(('activate grid-info)
|
||||
(let ((k (1+ ($ activations))))
|
||||
($ activations k)
|
||||
(unless (> k 1)
|
||||
($ open? #t)
|
||||
($ grid-info 'append-event `(gate-open ,x ,y)))
|
||||
($ grid-info 'append-event `(gate-open ,x ,y)))))
|
||||
(('deactivate grid-info)
|
||||
(let ((k (1- ($ activations))))
|
||||
($ activations k)
|
||||
(when (= k 0)
|
||||
($ open? #f)
|
||||
($ grid-info 'append-event `(gate-close ,x ,y)))
|
||||
($ grid-info 'append-event `(gate-close ,x ,y)))))
|
||||
(('wire-state grid-info from from-x from-y) #f)
|
||||
(('update-wire-state grid-info neighbor-grid) #f)
|
||||
(('alive?) #t)
|
||||
|
|
Loading…
Add table
Reference in a new issue