当前位置: 首页>>代码示例>>C++>>正文


C++ Maze::getCell方法代码示例

本文整理汇总了C++中Maze::getCell方法的典型用法代码示例。如果您正苦于以下问题:C++ Maze::getCell方法的具体用法?C++ Maze::getCell怎么用?C++ Maze::getCell使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Maze的用法示例。


在下文中一共展示了Maze::getCell方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: getNumberOfVisitedCells

int Arena::getNumberOfVisitedCells(Maze& m) {
    int count = 0;
    //for each cell in the maze
    for (int i = 0; i < m.getRows(); i++) {
        for (int j = 0; j < m.getCols(); j++) {
            //if cell has been visited, increase count
            if (m.getCell(i,j)->isVisited()) count++;
        }
    }
    return count;
}
开发者ID:mhuff17861,项目名称:GeneticAlgorithm,代码行数:11,代码来源:Arena.cpp

示例2: runSimulation

double Arena::runSimulation(Maze& maze, Robot& r) {
	//reset maze
	maze.clearVisited();
	maze.clearValues();

	//set needed values after reset
	Cell* curCell = maze.getStartCell();
	robotOrientation = direction::SOUTH;
	unsigned int move;
	double score;

	//while the robot is not in the same cell facing the same direction
	while (!repeat(robotOrientation, curCell->getValue()) && !(curCell == maze.getEndCell())) {
		//set current cell to visited and update it's value
		curCell->setVisited();
		curCell->setValue(curCell->getValue() + robotOrientation);

		//send the robot the environment and get it's next move
		move = r.getMove(getEnv(robotOrientation, curCell));

		//perform next move

		//find rotation
		if (move == 3 || move == 7) {
			robotOrientation = Direction::left(robotOrientation);
		}
		else if (move == 2 || move == 6) {
			robotOrientation = Direction::opposite(robotOrientation);
		}
		else if (move == 1 || move == 5) {
			robotOrientation = Direction::right(robotOrientation);
		}
		else {
			//no rotation
		}

		//move forwards
		if (!curCell->hasWall(robotOrientation) && !curCell->hasEdge(robotOrientation)) {
			curCell = maze.getCell(curCell->getRow() + Direction::row(robotOrientation), curCell->getCol() + Direction::col(robotOrientation));
		}
	}

	//calculate score    
	//score is a 1 if the end has been reached, else it is 1 - (distance from end * 0.01)
	if (curCell == maze.getEndCell()) {
		score = 1.0;
	}
	else {
		score = (double)getNumberOfVisitedCells(maze) / (double)((double)maze.getRows() * (double)maze.getCols());
	}
	//return score
	return score;
}
开发者ID:mhuff17861,项目名称:GeneticAlgorithm,代码行数:53,代码来源:Arena.cpp

示例3: findAllThePaths

void FindPathsFromXtoY::findAllThePaths(Maze& mazeT, Cell* startC, Cell* finalC)
{
	currentPath.pathVec.push_back(startC);
	currentPath.sizeOfPath++;
	startC->isCovered = true;

    if(startC->row == finalC->row &&
       startC->col == finalC->col)
    {
        allThePaths.push_back(currentPath);

        /*std::cout << "Current situation: " << std::endl;
        printAllThePaths();*/

        // currentPath.clear();
        // currentPath.pathVec.push_back(startCell);

        return;
    }



    for(int i = 0; i < 4; i++)
    {
        if(startC->row + xMoves[i] >= 0 &&
           startC->row + xMoves[i] < mazeT.getRows() &&
           startC->col + yMoves[i] >=0 &&
           startC->col + yMoves[i] < mazeT.getCols())
        {
            Cell* stepCell = mazeT.getCell(startC->row + xMoves[i], startC->col + yMoves[i]);
            if(stepCell &&
			   stepCell->isCovered == false &&
               stepCell->isOkayToPass())
            {
                // currentPath.push_back(stepCell);
                findAllThePaths(mazeT,stepCell,finalC);

				currentPath.pathVec.pop_back();
				currentPath.sizeOfPath--;
				stepCell->isCovered = false;
            }
        }
    }

    // startC->isCovered = false;
}
开发者ID:tsanislavgatev,项目名称:SDP,代码行数:46,代码来源:FindPathsFromXtoY.cpp

示例4: move_to_hero

bool Computer::move_to_hero(Maze& level_map)
{
    Point lu_cornor;
    Point rd_cornor;
    Point point;
    unsigned step = 1;
    Point hero_position = position;
    unsigned hero_review = review;
    bool end = false;

    unsigned ** screen;
    unsigned size_screen = (review * 2 + 1);
    screen = new unsigned*[size_screen];
    for (auto i = 0U; i < size_screen; ++i)
        screen[i] = new unsigned[size_screen];
    for (auto i = 0U; i < size_screen; ++i)
        for (auto j = 0U; j < size_screen; ++j)
            screen[i][j] = 0;


    screen[hero_review][hero_review] = 1;
    while (step <= hero_review)
    {
        lu_cornor.x = hero_position.x - (step-1);
        lu_cornor.y = hero_position.y - (step-1);
        rd_cornor.x = hero_position.x + (step-1);
        rd_cornor.y = hero_position.y + (step-1);

        for (int i = lu_cornor.y; i <= rd_cornor.y; i++)
            for (int j = lu_cornor.x; j <= rd_cornor.x; j++)
            {
                if (!level_map.isExistance(i, j)) continue;
                point.y = i - hero_position.y + hero_review;
                point.x = j - hero_position.x + hero_review;
                if (screen[point.y][point.x] == step && level_map.getCell(i, j) != '#')
                {
                    if (level_map.isExistance(i - 1, j) && (point.y - 1 >= 0))
                        if (screen[point.y - 1][point.x] == 0)
                            screen[point.y - 1][point.x] = step + 1;

                    if (level_map.isExistance(i + 1, j) && ((unsigned)point.y + 1 < size_screen))
                        if (screen[point.y + 1][point.x] == 0)
                            screen[point.y + 1][point.x] = step + 1;

                    if (level_map.isExistance(i, j - 1) && (point.x - 1 >= 0))
                        if (screen[point.y][point.x  - 1] == 0)
                            screen[point.y][point.x - 1] = step + 1;

                    if (level_map.isExistance(i, j + 1) && ((unsigned)point.x + 1 < size_screen))
                        if (screen[point.y][point.x + 1] == 0)
                            screen[point.y][point.x + 1] = step + 1;
                }
            }

        step++;
    }

    for (auto i = 0U; i < size_screen; ++i)
    {
        for (auto j = 0U; j < size_screen; ++j)
        {
            if (screen[i][j] != 0 && level_map.getCell(i + position.y - review, j + position.x - review) == 'H')
            {
                point.y = i;
                point.x = j;

                for (auto it = screen[i][j] - 1; it > 1; --it)
                {
                    if ((unsigned)point.x + 1 < size_screen)
                    if (screen[point.y][point.x + 1] == it
                            && level_map.getCell(point.y + position.y - review, point.x + 1 + position.x - review) != '#')
                    {
                        point.x = point.x + 1;
                        point.y = point.y;
                        continue;
                    }

                    if (point.x - 1 >= 0)
                    if (screen[point.y][point.x - 1] == it
                            && level_map.getCell(point.y + position.y - review, point.x - 1 + position.x - review) != '#')
                    {
                        point.x = point.x - 1;
                        point.y = point.y;
                        continue;
                    }

                    if ((unsigned)point.y + 1 < size_screen)
                    if (screen[point.y + 1][point.x] == it
                            && level_map.getCell(point.y + 1 + position.y - review, point.x + position.x - review) != '#')
                    {
                        point.x = point.x;
                        point.y = point.y + 1;
                        continue;
                    }

                    if (point.y - 1 >= 0)
                    if (screen[point.y - 1][point.x] == it
                            && level_map.getCell(point.y - 1 + position.y - review, point.x + position.x - review) != '#')
                    {
                        point.x = point.x;
//.........这里部分代码省略.........
开发者ID:DeveloperHacker,项目名称:Prototype,代码行数:101,代码来源:computer.cpp

示例5: movement

bool Computer::movement(Maze level_map)
{
    const auto Q_POSSIBILITIES = 4U;
    SegmentDistribution distributed_move[Q_POSSIBILITIES];
    Point shift;
    Point temp;
    bool result, approval1 = false, approval2 = false, approval3 = false;
    unsigned left_boundary = 0;
    unsigned root_decision, decision;


    if(move_to_hero(level_map) == true) return true;

    //относительно героя компьютера
    if (prev_position == position)
    {
        shift.x = 0;
        shift.y = -1;
    }
    else
    {
    shift.x = position.x - prev_position.x;
    shift.y = position.y - prev_position.y;
    }

    distributed_move[0].probability = 70; // Смещение вперёд
    distributed_move[0].shift = shift;

    distributed_move[1].probability = 2; // Смещение назад
    distributed_move[1].shift.x = -shift.x;
    distributed_move[1].shift.y = -shift.y;

    distributed_move[2].probability = 14; // Смещение влево
    distributed_move[2].shift.x = shift.y;
    distributed_move[2].shift.y = -shift.x;

    distributed_move[3].probability = 14; // Смещение вправо
    distributed_move[3].shift.x = -shift.y;
    distributed_move[3].shift.y = shift.x;

    for (auto i = 0U; i < Q_POSSIBILITIES; ++i)
    {
        temp.x = position.x + distributed_move[i].shift.x;
        temp.y = position.y + distributed_move[i].shift.y;
        if (level_map.isExistance(temp.y, temp.x))
        {
            approval1 = level_map.getCell(temp.y, temp.x) != '#';
            approval2 = level_map.getCell(temp.y, temp.x) != 'E';
            approval3 = level_map.getCell(temp.y, temp.x) != 'M';
        }
        result = approval1 && approval2 && approval3;
        distributed_move[i].use = result;
        if (result == true) left_boundary += distributed_move[i].probability;
    }

    if (left_boundary == 0) return true;
    root_decision = rand() % left_boundary;

    for (auto i = 0U; i < Q_POSSIBILITIES; ++i)
    {
        if (!distributed_move[i].use) continue;
        if (root_decision < distributed_move[i].probability)
        {
            decision = i;
            break;
        }
        else
            root_decision -= distributed_move[i].probability;
    }

    prev_position = position;
    position.x += distributed_move[decision].shift.x;
    position.y += distributed_move[decision].shift.y;

    return true;
}
开发者ID:DeveloperHacker,项目名称:Prototype,代码行数:76,代码来源:computer.cpp


注:本文中的Maze::getCell方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。