Exemplo n.º 1
0
bool Map::isWalkable(int x, int y) {
	if ( validPosition(x, y) ) {
		return map[y][x] == WALKABLE ? true : false;
	}

	return false;
}
Exemplo n.º 2
0
/*
 *	Accesses the intersection at the specified coordinate and pops the
 * 		vehicle from the deque specified by the direction param.
 *	Note: Potential NullRef if there is no intersection at the 
 *		specified coordinate in the map
 *	parameters:
 *		row - row number of the map to access each intersection
 *		col - column number of the map to access each intersection
 *		d - direction to access the queue of an exiting vehicle.
 */
int grid::exitVehicle(int row, int col, int d)
{
    if (validPosition(row, col))
    {
        if (d == NORTH)
        {
            return map[row][col].exitNorth();
        }
        else if (d == SOUTH)
        {
            return map[row][col].exitSouth();
        }
        else if (d == EAST)
        {
            return map[row][col].exitEast();
        }
        else if (d == WEST)
        {
            return map[row][col].exitWest();
        }
        else
        {
            return -1;
        }
    }
    else
    {
        return -1;
    }
}
Exemplo n.º 3
0
/*
 * adds an intersection object at the specified coordinates in the map.
 * 	Note: If intersection is already at the specified coordinate,
 *			addIntersection will overwrite the intersection currently
 *			stored there.
 *	Parameters:
 *	row - row number of the map to insert the intersection parameter into.
 *	col - column number of the map to inset the intersection parameter into.
 *	intersection - the intesection object to add to the map.
 */
void grid::addIntersection(int row, int col, intersection i)
{
    if (validPosition(row, col))
    {
        map[row][col] = i;
    }
}
Exemplo n.º 4
0
bool performAction(char code){
	printf("\tPerforming action %c on %d,%d %c\n",code,x,y,orientation);
	if (code == 'L' || code == 'R'){
		orientation = getNewOrientation(code == 'L');
		printf("\t\tChanging orientation to %c\n", orientation);
		return true;
	} else if (code == 'F') {
		int oldX = x;
		int oldY = y;
		move();
		if (validPosition(x,y)){
			printf("\t\tMoving to %d, %d\n", x,y);
			world[x][y] = rNum;
			return true;
		} else if (existsHint(oldX, oldY)){
			printf("\t\tIgnoring order to move to %d,%d\n", x,y);
			int x = oldX;
			int y = oldY;
			return true;
		} else {
			printf("\t\tRobot lost in position %d,%d\n", x,y);
			return false;
		}
	} else {
		world[x][y] = rNum;
		printf("\t\tStay in %d, %d\n", x,y);
		return true;
	}
}
Exemplo n.º 5
0
// Return the fragment of text after an offset.
QString QsciAccessibleScintillaBase::textAfterOffset(int offset,
        QAccessible::TextBoundaryType boundaryType, int *startOffset,
        int *endOffset) const
{
    QsciScintillaBase *sb = sciWidget();

    // Initialise in case of errors.
    *startOffset = *endOffset = -1;

    int position = validPosition(offset);

    if (position < 0)
        return QString();

    int start_position, end_position;

    if (!boundaries(sb, position, boundaryType, &start_position, &end_position))
        return QString();

    if (end_position >= sb->SendScintilla(QsciScintillaBase::SCI_GETTEXTLENGTH))
        return QString();

    if (!boundaries(sb, end_position, boundaryType, &start_position, &end_position))
        return QString();

    positionRangeAsOffsetRange(sb, start_position, end_position, startOffset,
            endOffset);

    return textRange(sb, start_position, end_position);
}
Exemplo n.º 6
0
void KoColorPanel::keyPressEvent( QKeyEvent* e )
{
    Position newPos( validPosition( m_focusPosition ) );
    if ( e->key() == Qt::Key_Up ) {
        if ( newPos.y == 0 )
            e->ignore();
        else
            --newPos.y;
    }
    else if ( e->key() == Qt::Key_Down ) {
        if ( newPos < Position( m_colorMap.count() % COLS, lines() - 2 ) )
            ++newPos.y;
        else
            e->ignore();
    }
    else if ( e->key() == Qt::Key_Left ) {
        if ( newPos.x == 0 )
            e->ignore();
        else
            --newPos.x;
    }
    else if ( e->key() == Qt::Key_Right ) {
        if ( newPos.x < COLS - 1 && newPos < Position( m_colorMap.count() % COLS - 1, lines() - 1 ) )
            ++newPos.x;
        else
            e->ignore();
    }
    else if ( e->key() == Qt::Key_Return ) {
        if ( isVisible() && parentWidget() && parentWidget()->inherits( "QPopupMenu" ) )
            parentWidget()->close();
        emit colorSelected( mapToColor( m_focusPosition ) );
    }
    updateFocusPosition( newPos );
}
Exemplo n.º 7
0
bool validateMove(Move* move, char** board, int player) {
	if(!validPosition(move->from) || !allPositionsAreValid(move->to)) {
		printMessage(INVALID_POSITION);
		return false;
	}
	if(!playerInPosition(move->from, board, player)) {
		printMessage(NO_DISC);
		return false;
	}
	if(!moveInLegalMoves(move, board, player)) {
		printMessage(ILLEGAL_MOVE);
		return false;
	}
	return true;
}
Exemplo n.º 8
0
/*
 *	Accesses the intersection at the specified coordinates on the map,
 *		and pushes it onto the directional deque of that intersection
 *	NOTE: potential NullRef if there is no intersection at the 
 *		specific coordinates.
 *	parameters:
 *	row - row number of the map to access the intersection.
 *	col - column number of the map to access the intersection.
 *	vehicle - vehicle number to enter.
 *	direction - direction vehicle is traveling.
 */
void grid::enterVehicle(int row, int col, int vehicle, int d)
{
    if (validPosition(row, col))
    {
        if (d == NORTH)
        {
            map[row][col].enterNorth(vehicle);
        }
        else if (d == SOUTH)
        {
            map[row][col].enterSouth(vehicle);
        }
        else if (d == EAST)
        {
            map[row][col].enterEast(vehicle);
        }
        else if (d == WEST)
        {
            map[row][col].enterWest(vehicle);
        }
    }
}
/**
 * Function to find the number of positions that 'MAX_QUEENS'
 * can be placed in a chess board of 'MAX_QUEENS' size.
 * The total count is tracked in a global variable called 'totalSolutions'.
 */
void findQueens(position q[MAX_QUEENS], int numQueens){

	if (numQueens >= MAX_QUEENS){
		totalSolutions++;
		printSolution(q, numQueens);
		return;
	}

	int i;
	for(i=0; i<MAX_QUEENS; ++i){

			if (validPosition(q, numQueens, i) == false){
				continue;
			}

			q[numQueens].x = numQueens;
			q[numQueens].y = i;

			findQueens(q, numQueens+1);
	}

}
Exemplo n.º 10
0
void Map::setPosition(int x, int y, MapValue value) {
	if ( validPosition(x, y) )
		map[y][x] = value;
}
Exemplo n.º 11
0
int Map::getPosition(int x, int y) {
	if ( validPosition(x, y) )
		return map[y][x];

	return OUT_OF_RANGE;
}