home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / games / volume11 / blockbuster / part03 / stagemm.c < prev    next >
C/C++ Source or Header  |  1990-08-10  |  3KB  |  130 lines

  1. /*
  2.  * File:       smm.c
  3.  * Author:     Eric Van Gestel
  4.  *
  5.  * Aux. For:   blockbuster
  6.  *
  7.  * Implementation:
  8.  *     Calculates a minimum and approximate maximum score for the stage.
  9.  *     If there are both 'D's or 'T's and 'U's, this tends to grow rapidly.
  10.  */
  11.  
  12. #include "blockbuster.h"
  13.  
  14. void
  15. main( argc, argv )
  16.     int             argc;
  17.     char           *argv[];
  18.  
  19. {
  20.     FILE           *fd;
  21.     char            buf[MAX_COL + 3];
  22.     register int    row, col, tmp;
  23.     register int    codes[256];    /* indexed by char */
  24.  
  25.     for ( tmp = 0; tmp < 256; )
  26.         codes[tmp++] = 0;
  27.  
  28.     /* open stage file */
  29.     if ( !( fd = fopen( argv[1], "r" ) ) ) {
  30.         perror( "Can't open stage" );
  31.         exit( 1 );
  32.     }
  33.     /* read stage name */
  34.     fscanf( fd, "%s\n", stage_name );
  35.     printf( "%>>> %s:", stage_name );
  36.  
  37.     /* read pallet dimensions */
  38.     fscanf( fd, "%d%d\n", &pallet_lengthI, &pallet_heightI );
  39.     if ( pallet_lengthI < MIN_PALLET_LENGTH ||
  40.          pallet_lengthI > MAX_PALLET_LENGTH ||
  41.          pallet_heightI < pallet_lengthI ||
  42.          pallet_heightI > MAX_PALLET_HEIGHT ) {
  43.         perror( "Inconsistent pallet dimensions" );
  44.         exit( 1 );
  45.     }
  46.     /* read stage map */
  47.     for ( row = 0; row <= MAX_ROW; row++ ) {
  48.         if ( !fgets( buf, MAX_COL + 3, fd ) ) {
  49.             perror( "Can't read stage" );
  50.             exit( 1 );
  51.         }
  52.         for ( col = 0; col <= MAX_COL; col++ )
  53.             codes[buf[col]]++;
  54.     }
  55.     fclose( fd );
  56.  
  57.     /* minimax approximation */
  58.     score = codes['1']
  59.         + codes['2'] * 3
  60.         + codes['3'] * 6
  61.         + codes['4'] * 10
  62.         + codes['5'] * 15
  63.         + codes['6'] * 21
  64.         + codes['7'] * 28
  65.         + codes['8'] * 36
  66.         + codes['9'] * 45;
  67.     printf( " from %d", score );
  68.     score += codes['I'] * 2
  69.         + codes['a'] * 10
  70.         + codes['b'] * 20
  71.         + codes['c'] * 30
  72.         + codes['d'] * 40
  73.         + codes['e'] * 50
  74.         + codes['j'] * 100;
  75.     for ( tmp = codes['D']; tmp; tmp-- )
  76.         score *= 2;
  77.     for ( tmp = codes['T']; tmp; tmp-- )
  78.         score *= 3;
  79.     if ( codes['U'] ) {
  80.         if ( codes['T'] )
  81.             for ( tmp = codes['U']; tmp; tmp-- )
  82.                 score *= 3;
  83.         else if ( codes['D'] )
  84.             for ( tmp = codes['U']; tmp; tmp-- )
  85.                 score *= 2;
  86.         else if ( codes['j'] )
  87.             score += codes['U'] * 100;
  88.         else if ( codes['e'] )
  89.             score += codes['U'] * 50;
  90.         else if ( codes['9'] )
  91.             score += codes['U'] * 45;
  92.         else if ( codes['d'] )
  93.             score += codes['U'] * 40;
  94.         else if ( codes['8'] )
  95.             score += codes['U'] * 36;
  96.         else if ( codes['c'] )
  97.             score += codes['U'] * 30;
  98.         else if ( codes['7'] )
  99.             score += codes['U'] * 28;
  100.         else if ( codes['6'] )
  101.             score += codes['U'] * 21;
  102.         else if ( codes['b'] )
  103.             score += codes['U'] * 20;
  104.         else if ( codes['5'] )
  105.             score += codes['U'] * 15;
  106.         else if ( codes['4'] )
  107.             score += codes['U'] * 11;
  108.         else if ( codes['a'] )
  109.             score += codes['U'] * 10;
  110.         else if ( codes['3'] )
  111.             score += codes['U'] * 6;
  112.         else if ( codes['2'] )
  113.             score += codes['U'] * 3;
  114.         else if ( codes['I'] )
  115.             score += codes['U'];
  116.         else if ( codes['1'] )
  117.             score += codes['U'];
  118.     }
  119.     printf( " to %d", score );
  120.     if ( codes['0'] )
  121.         printf( " and more" );
  122.     printf( "\n" );
  123.  
  124.     /* verify stage map */
  125.     if ( codes['/'] + codes['\\'] != 1 )
  126.         printf( "*** no or several launchpads\n" );
  127.     if ( codes['A'] && codes['^'] != 1 )
  128.         printf( "*** no or several emitters\n" );
  129. }
  130.