Ejemplo n.º 1
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;
}
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();
}
Ejemplo n.º 3
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;
};
Ejemplo n.º 4
0
int main()
{
	{
		Sorcerer	robert("Robert", "the Magnificient");
		
		Victim		jim("Jimmy");
		Peon		joe("Joe");
		
		std::cout << robert << jim << joe;
		
		robert.polymorph(jim);
		robert.polymorph(joe);
	}
	{
		Victim joe("Joe");
		Victim sarah = joe;
		Victim bob(sarah);

		std::cout << joe << sarah << bob;
		joe.getPolymorphed();
		sarah.getPolymorphed();
		bob.getPolymorphed();

		Peon pepe("Pepe");
		Peon carl = pepe;
		Peon martin(carl);
		Victim bobby = martin;
		Victim sar(carl);

		std::cout << pepe << carl << martin << bobby << sar;
	}
	return 0;
}
int main() {
  // NOTES: BEGIN INCLUSION
  std::string bob((std::istream_iterator<char>(std::cin)),
                  std::istream_iterator<char>());
  // NOTES: END INCLUSION
  return 0;
}
Ejemplo n.º 6
0
static void
run_daemon()
{
    std::thread bob(sink_thread);
    /* Wait for child process. */
    int status;
    int pid;
    if ((pid = wait(&status)) == -1) {
        perror("wait error");
    } else {
        // Check status.
        if (WIFSIGNALED(status) != 0)
            std::cout << "Child process ended because of signal " <<
                    WTERMSIG(status) << std::endl;
        else if (WIFEXITED(status) != 0)
            std::cout << "Child process ended normally; status = " <<
                    WEXITSTATUS(status) << std::endl;
        else
            std::cout << "Child process did not end normally" << std::endl;
    }
    std::cout << "Finished waiting for child" << std::endl;
    done = true;
    // wait for thread
    bob.join();
}
Ejemplo n.º 7
0
uhr::uhr( parameter &p )
{
  sprintf( errname, "%s/error", p.path );
  error_handler bob("uhr::Constructor",errname);

  start_clock = clock();
  start_time  = time( &start_time );

  h_cpu = m_cpu = s_cpu = 0;
  h_sys = m_sys = s_sys = 0;
}
Ejemplo n.º 8
0
void showTimerEditWindow( eWidget *parent, int type, Channel *cp, Program *pp, time_t preOffset, time_t postOffset )
{
	int timerType = ePlaylistEntry::SwitchTimerEntry;

        switch ( type ) {
                case timerEditRecord:
                        timerType = ePlaylistEntry::RecTimerEntry|ePlaylistEntry::recDVR;
                        break;
                case timerEditNGRAB:
                        timerType = ePlaylistEntry::RecTimerEntry|ePlaylistEntry::recNgrab;
                        break;
                default:
                        break;
        }

	EITEvent tempEvent;

        tempEvent.start_time = pp->getStartTime() - preOffset;

        time_t end = pp->getEndTime() + postOffset;

        tempEvent.duration = (int) ( end - tempEvent.start_time );

        eServiceReferenceDVB sref = cp->getServiceRef();

	// Want to restore this afterwards, in case we disturb
	// something else in enigma (I'm not clear what it's used
	// for)

	eString oldServiceDescr = sref.descr;

	sref.descr = getFullServiceName( cp->getServiceRef() ) + eString( "/" ) + pp->getTitle();

        eTimerManager *timerMgrP = eTimerManager::getInstance();

        if ( type == timerEditDelete ) {
                ePlaylistEntry* p = timerMgrP->findEvent( &sref, &tempEvent );

                if ( p )
                        timerMgrP->removeEventFromTimerList( parent, *p,eTimerManager::erase );
                else
                        showTimerListWindow();
        }
        else {
                eTimerEditView bob( tempEvent, timerType, sref );
		showExecHide( &bob );
        }

	sref.descr = oldServiceDescr;

        timerMgrP->saveTimerList();
}
Ejemplo n.º 9
0
int		main(void)
{
	try
	{
		Bureaucrat	bob("bob", 151);
	}
	catch (std::exception const& e)
	{
		std::cout << "bob: " << e.what() << std::endl;
	}
	Bureaucrat	michel_base;
	Bureaucrat	michel_grade("michel", 1);
	Bureaucrat	bob_base("bob", 150);
	Bureaucrat	bob_grade("bob_grade", 42);

	std::cout
		<< michel_base
		<< std::endl
		<< michel_grade
		<< std::endl
		<< bob_base
		<< std::endl
		<< bob_grade
		<< std::endl;
	try
	{
		michel_grade.incGrade();
	}
	catch (std::exception const& e)
	{
		std::cout << michel_grade << ": "<< e.what() << std::endl;
	}
	michel_base.incGrade();
	std::cout << michel_base << std::endl;
	michel_base.decGrade();
	std::cout << michel_base << std::endl;
	try
	{
		michel_grade.incGrade();
	}
	catch (std::exception const& e)
	{
		std::cout << michel_grade << ": " << e.what() << std::endl;
	}
	std::cout << bob_grade << std::endl;
	bob_grade.decGrade();
	std::cout << bob_grade << std::endl;
	bob_grade.decGrade();
	std::cout << bob_grade << std::endl;
}
Ejemplo n.º 10
0
int main(int argc, char *argv[]) {
  Waiter bob("Bob Apple", 314L, 5);
  Singer bev("Beverly Hills", 522L, 3);
  Waiter w_temp;
  Singer s_temp;
  Worker * pw[LIM] = { &bob, &bev, &w_temp, &s_temp};
  int i;
  for (i = 2; i < LIM; i++)
    pw[i]->Set();
  for (i = 0; i < LIM; i++) {
    pw[i]->Show();
    std::cout <<  std::endl;
  }
  return 0;
}
Ejemplo n.º 11
0
/**
 *  lädt eine BOB-File in ein ArchivInfo.
 *
 *  @param[in]  file    Dateiname der BOB-File
 *  @param[out] items   ArchivInfo-Struktur, welche gefüllt wird
 *
 *  @return Null bei Erfolg, ein Wert ungleich Null bei Fehler
 */
int libsiedler2::loader::LoadBOB(const std::string& file, const ArchivItem_Palette* palette, ArchivInfo& items)
{
    unsigned int header;

    if(file.empty() || palette == NULL)
        return 1;

    // Datei zum lesen öffnen
    boost::iostreams::mapped_file_source mmapFile;
    try {
        mmapFile.open(bfs::path(file));
    } catch(std::exception& e) {
        std::cerr << "Could not open '" << file << "': " << e.what() << std::endl;
        return 2;
    }
    typedef boost::iostreams::stream<boost::iostreams::mapped_file_source> MMStream;
    MMStream mmapStream(mmapFile);
    libendian::EndianIStream<false, MMStream& > bob(mmapStream);

    // hat das geklappt?
    if(!bob)
        return 2;

    // Header einlesen
    bob >> header;

    // ist es eine BOB-File? (Header 0xF601F501)
    if(header != 0x01F501F6)
        return 4;

    ArchivItem_Bob* item = dynamic_cast<ArchivItem_Bob*>(getAllocator().create(BOBTYPE_BOB));

    boost::filesystem::path filePath(file);
    if(filePath.has_filename())
        item->setName(filePath.filename().string());

    if(item->load(bob.getStream(), palette) != 0) {
        delete item;
        return 5;
    }

    // Item alloziieren und zuweisen
    items.clear();
    items.push(item);

    return 0;
}
BSONObj ClusterCommandTestFixture::_makeCmd(BSONObj cmdObj, bool includeAfterClusterTime) {
    BSONObjBuilder bob(cmdObj);
    // Each command runs in a new session.
    bob.append("lsid", makeLogicalSessionIdForTest().toBSON());
    bob.append("txnNumber", TxnNumber(1));
    bob.append("autocommit", false);
    bob.append("startTransaction", true);

    BSONObjBuilder readConcernBob = bob.subobjStart(repl::ReadConcernArgs::kReadConcernFieldName);
    readConcernBob.append("level", "snapshot");
    if (includeAfterClusterTime) {
        readConcernBob.append("afterClusterTime", kAfterClusterTime);
    }

    readConcernBob.doneFast();
    return bob.obj();
}
Ejemplo n.º 13
0
int	main(void) {
    {
        Weapon club = Weapon("crude spiked club");
        HumanA bob("Bob", club);
        bob.attack();
        club.setType("some other type of club");
        bob.attack();
    }
    {
        Weapon club = Weapon("crude spiked club");
        HumanB jim("Jim");
        jim.setWeapon(club);
        jim.attack();
        club.setType("some other type of club");
        jim.attack();
    }
}
Ejemplo n.º 14
0
Archivo: text.c Proyecto: hankem/jed
static void skip_chars_backward (char *range, int invert)
{
   SLwchar_Lut_Type *lut;
   int ignore_combining = 1;
   int no_newline;

   if (*range == '^')
     {
	invert = !invert;
	range++;
     }

   if (NULL == (lut = SLwchar_strtolut ((SLuchar_Type *)range, 1, 1)))
     return;

   no_newline = (0 == SLwchar_in_lut (lut, '\n'));
   if (invert)
     no_newline = !no_newline;

   do
     {
	unsigned char *p = CLine->data + Point;
	unsigned char *pmin = CLine->data;

	p = SLwchar_bskip_range (lut, pmin, p, ignore_combining, invert);
	if (p == NULL)
	  {
	     SLwchar_free_lut (lut);
	     return;
	  }
	jed_position_point (p);
	if (p > pmin)
	  {
	     SLwchar_free_lut (lut);
	     return;
	  }
	if (no_newline)
	  {
	     SLwchar_free_lut (lut);
	     return;
	  }
     }
   while (jed_up (1));
   SLwchar_free_lut (lut);
   bob ();
}
Ejemplo n.º 15
0
void WiredTigerRecordStore::appendCustomStats(OperationContext* txn,
                                              BSONObjBuilder* result,
                                              double scale) const {
    result->appendBool("capped", _isCapped);
    if (_isCapped) {
        result->appendIntOrLL("max", _cappedMaxDocs);
        result->appendIntOrLL("maxSize", static_cast<long long>(_cappedMaxSize / scale));
        result->appendIntOrLL("sleepCount", _cappedSleep.load());
        result->appendIntOrLL("sleepMS", _cappedSleepMS.load());
    }
    WiredTigerSession* session = WiredTigerRecoveryUnit::get(txn)->getSession(txn);
    WT_SESSION* s = session->getSession();
    BSONObjBuilder bob(result->subobjStart(kWiredTigerEngineName));
    {
        BSONObjBuilder metadata(bob.subobjStart("metadata"));
        Status status = WiredTigerUtil::getApplicationMetadata(txn, getURI(), &metadata);
        if (!status.isOK()) {
            metadata.append("error", "unable to retrieve metadata");
            metadata.append("code", static_cast<int>(status.code()));
            metadata.append("reason", status.reason());
        }
    }

    std::string type, sourceURI;
    WiredTigerUtil::fetchTypeAndSourceURI(txn, _uri, &type, &sourceURI);
    StatusWith<std::string> metadataResult = WiredTigerUtil::getMetadata(txn, sourceURI);
    StringData creationStringName("creationString");
    if (!metadataResult.isOK()) {
        BSONObjBuilder creationString(bob.subobjStart(creationStringName));
        creationString.append("error", "unable to retrieve creation config");
        creationString.append("code", static_cast<int>(metadataResult.getStatus().code()));
        creationString.append("reason", metadataResult.getStatus().reason());
    } else {
        bob.append("creationString", metadataResult.getValue());
        // Type can be "lsm" or "file"
        bob.append("type", type);
    }

    Status status =
        WiredTigerUtil::exportTableToBSON(s, "statistics:" + getURI(), "statistics=(fast)", &bob);
    if (!status.isOK()) {
        bob.append("error", "unable to retrieve statistics");
        bob.append("code", static_cast<int>(status.code()));
        bob.append("reason", status.reason());
    }
}
Ejemplo n.º 16
0
int				main(void)
{
	Form			form1("form1", 5, 5);
	Form			form2("form2", 10, 5);
	Bureaucrat		bob("bob", 1);
	Bureaucrat		roger("roger", 6);

	std::cout << form1 << form2 << bob << roger;
	bob.signForm(form1);
	std::cout << form1 << form2 << bob << roger;
	bob.signForm(form2);
	std::cout << form1 << form2 << bob << roger;
	roger.signForm(form1);
	std::cout << form1 << form2 << bob << roger;
	roger.signForm(form2);
	std::cout << form1 << form2 << bob << roger;
	return (0);
}
Ejemplo n.º 17
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;
}
Ejemplo n.º 18
0
int main()
{
	Waiter bob("Luke Sky", 314L, 5);
	Singer bev("Beverly H", 522L, 3);
	Waiter w_tmp;
	Singer s_tmp;

	Worker * pv[LIM] = { &bob, &bev, &w_tmp, &s_tmp };

	int i;
	for (i = 2; i < LIM; ++i)
		pv[i]->Set();
	for (i = 0; i < LIM; ++i)
	{
		pv[i]->Show();
		std::cout << std::endl;
	}
	return 0;
}
Ejemplo n.º 19
0
int main()
{
    Waiter bob("Robert Gruszka", 314L, 5);
    Singer bev("Beverly Hills", 522L, 3);
    Waiter w_temp;
    Singer s_temp;

    Worker * pw[LIM] = {&bob, &bev, &w_temp, &s_temp};

    int i;
    for (i = 2; i < LIM; i++)
        pw[i]->Set();
    for (i = 0; i < LIM; i++)
    {
        pw[i]->Show();
        std::cout << std::endl;
    }

    return 0;
}
Ejemplo n.º 20
0
int main() {
    int a = 2;
    int b = 3;
    //if (a == 2) {
    //   return a;
   // }
    
    //int x;
    //int y;
    //int x = bob(fred(a));
    //int y = 0;
    int xp = bob(a);
    int yp = fred(b);
    if (xp + yp == 2) {
       xp = a;
    }
   // int x = bob(fred(a));
   // int y = fred(bob(b));
    return xp + yp;
}
Ejemplo n.º 21
0
//template <typename T>
std::vector< int64_t > rand_permute(const int64_t& N, std::default_random_engine& rand_gen)
{
  std::vector< int64_t > permuted(N, 0);
  std::vector< float64_t > permuted_probs(N, 0);
  std::uniform_real_distribution<float64_t> dist(0.0,  1.0); //Does NOT include B, i.e. [0, 1)
  for(size_t a=0; a<N; ++a)
    {
      permuted[a] = a;
      permuted_probs[a] =  dist(rand_gen);
    }
  
  //sort it
  sorter<float64_t> bob( &permuted_probs[0] , permuted_probs.size() );
  bob.add_l( &permuted[0] ); //lol must be int, what if we make size_T? Need to mod sorter algo?
  
  bob.runsort();
  
  //and now we check ordering of index values if we want...?
  return permuted;
}
Ejemplo n.º 22
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);
}
Ejemplo n.º 23
0
int main()
{
    Person fredi("Fredi", 28);
    Person mari("Mari", 26);
    Person bella("Bella", 1);
    Person bob("Bob", 30);

    std::list<Person> myList;

    myList.push_back(fredi);
    myList.push_back(mari);
    myList.push_back(bella);
    myList.push_back(bob);

    myList.remove_if(PersonDoesNotMeetRequirements());

    std::cout << "myList contains:";
    for (std::list<Person>::iterator itr = myList.begin(); itr != myList.end(); ++itr)
        std::cout << " " << (*itr).GetName();
    std::cout << std::endl;

    return 0;
}
Ejemplo n.º 24
0
Archivo: main.c Proyecto: omid111/yao
/**
 *  @brief act as a client in the protocol.
 *
 *  @param host string representing the host name.
 *  @param portno the port number to connect to.
 *  @return non-zero on failure.
 */
int client(char *host, int portno)
{
  int error;
  struct sockaddr_in servAddr;
  int socketDesc = socket(PF_INET, SOCK_STREAM, 0);

  debug("Created a socket %d\n", socketDesc);

  if(socketDesc < 0)
  {
    debug("couldnt get a client socket\n");
    error = -1;
    goto done;
  }

  memset((unsigned char *) &servAddr, 0, sizeof(servAddr));

  servAddr.sin_addr.s_addr = inet_addr(host);
  servAddr.sin_family = PF_INET;
  servAddr.sin_port = htons(portno);

  //make a connection
  if(connect(socketDesc, (struct sockaddr *) &servAddr, sizeof(servAddr)) < 0)
  {
    debug("could not get a connection\n");
    error = -2;
    goto done;
  }

  debug("accepted a connection with fd %d\n", socketDesc);
  error = bob(secret, socketDesc);

done:
  close(socketDesc);
  return error;
}
Ejemplo n.º 25
0
TEST(Optional, Comparisons) {
  Optional<int> o_;
  Optional<int> o1(1);
  Optional<int> o2(2);

  EXPECT_TRUE(o_ <= o_);
  EXPECT_TRUE(o_ == o_);
  EXPECT_TRUE(o_ >= o_);

  EXPECT_TRUE(o1 < o2);
  EXPECT_TRUE(o1 <= o2);
  EXPECT_TRUE(o1 <= o1);
  EXPECT_TRUE(o1 == o1);
  EXPECT_TRUE(o1 != o2);
  EXPECT_TRUE(o1 >= o1);
  EXPECT_TRUE(o2 >= o1);
  EXPECT_TRUE(o2 > o1);

  EXPECT_FALSE(o2 < o1);
  EXPECT_FALSE(o2 <= o1);
  EXPECT_FALSE(o2 <= o1);
  EXPECT_FALSE(o2 == o1);
  EXPECT_FALSE(o1 != o1);
  EXPECT_FALSE(o1 >= o2);
  EXPECT_FALSE(o1 >= o2);
  EXPECT_FALSE(o1 > o2);

  /* folly::Optional explicitly doesn't support comparisons with contained value
  EXPECT_TRUE(1 < o2);
  EXPECT_TRUE(1 <= o2);
  EXPECT_TRUE(1 <= o1);
  EXPECT_TRUE(1 == o1);
  EXPECT_TRUE(2 != o1);
  EXPECT_TRUE(1 >= o1);
  EXPECT_TRUE(2 >= o1);
  EXPECT_TRUE(2 > o1);

  EXPECT_FALSE(o2 < 1);
  EXPECT_FALSE(o2 <= 1);
  EXPECT_FALSE(o2 <= 1);
  EXPECT_FALSE(o2 == 1);
  EXPECT_FALSE(o2 != 2);
  EXPECT_FALSE(o1 >= 2);
  EXPECT_FALSE(o1 >= 2);
  EXPECT_FALSE(o1 > 2);
  */

  // boost::optional does support comparison with contained value, which can
  // lead to confusion when a bool is contained
  boost::optional<int> boi(3);
  EXPECT_TRUE(boi < 5);
  EXPECT_TRUE(boi <= 4);
  EXPECT_TRUE(boi == 3);
  EXPECT_TRUE(boi != 2);
  EXPECT_TRUE(boi >= 1);
  EXPECT_TRUE(boi > 0);
  EXPECT_TRUE(1 <  boi);
  EXPECT_TRUE(2 <= boi);
  EXPECT_TRUE(3 == boi);
  EXPECT_TRUE(4 != boi);
  EXPECT_TRUE(5 >= boi);
  EXPECT_TRUE(6 >  boi);

  boost::optional<bool> bob(false);
  EXPECT_TRUE(bob);
  EXPECT_TRUE(bob == false); // well that was confusing
  EXPECT_FALSE(bob != false);
}
Ejemplo n.º 26
0
main()
{
	printf("%d\n", crappy_max(100, 200));
	printf("%d\n", crappy_max(200, 200));
	printf("%d\n", crappy_max(200, 100));
	printf("%d\n", crappy_max(100, 100));

	printf("%d %s\n", args(3));

	/* recursive substiution support is important */
	printf("%d\n", doug(bob(123,456), doug(123, 456)));
	printf("%d\n", bob(123,456));
	printf("%d\n", bob( bob(123,456), bob(123,456) ));
	printf("%d\n", bob( bob(bob(123,456),456), bob(123,456) ));
	printf("%d\n", bob( bob(bob(123,bob(123,456)),456), bob(123,456) ));

	/* XXX: this one doesn't work yet */
	/*
	printf("%d\n", bob(	bob(123,456), 
				bob(123,456) ));
	*/
}
Ejemplo n.º 27
0
void alice(int r1,int r2,int c1,int c2)
{
    if(r2<r1 || c2<c1)
    {
        return 0;
    }


    ull fr=0,lr=0,fc=0,lc=0,min;
    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];
    }

    min=fr;
    choice=1;
    if(lr<min)
    {
        min=lr;
        choice=2;
    }

    if(fc<min)
    {
        min=fc;
        choice=3;
    }

    if(lc<min)
    {
        min=lc;
        choice=4;
    }
    ac+=min;
    switch(choice)
    {
        case 1:
            bob(r1+1,r2,c1,c2);
            break;
        case 2:
            bob(r1,r2-1,c1,c2);
            break;
        case 3:
            bob(r1,r2,c1+1,c2);
            break;
        case 4:
            bob(r1,r2,c1,c2-1);
            break;

    }
}
Ejemplo n.º 28
0
Archivo: init12.C Proyecto: 0day-ci/gcc
int main()
{
    char a[1][2];
    a[0] = bob();// { dg-error "" } .*
}
Ejemplo n.º 29
0
int main() 
{ 
   bob("Hello World"); 
   exit(0); 
}
Ejemplo n.º 30
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
}