コード例 #1
0
ファイル: npc.c プロジェクト: c-neves/pinky-dinky-doo-revenge
void update_NPCs( NPC** _NPCs, int _NPCCount, bomb* _pBomb, map* _pMap )
{
    // loop through all NPCs
    int i;
    for ( i = 0; i < _NPCCount; i++ )
    {
        // update NPC's coordinates atributes
        _NPCs[i]->right  = _NPCs[i]->left + GC_block_size;
        _NPCs[i]->bottom = _NPCs[i]->top  + GC_block_size;

        _NPCs[i]->i = ( ( (_NPCs[i]->top + GC_block_size/2) - GC_y_offset) / GC_block_size );
        _NPCs[i]->j = ( (_NPCs[i]->left + GC_block_size/2) / GC_block_size );

        // invoke NPC's artificial intelligence, but not every loop
        // delay the artificial intelligence, it mustn't run each loop
        if ( time_is_up( _NPCs[i]->AI_timer ) )
        {
            //_NPCs[i]->p_NPC_AI( _pGame );

            NPC_random_walk_AI( _NPCs[i], _pBomb, _NPCs, _NPCCount, _pMap );

            reset_timer( _NPCs[i]->AI_timer );
        }
        else
        {
            // delay the NPC's walk
            if ( time_is_up( _NPCs[i]->walk_timer ) )
            {
                NPC_walk( _NPCs[i], _pBomb, _NPCs, _NPCCount, _pMap, _NPCs[i]->direction );

                reset_timer( _NPCs[i]->walk_timer );
            }
        }
    }
}
コード例 #2
0
ファイル: search2.c プロジェクト: zwegner/zct
/**
stop_search():
This checks for time and input to see if need to stop searching.
Created 091006; last modified 030709
**/
BOOL stop_search(void)
{
	CMD_RESULT cmd_result;
	BOOL stop = FALSE;
	GAME_ENTRY *current;

	if (zct->stop_search)
		stop = TRUE;
	/* Check for input, because we might enter this function more than once
		before fully stopping when unwinding the stack. */
	else if (zct->input_buffer[0])
		stop = TRUE;
	else if (time_is_up())
		stop = TRUE;
	else if (input_available())
	{
		/* Return to the root position. Some commands, such as "display" work
			on the root position instead of the current one. */
		current = board.game_entry;
		while (board.game_entry > root_entry)
			unmake_move();
		/* When pondering, the root entry is after the ponder move. */
		if (zct->engine_state == PONDERING)
			unmake_move();
		/* Read the command and parse it. */
		read_line();
		cmd_result = command(zct->input_buffer);
		/* Command() returns CMD_STOP_SEARCH when we need to exit the search to
			handle a command. */
		if (cmd_result == CMD_STOP_SEARCH)
			stop = TRUE;
		/* If the command was a move, either stop or make the move. */
		else if (zct->engine_state != NORMAL && cmd_result == CMD_BAD &&
			input_move(zct->input_buffer, INPUT_CHECK_MOVE))
		{
			/* If we are pondering, check if the move entered was the ponder
				move. If so, we don't need to stop. */
			if (zct->engine_state == PONDERING && input_move(zct->input_buffer,
				INPUT_GET_MOVE) == zct->ponder_move)
			{
				zct->input_buffer[0] = '\0';
				make_move(zct->ponder_move);
				zct->engine_state = NORMAL;
				update_clocks();
			}
			else
				stop = TRUE;
		}
		else if (cmd_result == CMD_BAD)
		{
			zct->input_buffer[0] = '\0';
			if (zct->protocol != UCI)
				print("Error.\n");
		}

		/* Check for ping here in UCI mode. */
		if (zct->ping && zct->protocol == UCI)
		{
			print("readyok\n");
			zct->ping = 0;
		}
		/* Go back to the position we were in before checking. This is kind of
			hacky in that it relies on the game history after undoing all the
			moves to be the same. */
		while (board.game_entry < current)
			make_move(board.game_entry->move);
	}

	/* If we're stopping the search, set a flag to make sure we don't come
		back here and decide to keep going, thereby introducing bugs... */
	if (stop)
		zct->stop_search = TRUE;

	return stop;
}
コード例 #3
0
ファイル: npc.c プロジェクト: c-neves/pinky-dinky-doo-revenge
void update_NPCs_frames( NPC** _NPCs, int _NPCCount )
{
    int i;
    for ( i = 0; i < _NPCCount; i++ )
    {
        if ( time_left( _NPCs[i]->frame_timer ) <= GC_NPC_frames_duration / 3.0 )  // 1st frame
        {
            switch( _NPCs[i]->direction )
            {
                case UP:
                {
                    _NPCs[i]->up_frame_index = 0;
                    break;
                }

                case RIGHT:
                {
                    _NPCs[i]->right_frame_index = 0;
                    break;
                }

                case DOWN:
                {
                    _NPCs[i]->down_frame_index = 0;
                    break;
                }

                case LEFT:
                {
                    _NPCs[i]->left_frame_index = 0;
                    break;
                }
            }
        }
        else if ( time_left( _NPCs[i]->frame_timer ) <= 2.0 * GC_NPC_frames_duration / 3.0 )   // 2nd frame
        {
            switch( _NPCs[i]->direction )
            {
                case UP:
                {
                    _NPCs[i]->up_frame_index = 1;
                    break;
                }

                case RIGHT:
                {
                    _NPCs[i]->right_frame_index = 1;
                    break;
                }

                case DOWN:
                {
                    _NPCs[i]->down_frame_index = 1;
                    break;
                }

                case LEFT:
                {
                    _NPCs[i]->left_frame_index = 1;
                    break;
                }
            }
        }
        else    // 3rd frame
        {
            switch( _NPCs[i]->direction )
            {
                case UP:
                {
                    _NPCs[i]->up_frame_index = 2;
                    break;
                }

                case RIGHT:
                {
                    _NPCs[i]->right_frame_index = 2;
                    break;
                }

                case DOWN:
                {
                    _NPCs[i]->down_frame_index = 2;
                    break;
                }

                case LEFT:
                {
                    _NPCs[i]->left_frame_index = 2;
                    break;
                }
            }
        }

        if ( time_is_up( _NPCs[i]->frame_timer ) )
            reset_timer( _NPCs[i]->frame_timer );
    }
}