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


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

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


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


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