Exemplo n.º 1
0
// Restore a previously preserved exception to the frame.
NUITKA_MAY_BE_UNUSED static inline void RESTORE_FRAME_EXCEPTION( PyFrameObject *frame_object )
{
    if ( frame_object->f_exc_type )
    {
#if _DEBUG_EXCEPTIONS
        PRINT_STRING("RESTORE_FRAME_EXCEPTION: restoring preserved\n");
        PRINT_ITEM( (PyObject *)frame_object );
        PRINT_NEW_LINE();
#endif

        SET_CURRENT_EXCEPTION( frame_object->f_exc_type, frame_object->f_exc_value, (PyTracebackObject *)frame_object->f_exc_traceback );

        frame_object->f_exc_type = NULL;
        frame_object->f_exc_value = NULL;
        frame_object->f_exc_traceback = NULL;
    }
#if _DEBUG_EXCEPTIONS
    else
    {
        PRINT_STRING("RESTORE_FRAME_EXCEPTION: nothing to restore\n");
        PRINT_ITEM( (PyObject *)frame_object );
        PRINT_NEW_LINE();
    }
#endif
}
Exemplo n.º 2
0
// Preserve the current exception as the frame to restore.
NUITKA_MAY_BE_UNUSED static inline void PRESERVE_FRAME_EXCEPTION( PyFrameObject *frame_object )
{
    // Setting exception for frame if not already done.
    if ( frame_object->f_exc_type == NULL )
    {
        PyThreadState *thread_state = PyThreadState_GET();

        if ( thread_state->exc_type != NULL && thread_state->exc_type != Py_None )
        {
#if _DEBUG_EXCEPTIONS
            PRINT_STRING("PRESERVE_FRAME_EXCEPTION: preserve thread exception\n");
#endif
            frame_object->f_exc_type = thread_state->exc_type;
            Py_INCREF( frame_object->f_exc_type );
            frame_object->f_exc_value = thread_state->exc_value;
            Py_XINCREF( frame_object->f_exc_value );
            frame_object->f_exc_traceback = thread_state->exc_traceback;
            Py_XINCREF( frame_object->f_exc_traceback );
        }
        else
        {
#if _DEBUG_EXCEPTIONS
            PRINT_STRING("PRESERVE_FRAME_EXCEPTION: no exception to preserve\n");
#endif
            frame_object->f_exc_type = Py_None;
            Py_INCREF( frame_object->f_exc_type );
            frame_object->f_exc_value = NULL;
            frame_object->f_exc_traceback = NULL;
        }
    }
#if _DEBUG_EXCEPTIONS
    else
    {
        PRINT_STRING("PRESERVE_FRAME_EXCEPTION: already preserving\n");
    }

    PRINT_ITEM( (PyObject *)frame_object );
    PRINT_NEW_LINE();
    PRINT_EXCEPTION( frame_object->f_exc_type,  frame_object->f_exc_value, frame_object->f_exc_traceback );
#endif

}
Exemplo n.º 3
0
/* This Func Prints All Of The List */
void printList(List *ptrList)
{
	Node *tmpList;

	if(!ptrList)
	{
		NO_LIST;
		return;
	}

	tmpList=ptrList->start;

	if(ListIsEmpty(ptrList))
		LIST_IS_EMPTY;

	while(tmpList)
	{
		PRINT_ITEM(tmpList->data);
		tmpList=tmpList->next;
	}
}
void evaluate(pair_t *pair) {
#ifdef DEBUG
	int i;
	int x;
	int y;
#endif
	int s;
	int a;
	int new_pos_x_1;
	int new_pos_y_1;
	int new_pos_x_2;
	int new_pos_y_2;
	
	pair->fitness_value = 0;
	
	/* for each session */
	for (s = 0; s < SESSIONS_NUMBER; s++) {
		init_random_map();
		INIT_RANDOM_POSITIONS();
		
		/* for each action */
		for (a = 0; a < ACTIONS_PER_SESSION_NUMBER; a++) {
			
#ifdef DEBUG
			for (y = 0; y < MAP_HEIGHT; y++) {
				for (x = 0; x < MAP_WIDTH; x++) {
					printf(
						"|%c%c%c",
						IS_SAME_POSITION(pos_x_1, pos_y_1, x, y) ? '1' : ' ',
						PRINT_ITEM(GET_ITEM_INTO_MAP(x, y)),
						IS_SAME_POSITION(pos_x_2, pos_y_2, x, y) ? '2' : ' '
					);
				}
				printf("|\n");
			}
#endif
			
			/* update robbies views, indexes, actions */
			UPDATE_VIEWS();
			UPDATE_INDEXES();
			UPDATE_ACTIONS(pair);
			
#ifdef DEBUG
			printf("Robby 1: |");
			for (i = 0; i < VIEW_SIZE; i++)
				printf("%c|", PRINT_ITEM(view_1[i]));
			printf(
				(pair->robby_1[index_1] == RANDOM_ACTION) ?
				" -> dna[%d] -> random: %s\n" : " -> dna[%d] -> %s\n",
				index_1,
				PRINT_ACTION(action_1)
			);
			printf("Robby 2: |");
			for (i = 0; i < VIEW_SIZE; i++)
				printf("%c|", PRINT_ITEM(view_2[i]));
			printf(
				(pair->robby_2[index_2] == RANDOM_ACTION) ?
				" -> dna[%d] -> random: %s\n" : " -> dna[%d] -> %s\n",
				index_2,
				PRINT_ACTION(action_2)
			);
#endif
			
			/* update robbies new positions */
			new_pos_x_1 = pos_x_1;
			new_pos_y_1 = pos_y_1;
			new_pos_x_2 = pos_x_2;
			new_pos_y_2 = pos_y_2;
			UPDATE_POSITION(action_1, new_pos_x_1, new_pos_y_1);
			UPDATE_POSITION(action_2, new_pos_x_2, new_pos_y_2);
			
			/* evaluate robby 1 movement */
			if (IS_MOVEMENT_ACTION(action_1)) {
				if (
					(!IS_POSITION_INTO_MAP(new_pos_x_1, new_pos_y_1)) ||
					(IS_COLLABORATIVE_VIEW &&
					 IS_SAME_POSITION(new_pos_x_1, new_pos_y_1, new_pos_x_2, new_pos_y_2))
				)
					pair->fitness_value -= 5;
				else {
					pos_x_1 = new_pos_x_1;
					pos_y_1 = new_pos_y_1;
				}
			}
			
			/* evaluate robby 2 movement */
			if (IS_MOVEMENT_ACTION(action_2)) {
				if (
					(!IS_POSITION_INTO_MAP(new_pos_x_2, new_pos_y_2)) ||
					(IS_COLLABORATIVE_VIEW &&
					 IS_SAME_POSITION(new_pos_x_2, new_pos_y_2, new_pos_x_1, new_pos_y_1))
				)
					pair->fitness_value -= 5;
				else {
					pos_x_2 = new_pos_x_2;
					pos_y_2 = new_pos_y_2;
				}
			}
			
			/* evaluate robby 1 pick up */
			if (action_1 == PICK_UP) {
				if (map[pos_x_1][pos_y_1] == CAN) {
					map[pos_x_1][pos_y_1] = EMPTY;
					pair->fitness_value += 10;
				} else
					pair->fitness_value -= 1;
			}
			
			/* evaluate robby 2 pick up */
			if (action_2 == PICK_UP) {
				if (map[pos_x_2][pos_y_2] == CAN) {
					map[pos_x_2][pos_y_2] = EMPTY;
					pair->fitness_value += 10;
				} else if (action_1 != PICK_UP || !IS_SAME_POSITION(pos_x_1, pos_y_1, pos_x_2, pos_y_2))
					pair->fitness_value -= 1;
			}
#ifdef DEBUG
			printf("Fitness: %f\n", pair->fitness_value);
#endif
		}
#ifdef DEBUG
		printf("\n\n");
#endif
	}
	
	pair->fitness_value = (double) pair->fitness_value / (double) SESSIONS_NUMBER;
}