File tree Expand file tree Collapse file tree 2 files changed +12
-4
lines changed
Expand file tree Collapse file tree 2 files changed +12
-4
lines changed Original file line number Diff line number Diff line change @@ -98,11 +98,10 @@ fn main() -> ! {
9898 let mut count = 0 ;
9999
100100 loop {
101- if count > 100 {
101+ if count > 10 {
102102 reset_random ( & mut game, & rosc) ;
103103 count = 0 ;
104104 }
105- count += 1 ;
106105
107106 display. clear ( ) ;
108107 for idr in 0 ..64 {
@@ -119,7 +118,9 @@ fn main() -> ! {
119118 }
120119 }
121120 display. flush ( ) . unwrap ( ) ;
122- game. advance ( ) ;
121+ if game. advance ( ) < 100 {
122+ count += 1 ;
123+ }
123124 //delay.delay_ms(500);
124125 }
125126}
Original file line number Diff line number Diff line change @@ -44,16 +44,23 @@ impl GameOfLife {
4444 }
4545 }
4646
47- pub fn advance ( self : & mut Self ) {
47+ pub fn advance ( self : & mut Self ) -> usize {
48+ let mut changes = 0 ;
4849 let mut tmp = GameOfLife :: new ( ) ;
4950 tmp. screen = self . screen . clone ( ) ;
5051 for idxr in 0 ..ROWS {
5152 for idxc in 0 ..COLUMNS {
5253 let index = idxr * COLUMNS + idxc;
5354 let new_state = tmp. next_state_at ( idxr, idxc) ;
55+ let old_state = self . get_at ( idxr, idxc) . unwrap_or ( false ) ;
56+ changes += match ( old_state != new_state) {
57+ true => 1 ,
58+ _ => 0
59+ } ;
5460 self . screen . set ( index, new_state) ;
5561 }
5662 }
63+ changes
5764 }
5865
5966 pub fn count_alive_neighbors ( self : & Self , row : usize , col : usize ) -> usize {
You can’t perform that action at this time.
0 commit comments