Exemple #1
0
void AgentMCTS::create_children_simple(const Board & board, Node * node){
	assert(node->children.empty());

	node->children.alloc(board.moves_avail(), ctmem);

	Node * child = node->children.begin(),
		 * end   = node->children.end();
	MoveIterator moveit(board, prunesymmetry);
	int nummoves = 0;
	for(; !moveit.done() && child != end; ++moveit, ++child){
		*child = Node(*moveit);
		nummoves++;
	}

	if(prunesymmetry)
		node->children.shrink(nummoves); //shrink the node to ignore the extra moves
	else //both end conditions should happen in parallel
		assert(moveit.done() && child == end);

	PLUS(nodes, node->children.num());
}
int main(int argc, char** argv) {
    ros::init(argc, argv, "arm_planning_lib_test"); //node name
    ros::NodeHandle nh;
    //ArmPlanningInterface interface(&nh);
    MoveitPlanningInterface moveit(&nh);
    ROS_INFO("setting poses");
    Vector7d my_angle;
    geometry_msgs::Pose my_pose;
    my_angle << -0.18503156094537968, 0.44527797626583865, 0.36021593694382065, 1.827325037963473, 1.0199002550686511, 1.0137709796128629, 1.2701787563643496;
    string colors[] = {"red", "blue", "white", "black", "green", "wood"};

    my_pose.position.x = 0.627811922278;
    my_pose.position.y = -0.00340972086974;
    my_pose.position.z = -0.0243679733262;
    my_pose.orientation.x = 1;
    my_pose.orientation.y = 0;
    my_pose.orientation.z = 0;
    my_pose.orientation.w = 0;
    /*
    POSE: X = 0.877945, Y = 0.036200, Z = -0.132033, orientation: X = 0.979358, Y = -0.202119, Z = 0.000723, W = -0.002389
    while (ros::ok()) {
    	ROS_INFO("executing %d", ++count);
    	interface.moveArmsBack();
    	ros::Duration(5.0).sleep();

//   		interface.planPath(my_angle);
//   		interface.executePath();
//   		ros::Duration(5.0).sleep();
        ROS_INFO("executing %d", ++count);
    	interface.planPath(interface.pre_grab_pose);
    	interface.executePath();
    	ros::Duration(5.0).sleep();
        ROS_INFO("executing %d", ++count);
    	interface.planPath(interface.grab_pose);
    	interface.executePath();
    	ros::Duration(5.0).sleep();
        ROS_INFO("executing %d", ++count);
    	interface.takeALook();
    	ros::Duration(5.0).sleep();

		ros::spinOnce();
    }*/
    //ROS_INFO("total %d colors", colors.size());

 
    bool ret;
    while (ros::ok()) {
        for (int i = 0; i < 6; ++i)
        {
            moveit.moveArmsBack();
            ros::Duration(5.0).sleep();
            ros::spinOnce();
            ROS_INFO("executing %s", colors[i].c_str());
            ret = moveit.colorMovement((colors[i]),my_pose);
            if(ret == false)
                ROS_INFO("Color not finished");
            ros::Duration(5.0).sleep();
            ros::spinOnce();
        }
    }
       /* 
    moveit.moveArmsBack();
    ros::Duration(5.0).sleep();
    moveit.planPath(my_pose);
    moveit.executePath();
    ros::Duration(5.0).sleep();
    ros::spinOnce();*/
    return 0;
}
int main(int argv, char *args[])
{
	// The events for SDL
	SDL::Event events;
	// and the handler to handle the events
	class handler : public SDL::Handle
	{
		public:
			handler() : stop(false)
			{
			}

			bool KeyPressed(SDL::KeySym &keysym)
			{
				if(keysym.sym == SDLK_ESCAPE)
					stop = true;

				// Returns true so a call to SDL::Handle::All() isn't tried
				// Only to avoid an extra call that would do nothing
				return true;
			}

			// If the class is used as a boolean such as if(handler) do something
			operator bool()
			{
				return stop;
			}
		private:
			bool stop;
	} handle;

	SDL::Init(SDL_INIT_VIDEO);
	atexit(SDL::Quit);
	// Check to show that the overloaded operators work first
	SDL::Surface One, Two;
	One.LoadBMP("bitmap.bmp");
	Two = One;

	SDL::Surface Three = One;

	SDL::Surface Four;
	Four = One;
	SDL::Surface temp(SDL_LoadBMP("icon.bmp"));

	// Should be equal
	if(Four == Two)
		std::cout << "Passed: Four and Two are equal"  << std::endl;
	else
	{
		std::cerr << "Failed: Four and Two are not equal"  << std::endl;
		exit(EXIT_FAILURE);
	}

	SDL::Surface icon;
	icon.LoadBMP("icon.bmp");

	//  Should not be equal
	if(icon == Four)
	{
		std::cerr << "Failed: icon and Four are equal" << std::endl;
		exit(EXIT_FAILURE);
	}
	else
		std::cout << "Passed: icon and Four not equal" << std::endl;

	// Should be equal
	if(temp == icon)
		std::cout << "Passed: temp now has a copy of icon and they're equal" << std::endl;
	else
	{
		std::cerr << "Failed: temp and icon aren't equal" << std::endl;
		exit(EXIT_FAILURE);
	}

	One = icon;

	// Should be equal
	if(icon == One)
		std::cout << "Passed: One now has a copy of icon and they're equal" << std::endl;
	else
	{
		std::cerr << "Failed: One and icon aren't equal" << std::endl;
		exit(EXIT_FAILURE);
	}

	if(Two != One)
		std::cout << "Passed: Two does NOT equal One." << std::endl;
	else
	{
		std::cerr << "Failed: Two DOES equal One." << std::endl;
		exit(EXIT_FAILURE);
	}

	// Now set setup screen with this icon to continue some basic tests.
	SDL::Screen screen(icon, NULL);
	screen.SetVideoMode(640, 480, 32, SDL_HWSURFACE|SDL_DOUBLEBUF);

	// Setup a rectangle to move the sprite
	int vx = 1, vy = 1;
	int width = icon.GetRect().w, height = icon.GetRect().h;

	// Three rects, One for current position, one for pevious position, and one to store the two prior rects to update
	SDL::Rect moveit(0, 0, width, height);
	SDL::Rect previous = moveit;
	SDL::Rect rect[2] = { moveit, previous };

	while(!handle)
	{
		// Fill the previous location with black
		screen.FillRect(previous, 0);
		// Move the position to draw the rect out of the just draw area
		moveit.x += vx;
		moveit.y += vy;
		// Try to blit the image to the screen
		if(!screen.Blit(icon, moveit))
			std::cout << "Not blitted: " << SDL::GetError() << std::endl;

		// If the image is over the bounds of the screen, reverse the velocity of the object
		if(moveit.x+width >= 640)
			vx = -1;
		if(moveit.x <= 0)
			vx = 1;

		if(moveit.y+height >= 486)
			vy = -1;
		if(moveit.y <= 0)
			vy = 1;

		// Update the two rects in the array to update on the screen
		rect[0] = moveit;
		rect[1] = previous;
		// Finally update the screen
		screen.UpdateRects(2, rect);

		// Now set previous to the previous location of the sprite (current but that will be moved before blitted
		previous = moveit;
		// Try for events
		events.Poll(handle);
		// Delay the execution so it runs  more uniform everywhere
		Delay();
	}

	return 0;
}
Exemple #4
0
void main()
{
    if(InitGraphics() == -1)
	return;


    initialisedata();

    clearviewport();
    rectangle(0,0,(maxx+1)*width+2, (maxy+1)*width+2);
    sx = (maxx+1)*width+6;
    sy = (maxy+1)*width+2;

    int loop = 0;
    while(!endgame)
    {
	loop++;
	for (int i = 0; i < NUM_PLAYERS; i++)
	{
	    drawplayer(plist[i]);
	}
	showscoreboard();
	delay(DELAY_INTERVAL);
	for (i = 0; i < NUM_PLAYERS; i++)
	{
	   showbox(plist[i]);
	}
	if (kbhit())
	{
	    handlekeypress();
	}

	if (endgame)
	    break;

	// 1 to n is computer plaer, 0 is me
	for (i = 1; i < NUM_PLAYERS; i++)
	{
	    decidemove(plist[i]);
	}

	for (i = 0; i < NUM_PLAYERS; i++)
	{
	    adjustdir(plist[i]);
	    moveit(plist[i]);
	}
	for (i = 0; i < NUM_PLAYERS; i++)
	{
	      updatescore(plist[i]);
	if (plist[i].score >= WINNING_SCORE)
	{
	    endgame = true;
	    setfillstyle(1, BLUE);

	    bar(200,120,439,300);
	    outtextxy(250,200,"GAME OVER");
	    if (i == 0)
	    {
		outtextxy(250,250,"YOU WIN");
	    }
	    else
	    {
		outtextxy(250,250,"YOU LOSE");
	    }
	    showscoreboard();
            char tr = getch();
        }
	}

    }


}