示例#1
0
文件: arr.cpp 项目: mykwillis/arr
int main(int argc, char **argv)
{
    int c;
    int i=0;

    Physics = 1;
    PulsePeriod = 0;

    WorldSnapshotGeneration = 1000;
    CycleDetectedGeneration = 0;
    PrintInterval = 5000;

    if ( argc > 1 )
        Physics = atoi( argv[1] );
    if ( argc > 2 )
        PulsePeriod = atoi( argv[2] );

    printf( "Using physics %d.\n", Physics);

    GenerateRandomWorld();

    do {

        if ( !(Generation % PrintInterval) )
            PrintWorld();

        AgeWorldByUniformPhysics();

        CheckForCycle();

        if ( _kbhit() )
            c = _getch();

        if ( c == ' ' ) {
            c = _getch();
        }

    //} while ( !_kbhit() || _getch() != 'q' );
    } while ( c != 'q' && CycleDetectedGeneration == 0 );

    printf("Physics used:          %d\n", Physics);
    printf("Number of generations: %d\n", Generation);
    if ( CycleDetectedGeneration != 0 ) {
        printf("World at generation %d repeated at generation %d\n", 
            WorldSnapshotGeneration, CycleDetectedGeneration);
    }

    return 0;
}
void ShowMovie(char*** world, int maxTicks, int rows, int columns, SDL_Surface* screen, SDL_Rect *Rect, int rectH, int rectW)
{
	//primitives
	
	//n will equal the size of the inputted world
		//which is basically the maximum columns
	//m is therefore the maxiumum rows.
	//m,n come from printworld
	//NB this will change when reading in a file
	//m and n will be the first row of textfile
	//There needs to be a 3d world variable.
	//char newWorld[rows][columns];
    int i, j;
	
	//actually draw the 'movie'
	//will use the defined delay
			
			//i have made i = 1 because the example windows exe
			//has this. it runs from 1 to 9 meaningh it skips 1
	for (i = 0; i<maxTicks; i++)
	{
		//print the world
		PrintWorld(world[i], rows, columns, screen, *Rect, rectH, rectW);
		//copy the new world
		//CopyWorld(world, newWorld, m, n, rows, columns, i);
		//animate ie clear the world thats all it does
		Animate(i);
		//get next generation of the world and store it
		NextGeneration(world[i], world[i+1], rows, columns);
		//check its status
        if(compareWorld(world[i], world[i-1], rows, columns) == TRUE)
        {
        	// stable....
            printf("The World is Stable.\n");	
        }
		else
		{
			for(j = 0; j < i - 1; j++)
			{
				if(compareWorld(world[i], world[j], rows, columns) == TRUE)
				{
					// print osc period is i-j....
					printf("The Worlds are Osciallting at a period of %d.\n", (i-j));
				}
                
			}
		}  
	}		
}