void Player::play(){ //play the game // Player would increase step every time one makes a movement, // And modify it depthlimit every 5 steps gameOver = 0; // nobody wins the game step = 0; depthLimit_ = 7; sab.setDepthLimit(depthLimit_); if (role == MIN) { takeIn(); curState.print(); } move(); putOut(); curState.print(); takeIn(); curState.print(); while (gameOver == 0) { move(); putOut(); curState.print(); if (gameOver == 0) { takeIn(); curState.print(); } } checkGame(); }
bool NetworkWorker::connect(const std::string& host, int port, const std::string& nick) { { Glib::Threads::Mutex::Lock lock(m_mutex); if (!m_network.disconnected || network_connect(&m_network, host.c_str(), port) == RET_FAILURE) return false; this->start(); } putOut("NICK %s\r\nUSER %s %s %s :myirc of Raphy & Bart\r\n", nick.c_str(), nick.c_str(), nick.c_str(), host.c_str()); return true; }
Item* Crafter::craft(Item_t it){ Item_t miss = IT_NONE; printf("craft()\n"); recipe rec = getRecipe(it); if(!craftable(it, &miss)){ printf("not enought ressources...\n"); return NULL; } printf("youp\n"); _nbIron -= rec.nbIron; _nbGold -= rec.nbGold; _nbRuby -= rec.nbRuby; return putOut(it); }
void phase2(char* outputFileName, int numberOfFiles) { int bufferSize = 15000000; /* size of the input buffers*/ char * recordStart; /* start position of the record */ char * recordEnd; /* end position of the record */ recType rec; int index; /* identify the run we are dealing with */ std::string tempName = "temp"; PhaseTwoInfo * info; /* initialize struct info */ info = new PhaseTwoInfo; info->numberOfFiles = numberOfFiles; info->inputFile = new std::ifstream *[numberOfFiles]; info->inputBufferArray = new Buffer*[numberOfFiles]; info->parRec = new partialRecord*[numberOfFiles]; info->currentRecord = new int[numberOfFiles]; info->endOfBuffer = new bool[numberOfFiles]; info->eof = new bool[numberOfFiles]; info->outputFile = new std::ofstream; info->outputFile->open(outputFileName,std::ios::binary); if (!info->outputFile->is_open()) { std::cout<<"error opening output file"<<std::endl; exit(-1); } info->outputBuffer = new Buffer; info->outputBuffer->buffer = new char[bufferSize+MAX_LENGTH]; info->outputBuffer->bufferSize = bufferSize+MAX_LENGTH; info->outputBuffer->bufferLength = 0; info->bufferSize = bufferSize; for (int i = 0; i < numberOfFiles; i++) { //info->eof[i] = new bool; //info->endOfBuffer[i] = new bool; //info->currentRecord[i] = new int; info->parRec[i] = new partialRecord; info->parRec[i]->partial = false; info->inputBufferArray[i] = new Buffer; info->inputBufferArray[i]->buffer = new char[bufferSize]; info->inputBufferArray[i]->bufferSize = bufferSize; info->inputFile[i] = new std::ifstream; info->inputFile[i]->open(tempName+std::to_string(i),std::ios::binary); info->inputFile[i]->read(info->inputBufferArray[i]->buffer, bufferSize); info->eof[i] = false; info->endOfBuffer[i] = false; /* initialize the RecordList*/ recordStart = info->inputBufferArray[i]->buffer; recordEnd = (char*) std::memchr(recordStart,'\n', info->inputBufferArray[i]->buffer+10000-recordStart); rec.size = recordEnd-recordStart+1; rec.data = recordStart; info->currentRecord[i] = rec.size; info->recordList.push_back(rec); } /* our main loop */ while ((index = getLeast(info)) != -1) { //std::cout<<"index "<<index<<std::endl; putOut(info, index); getNext(info,index); } /* write the records of the last buffer to the output file */ if (info->outputBuffer->bufferLength != 0) { info->outputFile->write(info->outputBuffer->buffer,info->outputBuffer->bufferLength); } }