Exemplo n.º 1
0
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;
}
Exemplo n.º 2
0
    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);
                    }
                }

            }
        }
    }
Exemplo n.º 3
0
void onIdle() {
    int elapsedTime = glutGet(GLUT_ELAPSED_TIME) - lastUpdate;
    //elapsedTime = (int) (elapsedTime * 0.5f); //slow down
    //if (elapsedTime < 5) return;
    if (!paused) {
        // FPS COUNTER //
        fpsCounter[0] += elapsedTime;
        fpsCounter[1]++;
        if (fpsCounter[0] > 1000) {
            //system("cls");
            cout << "FPS: " << 1000 / (fpsCounter[0] / fpsCounter[1]) << endl;
            fpsCounter[0] = fpsCounter[1] = 0;
        }
        // FPS COUNTER //
        cams.update(elapsedTime, &pacman);
        int pacmanDeathTime = maze.getPacmanDeathTime();
        if (!pacmanDeathTime) { //pacman is alive
            pacmanIsAlive = 1;
            pacman.update(elapsedTime, &maze);
            maze.eatBallAt(pacman.getPosX(), pacman.getPosY());
            ghosts.update(elapsedTime, pacman.getPosX(), pacman.getPosY(), &maze);
        }
        else {
            if (pacmanDeathTime + 6000 <  glutGet(GLUT_ELAPSED_TIME)) {
                //pacman.onBirth();
                pacman = Pacman();
                ghosts = Ghosts();
                maze.onPacmanBirth();
            }
            else {
                if (pacmanIsAlive) {
                    pacmanIsAlive = 0;
                    particles.start(pacman.getPosX(), pacman.getPosY());
                }
                particles.update(elapsedTime);
            }
        }
        glutPostRedisplay();
    }
    lastUpdate = glutGet(GLUT_ELAPSED_TIME);
}
Exemplo n.º 4
0
 void ColoredCubeApp::reloadLevel()
{
	currentKeys = 0;
	flashLightObject.getBattery();
	//add in the maze reset function
	Dimension d;
	d.x=20;
	d.z = 20;
	maze.init(d,mfxWVPVar,mfxWorldVar,md3dDevice);
	maze.build();
	/*maze.setTex(mfxDiffuseMapVar,mfxSpecMapVar,L"brickwork-texture.jpg",L"brickwork-bump-map.jpg");	
	maze.setCeilTex(mfxDiffuseMapVar,mfxSpecMapVar,L"13.free-brick-textures.jpg",L"brickwork-bump-map.jpg");
	maze.setFloorTex(mfxDiffuseMapVar,mfxSpecMapVar,L"carpet_diffuse.jpg",L"brickwork-bump-map.jpg");*/

	for(int i = 0; i < numLightObjects; i++)
	{
		Location l;
		l.x = rand()%mazeX;
		l.z = rand()%mazeZ;
		auto spot = maze.cellToPx(l);
		lamps[i].setPosition(Vector3(spot.x,5,spot.z));
	}
	for(int i = 0; i < totalKeys; i++)
	{
		Location l;
		l.x = rand()%mazeX;
		l.z = rand()%mazeZ;
		auto spot = maze.cellToPx(l);
		keyObject[i].setPosition(Vector3(spot.x,-1,spot.z));
		keyObject[i].setActive();
	}
	for(int i = 0; i < numBatteries; i++)
	{
		Location l;
		l.x = rand()%mazeX;
		l.z = rand()%mazeZ;
		auto spot = maze.cellToPx(l);
		batteries[i].setPosition(Vector3(spot.x,-1,spot.z));
		batteries[i].setActive();
	}
}
Exemplo n.º 5
0
 int findPath()
 {
     init();
     Node s=Node(sta,0,0,make_pair(-1,-1)),tmp;
     pri_List.push(s);
     mazer.pushQue(s.pos);
     while (!pri_List.empty())
     {
         tmp=pri_List.top();
         printf("%d %d %d %d %d\n",tmp.pos.first,tmp.pos.second,tmp.parent.first,tmp.parent.second,tmp.f);
         mazer.pushVis(tmp.pos);
         pri_List.pop();
         if (tmp.pos == end)
         {
             backtrace(end.first,end.second);
             return 1;
         }
         expandSuccessors(tmp);
     }
     return 0;
 }
Exemplo n.º 6
0
void onDisplay(void) {
    // cams.projection(winW, winH);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    cams.look();
    lights.display(&pacman);

    //draw stuff
    maze.draw();
    if (!maze.getPacmanDeathTime()) { //pacman is alive
        pacman.draw();
    }
    else particles.draw();
    mazeFloor.draw();
    ghosts.draw();
    hud.draw(winW, winH, &maze);
    glFlush();
}
Exemplo n.º 7
0
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;
    }
    
}
Exemplo n.º 8
0
void Animate()
{
	if (direction != 0){
		double step_limit = 60;
		static double step = 0;
		m_center = glm::vec3(glm::translate(glm::mat4(1.0f), glm::vec3(0, direction * (1 / step_limit) * 4, 0))*glm::vec4(m_center, 1));
		m_eye = glm::vec3(glm::translate(glm::mat4(1.0f), glm::vec3(0, direction * (1 / step_limit) * 4, 0))*glm::vec4(m_eye, 1));
		step++;
		if (step >= step_limit) {
			step = 0;
			cur_layer += direction;
			if (direction == 1) M.NextLayer();
			else M.PreviousLayer();
			direction = 0;
		}
		else {
			DrawElevator(step,step_limit);
		}
	}

}
Exemplo n.º 9
0
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());
}
Exemplo n.º 10
0
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;
}
Exemplo n.º 11
0
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);
}
Exemplo n.º 12
0
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);
}
Exemplo n.º 13
0
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;
}
Exemplo n.º 14
0
/**
 * 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 "";
}
Exemplo n.º 15
0
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;
}
Exemplo n.º 16
0
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;
}
Exemplo n.º 17
0
// 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();
}
Exemplo n.º 18
0
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;
}
Exemplo n.º 19
0
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);
}
Exemplo n.º 20
0
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;
}
Exemplo n.º 21
0
Maze *MazeGame::CreateMaze()
{
    Maze *aMaze = new Maze();

    Room *r1 = new Room(1);
    Room *r2 = new Room(2);

    Door *door = new Door(r1, r2);

    r1->SetSide(Room::East, door);
    r1->SetSide(Room::South, new Wall());
    r1->SetSide(Room::West, new Wall());
    r1->SetSide(Room::North, new Wall());

    r2->SetSide(Room::East,  new Wall());
    r2->SetSide(Room::South, new Wall());
    r2->SetSide(Room::West, door);
    r2->SetSide(Room::North, new Wall());

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

    return aMaze;
}
Exemplo n.º 22
0
 string getSolution(vector <string> maze)
 {
     set<Maze> app;
     queue<Maze> q;
     
     Maze initS;
     initS.s = 0;
     mazeMap = maze;
     H = (int) maze.size();
     W = (int) maze[0].size();
     
     for (int i = 0; i < H; ++i)
         for (int j = 0; j < W; ++j)
             if (maze[i][j] == '.')
                 initS.s |= (1 << (i * W + j));
     q.push(initS);
     app.insert(initS);
     
     while (q.size() > 0)
     {
         Maze now = q.front();
         q.pop();
         if (now.s == 0) return now.path;
         
         for (int k = 0; k < 4; ++k)
         {
             Maze news = now.makeMove(k);
             if (app.find(news) == app.end())
             {
                 app.insert(news);
                 q.push(news);
             }
         }
     }
     return "";
 }
Exemplo n.º 23
0
//Estimation statistique du commitor (on utilise directement le Maze)
void commitor_montecarlo(Maze& M, Vector<float>& q)
{
  int n=M.size();
  q.setSize(n);
  q[0]=0;
  q[n-1]=1;
  int l=M.nbColonnes();

  int nb;//compteur d'étapes
  float sumnb;//moyenne
  int sumB=0;

  //Nos deux états limites
  Position A(0,0);
  Position B(M.nbLignes()-1,M.nbColonnes()-1);

  //Position de début et de fin des trajectoire
  Position D, F;
  
  for(int i=1;i<n-1;i++)
    {
      sumB=0;
      sumnb=0;
      for(int j=0;j<NBITERMC;j++)
	{
	  nb=0;
	  D=Position(i/l,i%l);
	  trajectoire(M,D,nb,F,A,B,false);
	  sumnb+=nb;
	  if (F==B)
	    sumB++;
	}
      q[i]=float(sumB)/float(NBITERMC);
      M(i).q[3]=sumnb/float(NBITERMC);
    }
}
Exemplo n.º 24
0
int main()
{
	try
	{
		Maze a;
		Coord start, end;
		int row, column;
		cout << "请输入迷宫的行数和列数:" << endl;
		cin >> row >> column;
		cout << "请设置迷宫:('.'表示通道, '#'表示墙壁)" << endl;
		a.MazeLayOut(row, column);
		cout << "请输入起点的位置:";
		cin >> start.row >> start.column;
		cout << "请输入终点的位置:";
		cin >> end.row >> end.column;
		a.FindPath(start, end);
		a.ShowDynamicPath();
	}
	catch(string x)
	{
		cout << x << endl;
	}
	return 0;
}
Exemplo n.º 25
0
/**
 * Verifies the coord validation logic works
 * @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::TestCoordValidation(TestUnit::tTestData* pTestData) {
	Maze* pMaze = (Maze*)pTestData->testObj;

	// Negatives
	if (pMaze->isValidCoord(Maze::tCoord(-1, 0, 0))) {
		return "Failed to mark coord(-1, 0, 0) as invalid";
	}
	if (pMaze->isValidCoord(Maze::tCoord(0, -1, 0))) {
		return "Failed to mark coord(0, -1, 0) as invalid";
	}
	if (pMaze->isValidCoord(Maze::tCoord(0, 0, -1))) {
		return "Failed to mark coord(0, 0, -1) as invalid";
	}
	// Outside
	if (pMaze->isValidCoord(Maze::tCoord(100, 0, 0))) {
		return "Failed to mark coord(100, 0, 0) as invalid";
	}
	if (pMaze->isValidCoord(Maze::tCoord(0, 100, 0))) {
		return "Failed to mark coord(0, 100, 0) as invalid";
	}
	if (pMaze->isValidCoord(Maze::tCoord(0, 0, 100))) {
		return "Failed to mark coord(0, 0, 100) as invalid";
	}
	// Maze edges
	if (pMaze->isValidCoord(Maze::tCoord(10, 0, 0))) {
		return "Failed to mark coord(0, 0, 100) as invalid";
	}
	if (pMaze->isValidCoord(Maze::tCoord(0, 5, 0))) {
		return "Failed to mark coord(0, 0, 100) as invalid";
	}
	if (pMaze->isValidCoord(Maze::tCoord(0, 0, 7))) {
		return "Failed to mark coord(0, 0, 100) as invalid";
	}

	return "";
}
Exemplo n.º 26
0
// Input : Maze, debut, A, B
// Output: fin, nb
void trajectoire(Maze& M, Position& debut, int& nb, Position& fin,const Position& A, const Position& B, const bool& with_aff)
{
  debut.bouge(M);
  if (debut==A || debut==B)
    {
      fin=debut;
    }
  else
    {
      if (with_aff)
	{
	  M.aff(true);
	  debut.affiche();
	  milliSleep(200);
	}
      trajectoire(M,debut,++nb,fin,A,B,with_aff);
    }
}
Exemplo n.º 27
0
		void initialize(Maze & maze)
		{
			for ( int y = 0 ; y < (int)maze.GetSizeY() ; y ++ )
			{
				for ( int x = 0 ; x < (int)maze.GetSizeX() ; x ++ )
				{
					if ( x == 0 || x == maze.GetSizeX() - 1 ||
						y == 0 || y == maze.GetSizeY() - 1 )
						maze.SetWall(x, y);

					if ( (x%2) == 0 && (y%2) == 0 )
						maze.SetWall(x, y);
				}
			}
		}
Exemplo n.º 28
0
// 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);
  glEnable(GL_DEPTH_TEST);

  glLoadIdentity();
  double dt = GetDeltaTime();
  if (gFirstPerson)
  {
    double rad = gRat.getDegrees()/180.0 * M_PI;
    double dx = cos(rad) * MOVE_SPEED * dt;
    double dy = sin(rad) * MOVE_SPEED * dt;
    gluLookAt(gRat.getX(), gRat.getY(), gRatHeight, gRat.getX() + dx, gRat.getY() + dy, gRatHeight, 0, 0, 1);
    // when doing rat, calculate at point but z will stay.
  }
  else
  {
    gluLookAt(M*.5, -N*.5, 15, M*.5, N*.5, 0, 0, 0, 1); // 3 eye, 3 at point, 3 z-axis up
  }

	gMaze.draw();
  gRat.draw(gFirstPerson);

  if (gLeft) gRat.spinLeft(dt);
  if (gRight) gRat.spinRight(dt);
  if (gMiddle) gRat.move(dt);

  if (gFirstPerson)
  {
    gluPerspective(.02, (double)screen_x/screen_y, .0001, .0001);
  }
  else
  {
    gluPerspective(40, (double)screen_x/screen_y, N*.5, 3*(M+N));
  }

	glutSwapBuffers();
	glutPostRedisplay();

}
Exemplo n.º 29
0
/*
 * Rotate the Maze conter-clockwise for 45 degrees to get a grid system. Each
 * slash means connection of two pairs of grid points. This function translate
 * the Slash Maze to a graph of the grid system.
 * */
Grid mazeToGrid(const Maze & m) {
  Grid g;
  int i = 0, j = 0; //Grid coordinates
  int x, y;         //Maze coordinates
  int h = m.size();
  int w = m[0].size();
  //Initially, let m(0, 0) corresponds to g(0, 0). This may cause negative i/j
  //for a grid, but it doesn't matter, since grid g is a adjacency list.
  for (x = 0; x < h; x++) {
    int oi = i;
    int oj = j;
    for (y = 0; y < w; y++) {
      //m(x, y) corresponds to g(i, j) that is the top grid of the four grids
      //that slash m(x, y) involves.
      if (m[x][y] == '\\') {
        //Then top and right grids connect, so do left and bottom grids.
        g[Point(i, j)].push_back(Point(i, j + 1));
        g[Point(i, j + 1)].push_back(Point(i, j));
        g[Point(i + 1, j)].push_back(Point(i + 1, j + 1));
        g[Point(i + 1, j + 1)].push_back(Point(i + 1, j));
      }
      else {
        //Then top and left grids connect, so do right and bottom grids.
        g[Point(i, j)].push_back(Point(i + 1, j));
        g[Point(i + 1, j)].push_back(Point(i, j));
        g[Point(i, j + 1)].push_back(Point(i + 1, j + 1));
        g[Point(i + 1, j + 1)].push_back(Point(i, j + 1));
      }
      //while m(x, y) corresponds to g(i, j), m(x, y + 1) corresponds to
      //g(i - 1, j + 1)
      i--;
      j++;
    }
    //while m(x, y) corresponds to g(i, j), m(x + 1, y) corresponds to
    //g(i + 1, j + 1)
    i = oi + 1;
    j = oj + 1;
  }
  return g;
}
Exemplo n.º 30
0
/*----- R e t r a c e (  ) ----------------------------------

PURPOSE
Mark the path from the goal to the start cell.

INPUT PARAMETERS
maze           -- the maze object to be marked
-------------------------------------------------------------*/
void Retrace(Maze &maze)
{
 
	Position curPos = maze.Goal();
	int distance = maze.State(maze.Goal());		// Distance from start cell

	while (distance >= 0)
	{
		maze.Mark(curPos, PathCell);
		if ((maze.State(curPos + StepNorth)) == (distance - 1))
			curPos = curPos + StepNorth;
		
		else if ((maze.State(curPos + StepWest)) == (distance - 1))
			curPos = curPos + StepWest;
		
		else if ((maze.State(curPos + StepSouth)) == (distance - 1))
			curPos = curPos + StepSouth;
		
		else if ((maze.State(curPos + StepEast)) == (distance - 1))
			curPos = curPos + StepEast;

		distance -= 1;
	}
}