Normal quotes
This commit is contained in:
parent
5e10794a24
commit
18011c595a
352 changed files with 6040 additions and 6040 deletions
36
18-04.md
36
18-04.md
|
|
@ -14,7 +14,7 @@
|
|||
#include <conio.h>
|
||||
#include <time.h>
|
||||
#include <bios.h>
|
||||
#include “life.h”
|
||||
#include "life.h"
|
||||
|
||||
// functions in VIDEO.C
|
||||
void enter_display_mode( void );
|
||||
|
|
@ -51,14 +51,14 @@
|
|||
long start_time, end_time;
|
||||
unsigned int seed;
|
||||
|
||||
printf( “Seed (0 for random seed): ” );
|
||||
scanf( “%d”, &seed );
|
||||
printf( "Seed (0 for random seed): " );
|
||||
scanf( "%d", &seed );
|
||||
if( seed == 0 ) seed = (unsigned) time(NULL);
|
||||
srand( seed );
|
||||
|
||||
#ifndef NODRAW
|
||||
enter_display_mode();
|
||||
show_text( 0, 10, “Generation:” );
|
||||
show_text( 0, 10, "Generation:" );
|
||||
#endif
|
||||
|
||||
InitCellmap(); // randomly initialize cell map
|
||||
|
|
@ -71,7 +71,7 @@
|
|||
generation++;
|
||||
|
||||
#ifndef NOCOUNTER
|
||||
sprintf( gen_text, “%10lu”, generation );
|
||||
sprintf( gen_text, "%10lu", generation );
|
||||
show_text( 0, 12, gen_text );
|
||||
#endif
|
||||
}
|
||||
|
|
@ -89,9 +89,9 @@
|
|||
exit_display_mode();
|
||||
#endif
|
||||
|
||||
printf( “Total generations: %ld\nSeed: %u\n”, generation, seed );
|
||||
printf( “%ld ticks\n”, end_time );
|
||||
printf( “Time: %f generations/second\n”,
|
||||
printf( "Total generations: %ld\nSeed: %u\n", generation, seed );
|
||||
printf( "%ld ticks\n", end_time );
|
||||
printf( "Time: %f generations/second\n",
|
||||
(double)generation / (double)end_time * 18.2 );
|
||||
}
|
||||
|
||||
|
|
@ -167,37 +167,37 @@ a *change list;* that is, a list of pointers to cells that change in the
|
|||
current generation. Only those cells and their neighbors need to be
|
||||
checked or touched in any way in order to create the next generation,
|
||||
saving a great many instructions and also a great many cache misses due
|
||||
to the fact that cellmaps are too big to fit into the 486’s internal
|
||||
to the fact that cellmaps are too big to fit into the 486's internal
|
||||
cache. During a given generation, David runs down the list of cells that
|
||||
changed from the previous generation to make the changes for this
|
||||
generation, and in the process generates the change list for the next
|
||||
generation.
|
||||
|
||||
That’s the overall approach, but this being David Stafford, it’s not
|
||||
that simple, of course. I’ll let him tell you how his implementation
|
||||
works in his own words. (I’ve edited David’s text a bit, and added my
|
||||
That's the overall approach, but this being David Stafford, it's not
|
||||
that simple, of course. I'll let him tell you how his implementation
|
||||
works in his own words. (I've edited David's text a bit, and added my
|
||||
own comments in square brackets, so blame me for any errors.)
|
||||
|
||||
“Each three cells in the life grid are packed into two bytes, as shown
|
||||
"Each three cells in the life grid are packed into two bytes, as shown
|
||||
in Figure 18.1. So, it is convenient if the width of the cell array is
|
||||
an even multiple of three. There’s nothing in the algorithm that
|
||||
an even multiple of three. There's nothing in the algorithm that
|
||||
prevents it from supporting any arbitrary size, but the code is a bit
|
||||
simpler this way. So if you want a 200x200 grid, I recommend just using
|
||||
a 201x200 grid, and be happy with the extra free column. Otherwise the
|
||||
edge wrapping code gets more complex.
|
||||
|
||||
“Since every cell has from zero to eight neighbors, you may be wondering
|
||||
"Since every cell has from zero to eight neighbors, you may be wondering
|
||||
how I can manage to keep track of them with only three bits. Each cell
|
||||
really has only a maximum of seven neighbors since we only need to keep
|
||||
track of neighbors *outside* of the current cell word. That is, if cell
|
||||
‘B’ changes state then we don’t need to reflect this in the neighbor
|
||||
counts of cells ‘A’ and ‘C.’ Updating is made a little faster. [In other
|
||||
‘B' changes state then we don't need to reflect this in the neighbor
|
||||
counts of cells ‘A' and ‘C.' Updating is made a little faster. [In other
|
||||
words, when David picks up a word representing three cells, each of the
|
||||
three cells has at least one of the other cells in that word as a
|
||||
neighbor, and the state of that neighbor is stored right in that word,
|
||||
as shown in Figure 18.1. Therefore, the neighbor count for a given cell
|
||||
never needs to reflect more than seven neighbors, because at least one
|
||||
of the eight neighbors’ states is already encoded in the word.]
|
||||
of the eight neighbors' states is already encoded in the word.]
|
||||
|
||||
\
|
||||
**Figure 18.1** *Cell triplet storage.*
|
||||
|
|
|
|||
Loading…
Reference in a new issue