本文整理汇总了C++中Maze::getEndCell方法的典型用法代码示例。如果您正苦于以下问题:C++ Maze::getEndCell方法的具体用法?C++ Maze::getEndCell怎么用?C++ Maze::getEndCell使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Maze
的用法示例。
在下文中一共展示了Maze::getEndCell方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}