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


C++ Maze类代码示例

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


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

示例1: CreateMaze

Maze* MazeGame::CreateMaze(MazeFactory& factory) {
    Maze* m = factory.MakeMaze();
    Room* r1 = factory.MakeRoom(1);
    Room* r2 = factory.MakeRoom(2);
    Door* d = factory.MakeDoor(r1, r2);

    m->AddRoom(r1);
    m->AddRoom(r2);

    r1->SetSide(North, factory.MakeWall());
    r1->SetSide(East, d);
    r1->SetSide(South, factory.MakeWall());
    r1->SetSide(West, factory.MakeWall());
    r2->SetSide(North, factory.MakeWall());
    r2->SetSide(East, factory.MakeWall());
    r2->SetSide(South, factory.MakeWall());
    r2->SetSide(West, d);

    return m;
}
开发者ID:waterinet,项目名称:miscellaneous_repo,代码行数:20,代码来源:MazeGame.cpp

示例2: scurry

void Rat::scurry(double dt, Maze &maze)
{
    double radians = mDegrees * M_PI / 180;
    dx = cos(radians) * dt * SCURRY_SPEED;
    dy = sin(radians) * dt * SCURRY_SPEED;
  //  double dz
    if (maze.isSafe(mX+dx, mY+dy, mRadius))
    {
        mX += dx;
        mY += dy;
    }
    else if (maze.isSafe(mX, mY+dy, mRadius))
    {
        mY += dy;
    }
    else if (maze.isSafe(mX+dx, mY, mRadius))
    {
        mX += dx;
    }
    
}
开发者ID:codybrowncit,项目名称:C-plus-plus,代码行数:21,代码来源:rat.cpp

示例3: test_KShortestPath

void test_KShortestPath(const char *filename)
{
	Maze field;
	field.loadFromFile(filename);
	//field.loadFromArray(mazeData_66test);

	ShortestPath path(field);
	path.calcKShortestDistancePath(IndexVec(0,0), MAZE_GOAL_LIST, 5, false);

	int cnt = 0;
	for (auto &p : path.getKShortestDistancePath()) {
		cnt++;
		printf("path#%d length %lu\n", cnt, p.size());
		bool route[MAZE_SIZE][MAZE_SIZE] = {false};
		for (auto &index : p) {
			route[index.y][index.x] = true;
		}
		field.printWall(route);
	}
	printf("found %lu route\n", path.getKShortestDistancePath().size());
}
开发者ID:idt12312,项目名称:MazeSolver2015,代码行数:21,代码来源:main.cpp

示例4: CreateMaze

Maze* MazeGame::CreateMaze(MazeFactory& factory) {
    Maze* aMaze = factory.MakeMaze();
    Room* r1 = factory.MakeRoom(1);
    Room* r2 = factory.MakeRoom(2);
    Door* aDoor = factory.MakeDoor(r1, r2);

    aMaze->AddRoom(r1);
    aMaze->AddRoom(r2);

    r1->SetSide(North, factory.MakeWall());
    r1->SetSide(East, aDoor);
    r1->SetSide(South, factory.MakeWall());
    r1->SetSide(West, factory.MakeWall());

    r2->SetSide(North, factory.MakeWall());
    r2->SetSide(East, factory.MakeWall());
    r2->SetSide(South, factory.MakeWall());
    r2->SetSide(West, aDoor);

    return aMaze;
}
开发者ID:sunsuri,项目名称:Design-Patterns-GoF,代码行数:21,代码来源:MazeGame.cpp

示例5: main

int main(int argc, char *argv[])
{
    Maze maze;
    
    if (argc != 2)
    {
        cout << "Must supply 1 argument to this program\n";
        return 0;
    }
    
    maze.loadMaze(argv[1]);
    if (!maze.isValid()) 
    {
        cout << "Unable to load maze " << argv[1] << "\n";
        exit(0);
    }
    maze.calculatePath();
    maze.printMaze();
    
    exit(0);
}
开发者ID:stellalie,项目名称:dsa,代码行数:21,代码来源:assign3.cpp

示例6: test_Agent

void test_Agent(const char *filename)
{
	Maze field;
	Maze mazeInRobot;
	field.loadFromFile(filename);
	//field.loadFromArray(mazeData_66test);

	Agent agent(mazeInRobot);

	IndexVec cur(0,0);
	while(1) {
		bool pos[MAZE_SIZE][MAZE_SIZE] = {false};
		pos[cur.y][cur.x] = true;
		mazeInRobot.printWall(pos);

		agent.update(cur, field.getWall(cur));
		if (agent.getState() == Agent::FINISHED) break;

		Direction dir = agent.getNextDirection();
		for (int i=0;i<4;i++) {
			if (dir[i]) cur += IndexVec::vecDir[i];
		}
		usleep(1000000/10);
	}

	agent.caclRunSequence(true);
	bool route[MAZE_SIZE][MAZE_SIZE] = {false};
	for (auto &index : agent.getShortestPath()) {
		route[index.y][index.x] = true;
	}
	mazeInRobot.printWall(route);
}
开发者ID:idt12312,项目名称:MazeSolver2015,代码行数:32,代码来源:main.cpp

示例7: main

int main(int argc, char** argv)
{
    Maze* maze;

    MazeGame game;

    StandardMazeBuilder builder;
    CountingMazeBuilder countBuilder;

    game.CreateMaze(builder);

    maze = builder.GetMaze();

    game.CreateMaze(countBuilder);

    cout << "room size in maze : " << maze->RoomSize() << endl;

    int roomNum, doorNum;
    countBuilder.GetCounts(roomNum,doorNum);

    cout << "room Num : " << roomNum << " door Num: "  << doorNum << endl;
}
开发者ID:thuang136,项目名称:algorithm,代码行数:22,代码来源:builder.cpp

示例8: TestSetCellState

/**
 * Verifies that cells in a grid can have their state set.
 * @params pTestData - test object to store the maze in so it
 * will get cleaned up in all cases.
 * @returns error string if there was an error
 */
string MazeTest::TestSetCellState(TestUnit::tTestData* pTestData) {
	Maze* pMaze = (Maze*)pTestData->testObj;

	Maze::tCoord chg1 = Maze::tCoord(0, 0, 0);
	Maze::tCoord chg2 = Maze::tCoord(5, 3, 1); 
	Maze::tCoord chg3 = Maze::tCoord(9, 4, 6);
	Maze::tCoord noChg = Maze::tCoord(2, 2, 2);

	// Update the cells, start, end, and inner item
	if (!pMaze->updateCell(chg1, Maze::CELL_SOLID) ||
			!pMaze->updateCell(chg2, Maze::CELL_OCCUPIED) ||
			!pMaze->updateCell(chg3, Maze::CELL_EXIT)) {
		return "Failed to update valid cell in maze";
	}

	Maze::tGrid* pGrid = pMaze->getGrid();

	// Verify the changes only occred where desired
	Maze::tCell* cell = pGrid->at(noChg);
	if (cell->state != Maze::CELL_EMPTY) {
		return "Cell state change when it wasn't supposed to.";
	}

	// Verify changes
	cell = pGrid->at(chg1);
	if (cell->state != Maze::CELL_SOLID) {
		return "Unable to set cell to solid state.";
	}
	cell = pGrid->at(chg2);
	if (cell->state != Maze::CELL_OCCUPIED) {
		return "Unable to set cell to occupied state.";
	}
	cell = pGrid->at(chg3);
	if (cell->state != Maze::CELL_EXIT) {
		return "Unable to set cell to exit state.";
	}

	return "";
}
开发者ID:jasondelponte,项目名称:3dMazeBot,代码行数:45,代码来源:maze_test.cpp

示例9: MakeMaze

Maze* MazeGame::CreateMaze() {
    Maze* aMaze = MakeMaze();

    Room* r1 = MakeRoom(1);
    Room* r2 = MakeRoom(2);
    Door* theDoor = MakeDoor(r1, r2);

    aMaze->AddRoom(r1);
    aMaze->AddRoom(r2);

    r1->SetSide(North, MakeWall());
    r1->SetSide(East, theDoor);
    r1->SetSide(South, MakeWall());
    r1->SetSide(West, MakeWall());

    r2->SetSide(North, MakeWall());
    r2->SetSide(East, MakeWall());
    r2->SetSide(South, MakeWall());
    r2->SetSide(West, theDoor);

    return aMaze;
}
开发者ID:sunsuri,项目名称:Design-Patterns-GoF,代码行数:22,代码来源:MazeGame.cpp

示例10: search

bool search(Maze &maze,set<pointT> &includePoint,pointT current,pointT exit){
    pointT around;
    includePoint.insert(current);
    int i=0;
    while(i<4){
        around=current;
        switch(i){
            case 0:
                around.col--;
                break;
            case 1:
                around.row--;
                break;
            case 2:
                around.col++;
                break;
            default:
                around.row++;
        }
        //判断该点合法
        if(maze.pointInBounds(around)&&!maze.isWall(current,around)&&includePoint.count(around)==0){
            if(around==exit){
                cout<<"get it"<<endl;
                maze.drawMark(around,"Red");

                return true;
            }
            else{
                bool flag=search(maze,includePoint,around,exit);
                if(flag){
                    maze.drawMark(around,"Red");
                    return true;
                }
            }
        }
        i++;
    }
    return false;
}
开发者ID:nejyeah,项目名称:cplusplus,代码行数:39,代码来源:part2.cpp

示例11: display

// This callback function gets called by the Glut
// system whenever it decides things need to be redrawn.
void display(void)
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	if (current_view == perspective_view) {
		glEnable(GL_DEPTH_TEST);
		glLoadIdentity();
		gluLookAt(-3,-3,7,   3,3,0,   0,0,1);
	}
	else if (current_view == top_view){
		glDisable(GL_DEPTH_TEST);
		glLoadIdentity();
	}
	else if (current_view == rat_view){
		glEnable(GL_DEPTH_TEST);
		glLoadIdentity();
		double z_level = .25;
		double x = gRat.getX();
		double y = gRat.getY();
		//problem with dx and dy
		double dx = gRat.getdX();
		double dy = gRat.getdY();
		//double at_x = x + dx;
		//double at_y = y + dy;
		double at_x =gRat.getNextX() ;
		double at_y =gRat.getNextY() ;
		double at_z = z_level;
		//std::cout<<dx<<"   "<<at_x<<"----"<<dy<<"    "<<at_y<<std::endl;
		gluLookAt(x,y,z_level,  at_x, at_y, at_z,  0,0,1);
		//gluLookAt(x,y,z_level,  360, 360, at_z,  0,0,1);
	}


	gMaze.Draw(current_view);

	if(gMiddleButtonDown) {
		gRat.Scuttle(gMaze); 
		glutPostRedisplay();
	}
	if(gLeftButtonDown){
		gRat.SpinLeft(); 
		glutPostRedisplay();
	}
	if(gRightButtonDown){
		gRat.SpinRight(); 
		glutPostRedisplay();
	}
	gRat.Draw(current_view);

	glutSwapBuffers();
}
开发者ID:coltonmorris,项目名称:3d-maze,代码行数:53,代码来源:graphics1.cpp

示例12: 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

示例13: move

void MazeCreator::move(Maze & m, State & s, Position & c, unsigned char dir) const
{
	m.c(c) &= ~dir;
	switch (dir) {
		case TOP:
			m.c(c.first, c.second-1) &= ~BOTTOM;
			--c.second;
			break;
		case BOTTOM:
			m.c(c.first, c.second+1) &= ~TOP;
			++c.second;
			break;
		case RIGHT:
			m.c(c.first+1, c.second) &= ~LEFT;
			++c.first;
			break;
		case LEFT:
			m.c(c.first-1, c.second) &= ~RIGHT;
			--c.first;
			break;
	}
	s.visit(c);
}
开发者ID:mariokonrad,项目名称:maze,代码行数:23,代码来源:MazeCreator.cpp

示例14:

Maze *MazeGame::CreateMaze(MazeFactory &mazeFactory)
{
    Maze *aMaze = mazeFactory.MakeMaze();
    Room *r1 = mazeFactory.MakeRoom(1);
    Room *r2 = mazeFactory.MakeRoom(2);

    Door *door = mazeFactory.MakeDoor(r1, r2);

    r1->SetSide(Room::East, door);
    r1->SetSide(Room::South, mazeFactory.MakeWall());
    r1->SetSide(Room::West, mazeFactory.MakeWall());
    r1->SetSide(Room::North, mazeFactory.MakeWall());

    r2->SetSide(Room::East,  mazeFactory.MakeWall());
    r2->SetSide(Room::South, mazeFactory.MakeWall());
    r2->SetSide(Room::West, door);
    r2->SetSide(Room::North, mazeFactory.MakeWall());

    aMaze->AddRoom(r1);
    aMaze->AddRoom(r2);

    return aMaze;
}
开发者ID:e5MaxSpace,项目名称:DesignPatterns,代码行数:23,代码来源:mazegame.cpp

示例15: expandSuccessors

    void expandSuccessors(Node c)
    {
        int i,d,g,h;
        Node t;
        P_II jp;
        V_PII nbs=neighbourPrune(c);
        for (i=0; i<nbs.size(); i++)
        {
            jp=checkJump(nbs[i],c.pos);
            if (jp.first != -1)
            {
                if (mazer.isInVis(jp) == true)
                    continue;
                d=abs(jp.first-c.pos.first)+abs(jp.second-c.pos.second);
                g=c.g+d;
                if (mazer.isInQue(jp) == false || g < mem_g[jp.first][jp.second])
                {
                    mem_g[jp.first][jp.second]=g;
                    t.g=g;
                    h=abs(jp.first-end.first)+abs(jp.second-end.second);
                    t.f=t.g+h;
                    t.pos=jp;
                   // printf("%d %d %d %d %d %d\n",t.pos.first,t.pos.second,t.parent.first,t.parent.second,c.pos.first,c.pos.second);
                    t.parent=c.pos;


                    if (mazer.isInQue(jp) == false)
                    {
                        path[jp.first][jp.second]=c.pos;
                        pri_List.push(t);
                        mazer.pushQue(t.pos);
                    }
                    else
                    {
                        pri_List.update(t);
                    }
                }

            }
        }
    }
开发者ID:eLRuLL,项目名称:JumpPointSearchAlgorithm,代码行数:41,代码来源:main.cpp


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