Skip to content

Commit

Permalink
(update-cell) accounts for perimeter neighbors.
Browse files Browse the repository at this point in the history
  • Loading branch information
jpt4 committed Jan 28, 2016
1 parent a8ae1a5 commit c48c0b9
Showing 1 changed file with 66 additions and 29 deletions.
95 changes: 66 additions & 29 deletions practice/aa.scm
Original file line number Diff line number Diff line change
Expand Up @@ -86,18 +86,6 @@ MASTER-SCHEDULER(T+1)
(neighbor-a nba nba!) (neighbor-b nbb nbb!) (neighbor-c nbc nbc!)
)

;;don't develop rlem object unless rlem record proves insufficient
#;(define (rlem-3453 id mem ai bi ci ao bo co na nb nc)
(define state (rlem-3453-state id mem ai bi ci ao bo co na nb nc))

(define (self msg)
(case (car msg)
['state state]
)
)
self
)

(define (rlem-3453-lattice r c . cl-list)
(define cell-list (if (null? cl-list) (rlem-hex-grid r c) (car cl-list)))
(define activation-order (map id (random-permutation (cdr cell-list))))
Expand All @@ -118,25 +106,31 @@ MASTER-SCHEDULER(T+1)
(let* ([cell (cell-list-ref index)]
[in (lambda () (list (ai cell) (bi cell) (ci cell)))] ;lazy in
[out (list (ao cell) (bo cell) (co cell))]
[nba (cell-list-ref (nba cell))]
[nbb (cell-list-ref (nbb cell))]
[nbc (cell-list-ref (nbc cell))]
[nbra (cell-list-ref (nba cell))]
[nbrb (cell-list-ref (nbb cell))]
[nbrc (cell-list-ref (nbc cell))]
[empty? (lambda (c) (equal? '(0 0 0) c))]
[inhale ;gather new input from neighbors' outputs
(lambda ()
(begin
(ai! cell (ao nba)) (bi! cell (bo nbb)) (ci! cell (co nbc))
(ao! nba 0) (bo! nbb 0) (co! nbc 0)))] ;clear nbr outputs
(ai! cell (ao nbra)) (bi! cell (bo nbrb)) (ci! cell (co nbrc))
(ao! nbra 0) (bo! nbrb 0) (co! nbrc 0)))] ;clear nbr outputs
[process
(lambda ()
(if (not (empty? (in))) ;did (inhale) acquire new input?
(begin
(case (mem cell) ;rotate in right/left, write to out
(case (mem cell) ;rotate input right/left, write to output
['0 (ao! cell (ci cell)) (bo! cell (ai cell)) ;right
(co! cell (bi cell))]
['1 (ao! cell (bi cell)) (bo! cell (ci cell)) ;left
(co! cell (ai cell))])
(ai! cell 0) (bi! cell 0) (ci! cell 0) ;clear inputs
(if (equal? (nba cell) 'p)
(ao! cell 0)) ;}if cell borders the perimeter
(if (equal? (nbb cell) 'p) ;}immediately dispose of its
(bo! cell 0)) ;}output channel values
(if (equal? (nbc cell) 'p)
(co! cell 0))
(mem! cell (abs (- (mem cell) 1))))))]) ;mem switch
(cond
[(and (empty? out) (empty? (in))) (begin (inhale) (process))]
Expand Down Expand Up @@ -169,7 +163,47 @@ MASTER-SCHEDULER(T+1)
self
)

;;f(rows, cols) => neighbor-list, neighbor-list:={(Id,nba,nbb,nbc)...}
#|
An example 3x5 hex grid constructed by (rlem-hex-grid), overlaid on a
rectangular co-ordinate graph. The first element of the first row, indexed as
id-0, is at hex-co-ordinate x(0,0), equivalent to ortho-co-ordinate r(2,2) on
this graph due to a 2-up, 2-right translation. Element id-1 is at x(0,1) or
r(3,3). Elements id-0 through id-5, id-6 through id-B, and id-C through
id-H comprise rows 1, 2, and 3, respectively. Column 1 is composed of
elements id-0, id-6, and id-C, and so forth for the others. Rows grow up and to
the right (alternatively from south-west to north-east); with respect to Row 1,
subsequent rows can be generated by a 1-up translation. "p" indicates the
special perimeter cell, which does not update state, always sources "0" on its
output channels, and immediately sinks its neighbors non-zero output channel
values so that they do not block.

y
|
A p
| \
9 p H-p
| \ /
8 p F-G
| \ / \
7 D-E B-p
| / \ /
6 p-C 9-A
| \ / \
5 7-8 5-p
| / \ /
4 p-6 3-4
| \ / \
3 1-2 p
| / \
2 p-0 p
| \
1 p
|
--o-1-2-3-4-5-6-7-8-9-x
|
|
|#
;;f(rows, cols) => cell-list
(define (rlem-hex-grid rows cols)
(let* ([size (* rows cols)]
[p (rlem-3453-state 'p 0 0 0 0 0 0 0 '_ '_ '_)]
Expand Down Expand Up @@ -247,16 +281,16 @@ MASTER-SCHEDULER(T+1)

(define (step lat . t)
(dispnl* (cons 'original-lattice-state (lat '(cell-list))))
(cond
[(null? t) (step lat 1)]
[(equal? (car t) 1) (begin
(lat '(update-lattice 1))
(dispnl* (cons `(steps-to-go ,(car t))
(lat '(cell-list)))))]
[else (begin
(lat '(update-lattice 1))
(dispnl* (cons `(steps-to-go ,(car t)) (lat '(cell-list))))
(step lat (- (car t) 1)))]))
(let next ([ts (if (null? t) 1 (car t))])
(cond
[(equal? ts 1) (begin
(lat '(update-lattice 1))
(dispnl* (cons `(steps-to-go ,ts)
(lat '(cell-list)))))]
[else (begin
(lat '(update-lattice 1))
(dispnl* (cons `(steps-to-go ,ts) (lat '(cell-list))))
(next (- ts 1)))])))

(define tstrlem0 (rlem-3453-state 'tst 0 0 0 0 0 0 0 0 0 0))
(define tstgrid0 (rlem-hex-grid 5 4))
Expand All @@ -281,4 +315,7 @@ MASTER-SCHEDULER(T+1)
(dispnl* (cons 'randlat0-cell-list-new-born (randlat0 '(cell-list))))
(dispnl* (cons 'randlat0-update-lattice-5 (randlat0 '(update-lattice 5))))
(dispnl* (cons 'randlat0-cell-post-update-lattice-5 (randlat0 '(cell-list))))
;show the work
(dispnl* 'step-through-random-10x10-lattice-10-times)
(step (random-lattice 10 10) 10)
)

0 comments on commit c48c0b9

Please sign in to comment.