void main()
{
 long int g,x,y,a,b,k1,k2,n;
 clrscr();

 cout<<"\n\t Enter value of n & g";
 cin>>n>>g;

 cout<<"\n\t Enter value of x & y";
 cin>>x>>y;

 a=alice(n,g,x);
 cout<<"\n\t alice end value:"<<a;

 b=bob(n,g,y);
 cout<<"\n\t bob end value:"<<b;

 k1=alice(n,b,x);
 cout<<"\n\t valueof k1 :"<<k1;

 k2=alice(n,a,y);
 cout<<"\n\t valueof k2 :"<<k2;

 getch();
}
Beispiel #2
0
int main()
{
    int t,i,j,n,m,k,l;
    ull ans;
    scanf("%d",&t);
    while(t--)
    {
        ac=0;bc=0;

        scanf("%d %d",&n,&m);

        for(i=0;i<n;i++)
        {
            for(j=0;j<m;j++)
            {
                scanf("%llu",&a[i][j]);
            }
        }
        alice(0,n-1,0,m-1);
        //printf("ans: %llu ",ans);
        //printf("ac: %llu\n",ac);
        if(ac==bc)
        {
            printf("%llu\n",bc+ac);
        }
        else
        {
            printf("%llu\n",(bc>ac?bc:ac));
        }

    }
    //printf("%d",t);
    return 0;
}
Beispiel #3
0
void main(void)
{
  unsigned int x = alice(0);
  unsigned int i;
  for(i = 0; i < 5; i++)
    output_alice(x);
}
Beispiel #4
0
bool MetavoxelTests::run() {
    
    qDebug() << "Running metavoxel tests...";
    
    // seed the random number generator so that our tests are reproducible
    srand(0xBAAAAABE);

    // create two endpoints with the same header
    QByteArray datagramHeader("testheader");
    Endpoint alice(datagramHeader), bob(datagramHeader);
    
    alice.setOther(&bob);
    bob.setOther(&alice);
    
    // perform a large number of simulation iterations
    const int SIMULATION_ITERATIONS = 100000;
    for (int i = 0; i < SIMULATION_ITERATIONS; i++) {
        if (alice.simulate(i) || bob.simulate(i)) {
            return true;
        }
    }
    
    qDebug() << "Sent" << highPriorityMessagesSent << "high priority messages, received" << highPriorityMessagesReceived;
    qDebug() << "Sent" << unreliableMessagesSent << "unreliable messages, received" << unreliableMessagesReceived;
    qDebug() << "Sent" << reliableMessagesSent << "reliable messages, received" << reliableMessagesReceived;
    qDebug() << "Sent" << streamedBytesSent << "streamed bytes, received" << streamedBytesReceived;
    qDebug() << "Sent" << datagramsSent << "datagrams, received" << datagramsReceived;
    
    qDebug() << "All tests passed!";
    
    return false;
}
Beispiel #5
0
int main()
{
	int key = 8;
	std::string alphabet("abcdefghijklmnopqrstuvwxyz .;_");

	Receiver bob( key , alphabet );
	Transmitter alice( key , alphabet );

	std::string message ="mi nombre es victor miguel sequeiros arapa";

	alice.rail_cipher(message);

	std::cout << message << std::endl;

	bob.rail_decipher(message);

	std::cout << message << std::endl;
/*
	alice.route_cipher(message);
	std::cout << message << std::endl;

	bob.route_decipher(message);
	std::cout << message << std::endl;
*/
	return 0;
};
Beispiel #6
0
/**
 *  @brief act as a server in the protocol.
 *
 *  @param portno the port number to listen on.
 *  @return non-zero on failure.
 */
int server(int portno)
{
  debug("called server() with port %d\n", portno);
  int error = 0;
  struct sockaddr_in servAddr;
  struct sockaddr_in cliAddr;
  unsigned cliLen = sizeof(cliAddr);
  int listenfd = socket(PF_INET, SOCK_STREAM, 0);
  int connfd = -1;
  int socketOption = 1;

  if(listenfd < 0)
  {
    error = -1;
    goto done;
  }

  if(setsockopt(listenfd, SOL_SOCKET, SO_REUSEADDR, &socketOption,
      sizeof(socketOption)))
  {
    error = -2;
    goto done;
  }

  memset((unsigned char *) &servAddr, 0, sizeof(servAddr));
  servAddr.sin_family = AF_INET;
  servAddr.sin_addr.s_addr = INADDR_ANY;
  servAddr.sin_port = htons(portno);
  if(bind(listenfd, (struct sockaddr *) &servAddr, sizeof(servAddr)) < 0)
  {
    error = -3;
    goto done;
  }

  debug("about to listen() with fd %d\n", listenfd);
  //listen for a connection
  listen(listenfd, MAX_QUEUE);
  if((connfd = accept(listenfd, (struct sockaddr *) &cliAddr, &cliLen)) < 0)
  {
    error = -4;
    goto done;
  }
  debug("accepted a connection with fd %d\n", connfd);

  //close the socket, only 1 connection is needed
  close(listenfd);

  error = alice(secret, connfd);

done:
  close(listenfd);
  close(connfd);
  return error;
}
Beispiel #7
0
bool MetavoxelTests::run() {
    
    qDebug() << "Running transmission tests...";
    qDebug();
    
    // seed the random number generator so that our tests are reproducible
    srand(0xBAAAAABE);

    // create two endpoints with the same header
    QByteArray datagramHeader("testheader");
    Endpoint alice(datagramHeader), bob(datagramHeader);
    
    alice.setOther(&bob);
    bob.setOther(&alice);
    
    // perform a large number of simulation iterations
    const int SIMULATION_ITERATIONS = 10000;
    for (int i = 0; i < SIMULATION_ITERATIONS; i++) {
        if (alice.simulate(i) || bob.simulate(i)) {
            return true;
        }
    }
    
    qDebug() << "Sent" << highPriorityMessagesSent << "high priority messages, received" << highPriorityMessagesReceived;
    qDebug() << "Sent" << unreliableMessagesSent << "unreliable messages, received" << unreliableMessagesReceived;
    qDebug() << "Sent" << reliableMessagesSent << "reliable messages, received" << reliableMessagesReceived;
    qDebug() << "Sent" << streamedBytesSent << "streamed bytes, received" << streamedBytesReceived;
    qDebug() << "Sent" << datagramsSent << "datagrams with" << bytesSent << "bytes, received" <<
        datagramsReceived << "with" << bytesReceived << "bytes";
    qDebug() << "Created" << sharedObjectsCreated << "shared objects, destroyed" << sharedObjectsDestroyed;
    qDebug() << "Performed" << objectMutationsPerformed << "object mutations";
    qDebug();
    
    qDebug() << "Running serialization tests...";
    qDebug();
    
    if (testSerialization(Bitstream::HASH_METADATA) || testSerialization(Bitstream::FULL_METADATA)) {
        return true;
    }
    
    qDebug() << "All tests passed!";
    
    return false;
}
int main(int argc, char **argv) {

	//Initialize ros usage
	ros::init(argc, argv, "follow_the_rabbit");

	std::string r_frame,o_frame;
	std::string topic_id;

	//Create Nodehandlers
	ros::NodeHandle nh("~");
	ros::NodeHandle n();

	nh.param<std::string>("rabbit_frame_id",r_frame,"/rabbit");
	nh.param<std::string>("vehicle_frame_id",o_frame,"/base_footprint");
	nh.param<std::string>("cmd_vel_topic_id",topic_id,"/fmControllers/cmd_vel");

	RabbitFollow alice(r_frame,o_frame);

	nh.param<double>("field_of_view_rad",alice.fov,2*M_PI);
	nh.param<double>("max_angular_vel",alice.max_ang_vel,1.5);
	nh.param<double>("max_linear_vel",alice.max_lin_vel,1.0);
	nh.param<double>("oscilation_bounds",alice.oscilation_bound,0.05);
	nh.param<double>("target_acquired_tolerance",alice.target_acquired_tolerance,0.1);
	alice.nh = &nh;

	ros::Timer t = nh.createTimer(ros::Duration(0.05),&RabbitFollow::spin,&alice);

	alice.cmd_vel_pub = nh.advertise<geometry_msgs::Twist>(topic_id.c_str(),10);

	dynamic_reconfigure::Server<fmControllers::rabbit_follow_paramsConfig> server;

	dynamic_reconfigure::Server<fmControllers::rabbit_follow_paramsConfig>::CallbackType cb;

	cb = boost::bind(&callback, _1, _2,&alice);
	server.setCallback(cb);


	t.start();
	//Handle callbacks
	ros::spin();

}
Beispiel #9
0
void main(void)
{
    unsigned int x=0;
    unsigned int i;
    unsigned int borrow=0;

    for(i = 0; i < 32;)
    {
        unsigned int a1 = alice(i);
        unsigned int b1 = bob(i);
        unsigned int b = borrow;
        borrow = 0;

        if(a1 < (b1 + b))
            borrow = 1;

        i += 32;
    }
    if(borrow == 0) x= 0x1;
    else x = 0xffffffff;

    output_alice(x);
}
Beispiel #10
0
void bob(int r1,int r2,int c1,int c2)
{
    if(r2<r1 || c2<c1)
    {
        return 0;
    }


    ull fr=0,lr=0,fc=0,lc=0,max;
    int i,choice;
    for(i=c1;i<=c2;i++)
    {
        fr+=a[r1][i];
    }

    for(i=c1;i<=c2;i++)
    {
        lr+=a[r2][i];
    }

    for(i=r1;i<=r2;i++)
    {
        fc+=a[i][c1];
    }
    for(i=r1;i<=r2;i++)
    {
        lc+=a[i][c2];
    }

    max=fr;
    choice=1;
    if(lr>max)
    {
        max=lr;
        choice=2;
    }

    if(fc>max)
    {
        max=fc;
        choice=3;
    }

    if(lc>max)
    {
        max=lc;
        choice=4;
    }
    bc+=max;
    switch(choice)
    {
        case 1:
            alice(r1+1,r2,c1,c2);
            break;
        case 2:
            alice(r1,r2-1,c1,c2);
            break;
        case 3:
            alice(r1,r2,c1+1,c2);
            break;
        case 4:
            alice(r1,r2,c1,c2-1);
            break;

    }

}
Beispiel #11
0
int main(int argc, char **argv)
{
	if (argc > 1)
		printf ("%s\n", alice (argv[1], getenv("USER")));
}
Beispiel #12
0
int main(int argc, char* argv[]) {

  if (argc < 3)
    usage(std::cout);

  int nb_colors = atoi(argv[2]);
	srand(time(0));

	int nbParties = 10;
	if (argc > 3)
		nbParties = atoi(argv[3]);
	if (argc > 4)
	  setNumberOfSimulations(atoi(argv[4]));

	Graph g;
	g.getGraphFromDot(argv[1]);
	/*for(int i=0 ; i<6 ; i++)
		g.addVertex();
	g.addEdge(g.getVertex(1), g.getVertex(2));
	g.addEdge(g.getVertex(1), g.getVertex(5));
	g.addEdge(g.getVertex(2), g.getVertex(3));
	g.addEdge(g.getVertex(2), g.getVertex(5));
	g.addEdge(g.getVertex(3), g.getVertex(4));
	g.addEdge(g.getVertex(4), g.getVertex(5));
	g.addEdge(g.getVertex(0), g.getVertex(5));
	*/
	MapGame game(g, nb_colors);

	std::cout << "The graph has " << game.getGraph().getNbVertices()
		 << " vertices"  << std::endl;
	std::cout << (game.isFinished()?"finished":"not finished") << std::endl;

	MonteCarloSelection algoAlice(game, false), algoBob(game, true);
	Player alice(algoAlice);
	Player bob(algoBob);
	int nbGagnees = 0;
	std::cout << "Played " << 0 << " games, alice won " << nbGagnees;
	std::cout.flush();
	for (int i = 0; i < nbParties; ++i)
	{
		if (game.play(alice, bob))
			++nbGagnees;
		game.reset();
		algoAlice.reset();
		algoBob.reset();
		std::cout << "\rPlayed " << i+1 << " games, alice won " << nbGagnees;
		std::cout.flush();
	}
	std::cout << std::endl;
	std::cout << "alice a gagne " << nbGagnees << "/" << nbParties << " parties" << std::endl;

	// MonteCarloNode* mcTree = new MonteCarloNode(&game);
	// int nbWon = simulate(mcTree, nbParties, false, UCB1);
	// std::cout << "Monte-Carlo a gagne " << nbWon << "/" << nbParties << " parties" << std::endl;

	// mcTree->deleteChildren();
	// delete mcTree;

	// For testing purpose
	// g.printGraph(); // Only works on graph generated from a dot file using getGraphFromDot
	// std::this_thread::sleep_for(std::chrono::milliseconds(2000));
	// End for testing purpose
}
int main() {

  std::cout << "start of main" << std::endl;

  // ====================================================
  // SINGLE OWNER SMART POINTERS
  // ====================================================

  // first, without smart pointers!
  Balloon* alice(new Balloon("Hello Kitty"));

  // now, with our homemade single owner smart pointer
  dsAutoPtr<Balloon> bob(new Balloon("Spiderman"));

  // both alice & bob work like regular pointers...
  alice->print();
  bob->print();



  //
  // CHECKPOINT 2A: INSERT NECESSARY EXPLICIT DEALLOCATION
  //
  delete alice;



  // ====================================================
  // SIMPLE SHARED POINTERS
  // ====================================================

  // first, without smart pointers
  Balloon* cathy(new Balloon("Buzz Lightyear"));
  Balloon* daniel(cathy);
  Balloon* elaine(new Balloon("Pokemon"));
  Balloon* fred(elaine);
  daniel = fred;
  fred = NULL;
  elaine = cathy;
  cathy = NULL;



  //
  // CHECKPOINT 2B: INSERT NECESSARY EXPLICIT DEALLOCATION
  //
  delete elaine;
  delete daniel;

  daniel = NULL;
  elaine = NULL;


  // now, with our homemade shared pointer
  dsSharedPtr<Balloon> cathy2(new Balloon("Buzz Lightyear2"));
  dsSharedPtr<Balloon> daniel2(cathy2);
  dsSharedPtr<Balloon> elaine2(new Balloon("Pokemon2"));
  dsSharedPtr<Balloon> fred2(elaine2);
  daniel2 = fred2;
  fred2 = NULL;
  elaine2 = cathy2;
  cathy2 = NULL;
   // NOTE:  no explicit destruction required!
  daniel2 = NULL;
  elaine2 = NULL;


  // ====================================================
  // SHARED POINTERS WITH INTERCONNECTED STRUCTURES
  // ====================================================

  dsSharedPtr<Balloon> georgette(new Balloon("Mr Potato Head"));
  dsSharedPtr<Balloon> henry(new Balloon("Snoopy"));

  georgette->addRope2(henry);
  henry = new Balloon("Tigger");
  georgette->addRope2(henry);
  georgette->print2();
  henry->print2();

  dsSharedPtr<Balloon> isabelle(new Balloon("Shrek"));
  henry->addRope2(isabelle);
  isabelle = new Balloon("Barney the Purple Dinosaur");
  georgette->addRope2(isabelle);

  henry->print2();
  georgette->print2();
  isabelle->print2();


  //
  // CHECKPOINT 2C: REWRITE THE ABOVE EXAMPLE TO USE SHARED POINTERS
  //



  // ====================================================
  // CYCLIC STRUCTURES
  // ====================================================


  // FOR CHECKPOINT 3



  Balloon* jacob(new Balloon("Dora the Explorer"));
  Balloon* katherine(new Balloon("Kung Fu Panda"));
  Balloon* larry(new Balloon("Scooby Doo"));
  Balloon* miranda(new Balloon("SpongeBob SquarePants"));
  Balloon* nicole(new Balloon("Papa Smurf"));

  jacob->addRope(katherine);
  katherine->addRope(larry);
  larry->addRope(jacob);
  miranda->addRope(jacob);
  nicole->addRope(miranda);
  larry->addRope(nicole);

  katherine = NULL;
  larry = NULL;
  miranda = NULL;
  nicole = NULL;

  // jacob points to a cyclic structure!

  // to cleanup this structure:
  deleteAll(jacob);
  //delete jacob;

  jacob = NULL;




  std::cout << "end of main" << std::endl;
  return 0;

  //
  // NOTE: when smart pointers go out of scope, the destructors for
  //       those objects will be called automatically
  //
}