evolve4src/src/evolve_simulator/cell.cpp
void Cell_Simulate(CELL *c)
{
	ORGANISM *o;
	int before, after, usage;

	ASSERT( c != NULL );
	ASSERT( ! c->kfm->terminated );

	o = c->organism;

	before = (c->kfm->call_stack_size + c->kfm->data_stack_size) - NOCOST_STACK;
	if( before < 0 ) {
		before = 0;
	}

	kforth_machine_execute(c->kfm);

	after = (c->kfm->call_stack_size + c->kfm->data_stack_size) - NOCOST_STACK;
	if( after < 0 ) {
		after = 0;
	}

	usage = (after - before);

	if( usage <= o->energy ) {
		o->energy -= usage;
	} else {
		kforth_machine_reset(c->kfm);
		c->kfm->terminated = 1;
		o->energy += before;
	}

}
/***********************************************************************
 * Simulate Cell
 *
 * We execute the KFORTH engine 1 execution step.
 * The change in stack size, will alter the amount of
 * energy we have.
 *
 * If a cell terminates, it dies.
 *
 * We compute the change in the stack usage of executing
 * the cell's KFORTH_MACHINE 1 step. This amount of stack
 * usage will decrease the amount of energy the organism
 * has. If we use more stack space than energy in the organism,
 * then we kill the cell and restore the cells stack usage BEFORE
 * to the organisms energy.
 *
 */
Simulate Cell
We execute the KFORTH engine 1 execution step.
The change in stack size, will alter the amount of
energy we have.

If a cell terminates, it dies.

We compute the change in the stack usage of executing
the cell's KFORTH_MACHINE 1 step. This amount of stack
usage will decrease the amount of energy the organism
has. If we use more stack space than energy in the organism,
then we kill the cell and restore the cells stack usage BEFORE
to the organisms energy.
Simulate Cell We execute the KFORTH engine 1 execution step . The change in stack size will alter the amount of energy we have . If a cell terminates it dies . We compute the change in the stack usage of executing the cell ' s KFORTH_MACHINE 1 step . This amount of stack usage will decrease the amount of energy the organism has . If we use more stack space than energy in the organism then we kill the cell and restore the cells stack usage BEFORE to the organisms energy .
void Cell_Simulate(CELL *c)
{
	ORGANISM *o;
	int before, after, usage;
	ASSERT( c != NULL );
	ASSERT( ! c->kfm->terminated );
	o = c->organism;
	before = (c->kfm->call_stack_size + c->kfm->data_stack_size) - NOCOST_STACK;
	if( before < 0 ) {
		before = 0;
	}
	kforth_machine_execute(c->kfm);
	after = (c->kfm->call_stack_size + c->kfm->data_stack_size) - NOCOST_STACK;
	if( after < 0 ) {
		after = 0;
	}
	usage = (after - before);
	if( usage <= o->energy ) {
		o->energy -= usage;
	} else {
		kforth_machine_reset(c->kfm);
		c->kfm->terminated = 1;
		o->energy += before;
	}
}
void Cell_Simulate ( CELL * c ) { ORGANISM * o ; int before , after , usage ; ASSERT ( c != NULL ) ; ASSERT ( ! c -> kfm -> terminated ) ; o = c -> organism ; before = ( c -> kfm -> call_stack_size + c -> kfm -> data_stack_size ) - NOCOST_STACK ; if ( before < 0 ) { before = 0 ; } kforth_machine_execute ( c -> kfm ) ; after = ( c -> kfm -> call_stack_size + c -> kfm -> data_stack_size ) - NOCOST_STACK ; if ( after < 0 ) { after = 0 ; } usage = ( after - before ) ; if ( usage <= o -> energy ) { o -> energy -= usage ; } else { kforth_machine_reset ( c -> kfm ) ; c -> kfm -> terminated = 1 ; o -> energy += before ; } }
Simulate Cell
 We execute the KFORTH engine 1 execution step.
Simulate Cell We execute the KFORTH engine 1 execution step .