Count gate activations and only close when equal deactivations occur.

This commit is contained in:
David Thompson 2024-05-24 19:07:17 -04:00
parent 6053727ee4
commit be21e4a6c0

View file

@ -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)