#import "grid.h"

#define __USE_FIXED_PROTOTYPES__   // for gcc headers
#include <stdio.h>

int compareIntegers( id a, id b )
{
  if ( (int)a < (int)b ) return -1;
  return ( (int)a > (int)b );
}

int main(void)
{
  id aZone, aMap, aTurtle, index;
  int i;

  initModule( grid );

  aZone = [Zone create: globalZone];
  aMap  = [Map createBegin: aZone];
  [aMap setCompareFunction: compareIntegers];
  aMap = [aMap createEnd];

  printf( "count: %d\n", [aMap count] );

  for ( i = 0; i < 10; i++ ) {
    aTurtle = [GridTurtle create: aZone];
    [aTurtle turn: -1];
    [aTurtle move: (10 - i) * 10];
    [aMap at: (id)(10 - i) insert: aTurtle];
  }

  printf( "count: %d\n", [aMap count] );

  index = [aMap begin: aZone];
  while ( (aTurtle = [index next]) ) {
    printf( "%d: ", (int)[index getKey] );
    [aTurtle print];
  }
  [index drop];

  [[aMap first] print];
  [[aMap last] print];
  return 0;
}
