| Life Game Demo Sample Code
void LifeDemo( void )
{
char inputChar;
char theExpression[ 128 ];
char szDemoFile[ 128 ];
LZObjectHandle hTheExpression = 0;
long lCycleIndex = 0;
long lGridLineIndex = 0;
long lDefineOpResult = 0;
lzCreatePublicContext( "LifeContext" );
lzSetContext( "LifeContext", false );
sprintf( szDemoFile, "%s%s", TEST_FILE_PATH_PREFIX, "initlife.lzo" );
lDefineOpResult = lzReadExpOp( kGlobalScope,
"initlife",
"nofix",
"void",
NULL,
"sin",
szDemoFile );
if ( lDefineOpResult )
{
cout << "Failed to load INITLIFE operator.\r\n";
cout << lzGetLastErrorText() << "\r\n\n";
}
lDefineOpResult = lzDefineExpOp( kGlobalScope,
"life",
"nofix",
"void",
NULL,
"sin",
NULL );
sprintf( szDemoFile, "%s%s", TEST_FILE_PATH_PREFIX, "life.lzo" );
lDefineOpResult = lzReadExpOpStr( kGlobalScope,
"life",
szDemoFile );
if ( lDefineOpResult )
{
cout << "Failed to load LIFE operator.\r\n";
cout << lzGetLastErrorText() << "\r\n\n";
}
strcpy( theExpression, "initlife" );
lzEvalExpStrToStr( theExpression );
strcpy( theExpression, "life" );
hTheExpression = lzParseExp( theExpression );
for ( lCycleIndex = 0; lCycleIndex < 50; lCycleIndex++ )
{
lzEvalExpHndlToStr( hTheExpression );
cout << " Generation " << (lCycleIndex + 1) << '\n';
cout << "+----------------+" << '\n';
for ( lGridLineIndex = 15; lGridLineIndex >= 0; lGridLineIndex-- )
{
cout << "|" << lzGetStrArrayElement( kGlobalScope,
"board",
1, lGridLineIndex, 0, 0, 0, 0, 0 ) << "|" << '\n';
}
cout << "+----------------+" << '\n';
cout.flush();
inputChar = '\0';
inputChar = getchar();
if ( inputChar == '\\' )
break;
}
lzDestroyPublicContext( "LifeContext" );
}
|