/*
    第2種情報処理技術者試験    平成12年度・秋期・午後 問11
                                BohYoh Shibata PREPARATION
*/

#include  <stdio.h>
#define   ON        1
#define   OFF       0
#define   HIT       1
#define   CMAX      16
#define   BLKSZ     24
#define   MGNCNT    200
#define   DSPCNT    250
#define   STOP      3000

typedef struct { int flg; int st; } mbox;
int  rand16(void);
int  sense( int*, int* );
void mogura( char*, int, int );
main(void) {
    int mflg=OFF, hitpt=0;
    int hitck[BLKSZ][BLKSZ], gcnt, gx, gy, ix, iy;
    mbox mg[CMAX][CMAX];
    for ( ix=0; ix<CMAX; ix++ )
        for ( iy=0; iy<CMAX; iy++ ) {
            mg[ix][iy].flg = OFF;
            mg[ix][iy].st = 0;
        }
    for ( ix=0; ix<BLKSZ; ix++ )
        for ( iy=0; iy<BLKSZ; iy++ ) hitck[ix][iy] = HIT;
    for ( gcnt=0; gcnt<STOP; gcnt++ ) {
        if ( gcnt % MGNCNT == 0 ) {
            ix = rand16();
            iy = rand16();
            if ( mg[ix][iy].flg == OFF ) {
                mg[ix][iy].flg = ON;
                mg[ix][iy].st = gcnt;
                mogura( "open", ix, iy );
            }
        }
        mflg = sense( &gx, &gy );
        if ( mflg == ON ) {
            if ( mg[gx/BLKSZ][gy/BLKSZ].flg == ON &&
                 hitck[gx%BLKSZ][gy%BLKSZ] == HIT ) {
                hitpt += 10;
                mogura( "hit", gx/BLKSZ, gy/BLKSZ );
                mg[gx/BLKSZ][gy/BLKSZ].flg = OFF;
                mg[gx/BLKSZ][gy/BLKSZ].st = 0;
            }
            else hitpt--;
        }
        for ( ix=0; ix<CMAX; ix++ ) {
            for ( iy=0; iy<CMAX; iy++ )
                if ( mg[ix][iy].flg == ON ) {
                    if ( (gcnt-mg[ix][iy].st)>DSPCNT ) {
                        mg[ix][iy].flg = OFF;
                        mg[ix][iy].st = 0;
                        mogura( "close", ix, iy );
                    }
                }
        }
    }
    printf( "ゲーム終了\nあなたの得点は%dです\n", hitpt );
}