示例#1
0
winner tieBreaker(uint8_t * const handA, uint8_t * const handB) {
    uint32_t i;
    for(i=0; i<HAND_SIZE; ++i)
        if(getRank(handA[i]) != getRank(handB[i]))
            return getRank(handA[i]) > getRank(handB[i]) ? PLAYER_ONE : PLAYER_TWO;
    return TIE;
}
示例#2
0
template<> bool Communicator::bcast(std::string& v, int origin_rank) {
  unsigned int length = 0;
  if (origin_rank == getRank()) {
    length = v.length();
  }
  if (!bcast(length, origin_rank)) {
    std::cerr << "Failed to bcast string length." << std::endl;
    return false;
  }
  if (0 == length) {
    v = "";
    return true;
  }
  if (origin_rank == getRank()) {
    if (!bcast(v.c_str(), length, origin_rank)) {
      std::cerr << "Failed to bcast string contents." << std::endl;
      return false;
    }
  } else {
    char* buf = new char[length];
    if (!bcast(buf, length, origin_rank)) {
      std::cerr << "Failed to bcast string contents (recv)." << std::endl;
      delete [] buf;
      return false;
    }
    v = std::string(buf, length);
    delete [] buf;
  }
  return true;
}
int VotePacket::betterThanThis(int32 myRank, uint16 myPort) const
{
   uint32 localIP;
  
   mc2dbg8 << "[VotePacket] myRank: " << myRank << " packet rank: "
           << getRank() << endl;
   // First compare ranks 
   if(getRank() > myRank)
      return -1;
   if(getRank() < myRank)
      return 1;

   localIP = NetUtility::getLocalIP();
   if(getOriginIP() < localIP)
      return 1;
   if(getOriginIP() > localIP)
      return -1;

   // He's running on my computer. Compare ports
   if(getOriginPort() < myPort)
      return 1;
   if(getOriginPort() > myPort)
      return -1;

   // We should never be here!
   mc2log << error << "[VotePacket] BUG! betterThanThis(): "
          << "We have two modules with the same IP and port. Impossible!"
          << endl;

   return 0;

}
示例#4
0
void orderHand(uint8_t * const hand) {
    /* Selection Sort is optimal for small sets */
    uint32_t i,j,k;
    for(i=0; i<HAND_SIZE; swap(hand,i++,k))
        for(k=j=i; j<HAND_SIZE; ++j)
            if(getRank(hand[j]) > getRank(hand[k]))
                k=j;
}
示例#5
0
bool Shape::sameDims(const Shape &other) const
{
	if (getRank() != other.getRank()) return false;

	for (int i=0; i<getRank(); ++i) {
		if (getDim(i) != other.getDim(i)) return false;
	}
	return true;
}
示例#6
0
uint8_t isXOfKind(uint8_t * const hand,const uint32_t x) {
    uint32_t i,j,match;
    for(i=0; i<=HAND_SIZE-x; ++i) {
        for(j=0,match=1; match && j<x-1; ++j)
            match = getRank(hand[i+j]) == getRank(hand[i+j+1]);
        if(match)
            return organizeXOfKind(hand,getRank(hand[i])), getRank(hand[0]);
    }
    return 0x00;
}
示例#7
0
文件: 1111.c 项目: saki45/OJ
int main(){
	int bCards[15][4], bCardsSum[15], wCards[15][4], wCardsSum[15], i, hash[256], bRank, wRank;
	int bWin, wWin, cmpResult;
	char buf[50], *str;

	memset(hash, 0, sizeof(hash));
	for(i='2'; i<='9'; i++){
		hash[i] = i-'2'+2;
	}
	hash['T'] = 10;
	hash['J'] = 11;
	hash['Q'] = 12;
	hash['K'] = 13;
	hash['A'] = 14;

	hash['C'] = 0;
	hash['D'] = 1;
	hash['H'] = 2;
	hash['S'] = 3;

	while(fgets(buf, sizeof(buf), stdin) != NULL){
		bWin = 0;
		wWin = 0;

		str = buf;
		str = processCards(bCards, bCardsSum, str, hash);
		processCards(wCards, wCardsSum, str, hash);

		bRank = getRank(bCards, bCardsSum);
		wRank = getRank(wCards, wCardsSum);

		if(bRank>wRank)
			bWin = 1;
		else if(wRank>bRank)
			wWin = 1;
		else{
			cmpResult = compareSameRank(bCardsSum, wCardsSum, bRank);
			if(cmpResult > 0)
				bWin = 1;
			else if(cmpResult < 0)
				wWin = 1;
		}

		if(bWin)
			printf("Black wins.\n");
		else if(wWin)
			printf("White wins.\n");
		else
			printf("Tie.\n");
	}
	return 0;
}
示例#8
0
uint8_t  isTwoPair      (uint8_t * const hand) {
    uint32_t i,j,x;
    if(!isXOfKind(hand,2))
        return 0;
    for(i=2,x=0; !x && i<HAND_SIZE; ++i)
        for(j=i+1; !x && j<HAND_SIZE; ++j)
            if(getRank(hand[i])==getRank(hand[j]))
                x = i;
    if(!x)
        return 0;
    if(x != 2)
        swap(hand,2,HAND_SIZE-1);
    return getRank(hand[0]);
}
示例#9
0
    bool recvData(std::vector<double>& receivedData)
    {
        bool isDataReceived = false;
        if ( intraComm != MPI::COMM_NULL)
        {
            MPI::Status status;
            double buffer[100];
            intraComm.Recv(buffer, 100,
                           MPI::DOUBLE,
                           MPI::ANY_SOURCE,
                           /*tag*/ 100,
                           status);

            int count = status.Get_count(MPI::DOUBLE);
            receivedData = std::vector<double>(buffer, buffer+count);

            log.Info() << "RECV [ " << getRank()
                        << " <-- "
                        << status.Get_source()
                        << " ] data : "
                        << receivedData
                        << std::endl;
            isDataReceived = true;
        }else
        {
            log.Err() << "PID " << getProcessId()
                      << " failed to RECV"
                      << std::endl;
        }
        return isDataReceived;
    }
示例#10
0
std::string Square::toString() const {
  std::ostringstream oss;

  oss << (int)getFile() << (int)getRank();

  return oss.str();
}
示例#11
0
		void CalendarTemplateElement::toParametersMap( util::ParametersMap& map, bool withAdditionalParameters, boost::logic::tribool withFiles /*= boost::logic::indeterminate*/, std::string prefix /*= std::string() */ ) const
		{
			map.insert(TABLE_COL_ID, getKey());
			map.insert(
				CalendarTemplateElementTableSync::COL_CALENDAR_ID,
				getCalendar() ? getCalendar()->getKey() : RegistryKeyType(0)
			);
			map.insert(
				CalendarTemplateElementTableSync::COL_RANK,
				getRank()
			);
			map.insert(
				CalendarTemplateElementTableSync::COL_MIN_DATE,
				getMinDate().is_special() ? string() : to_iso_extended_string(getMinDate())
			);
			map.insert(
				CalendarTemplateElementTableSync::COL_MAX_DATE,
				getMaxDate().is_special() ? string() : to_iso_extended_string(getMaxDate())
			);
			map.insert(
				CalendarTemplateElementTableSync::COL_INTERVAL,
				boost::lexical_cast<std::string>(static_cast<int>(getStep().days()))
			);
			map.insert(
				CalendarTemplateElementTableSync::COL_POSITIVE,
				static_cast<int>(getOperation())
			);
			map.insert(
				CalendarTemplateElementTableSync::COL_INCLUDE_ID,
				getInclude() ? getInclude()->getKey() : RegistryKeyType(0)
			);
		}
示例#12
0
void ChocoboEditor::SetChocobo(FF7CHOCOBO choco, QString Processed_Name, bool cant_mate, quint16 stamina,quint8 rating)
{
	choco_data = choco;
	if( Processed_Name.startsWith('\xff') || Processed_Name == QString(6,'\x20')){Processed_Name ="";}
	choco_name = Processed_Name;
	choco_cant_mate = cant_mate;
	choco_stamina = stamina;
	choco_rating = rating;
	line_name->setText(choco_name);
	combo_type->setCurrentIndex(choco_data.type);
	combo_sex->setCurrentIndex(choco_data.sex);
	if(choco_cant_mate){cb_cantMate->setCheckState(Qt::Checked);}
	else{cb_cantMate->setCheckState(Qt::Unchecked);}
	sb_speed->setValue(choco_data.speed);
	sb_mSpeed->setValue(choco_data.maxspeed);
	sb_sprint->setValue(choco_data.sprintspd);
	sb_mSprint->setValue(choco_data.maxsprintspd);
	sb_stamina->setValue(choco_stamina);
	sb_accel->setValue(choco_data.accel);
	sb_wins->setValue(choco_data.raceswon);
	sb_pCount->setValue(choco_data.pcount);
	sb_coop->setValue(choco_data.coop);
	sb_intel->setValue(choco_data.intelligence);
	sb_personality->setValue(choco_data.personality);
	combo_rating->setCurrentIndex(choco_rating);
	getRank();
}
示例#13
0
void MemoryControl::issueRequest (int bank) {
  int rank = getRank(bank);
  MemoryNode req = m_bankQueues[bank].front();
  m_bankQueues[bank].pop_front();
  if (m_debug) {
    uint64 current_time = g_eventQueue_ptr->getTime();
    printf("    Mem issue request%7d: 0x%08llx %c         at %10lld  bank =%3x\n",
        req.m_msg_counter, req.m_addr, req.m_is_mem_read? 'R':'W', current_time, bank);
  }
  if (req.m_msgptr.ref() != NULL) {  // don't enqueue L3 writebacks
    enqueueToDirectory(req, m_mem_ctl_latency + m_memFixedDelay);
  }
  m_oldRequest[bank] = 0;
  markTfaw(rank);
  m_bankBusyCounter[bank] = m_bank_busy_time;
  m_busBusy_WhichRank = rank;
  if (req.m_is_mem_read) {
    g_system_ptr->getProfiler()->profileMemRead();
    m_busBusyCounter_Basic = m_basic_bus_busy_time;
    m_busBusyCounter_Write = m_basic_bus_busy_time + m_read_write_delay;
    m_busBusyCounter_ReadNewRank = m_basic_bus_busy_time + m_rank_rank_delay;
  } else {
    g_system_ptr->getProfiler()->profileMemWrite();
    m_busBusyCounter_Basic = m_basic_bus_busy_time;
    m_busBusyCounter_Write = m_basic_bus_busy_time;
    m_busBusyCounter_ReadNewRank = m_basic_bus_busy_time;
  }
}
示例#14
0
 bool readHand(FILE* fp) {
     for(int i=0;i<NumCards;++i) {
         hist[i] = 0;
     }
     for(int i=0;i<HAND_SIZE;++i) {
         char data[4];
         if(fscanf(fp,"%s",data) != 1) {
             return false;
         }
         cards[i].readCard(data[0], data[1]);
         int val = (int)cards[i].val;
         hist[val] += 1;
     }
     for(int i=0;i<HAND_SIZE;++i) {
         for(int j=i+1;j<HAND_SIZE;++j) {
             if(cards[i] < cards[j]) { // descending order
                 Card t = cards[i];
                 cards[i] = cards[j];
                 cards[j] = t;
             }
         }
     }
     getRank();
     return true;
 }
示例#15
0
bool MemoryControl::issueRefresh (int bank) {
  if (!m_need_refresh || (m_refresh_bank != bank)) return false;
  if (m_bankBusyCounter[bank] > 0) return false;
  // Note that m_busBusyCounter will prevent multiple issues during
  // the same cycle, as well as on different but close cycles:
  if (m_busBusyCounter_Basic > 0) return false;
  int rank = getRank(bank);
  if (m_tfaw_count[rank] >= ACTIVATE_PER_TFAW) return false;

  // Issue it:

  //if (m_debug) {
    //uint64 current_time = g_eventQueue_ptr->getTime();
    //printf("    Refresh bank %3x at %lld\n", bank, current_time);
  //}
  g_system_ptr->getProfiler()->profileMemRefresh();
  m_need_refresh--;
  m_refresh_bank++;
  if (m_refresh_bank >= m_total_banks) m_refresh_bank = 0;
  m_bankBusyCounter[bank] = m_bank_busy_time;
  m_busBusyCounter_Basic = m_basic_bus_busy_time;
  m_busBusyCounter_Write = m_basic_bus_busy_time;
  m_busBusyCounter_ReadNewRank = m_basic_bus_busy_time;
  markTfaw(rank);
  return true;
}
示例#16
0
Word ThRightNormalForm::getShortWord( ) const
{
  Word result;
  Permutation omega = Permutation::getHalfTwistPermutation( getRank( ) );
  int power = getPower( );

  if( power<0 ) {

    const list< Permutation >& decomp = getDecomposition( );
    list<Permutation>:: const_iterator it = decomp.begin( );
    for( int j=0 ; it!=decomp.end( ) ; ++it, ++j ) {
      int n = j - decomp.size( ) - power;
      if( n<0 ) {
	vector< int > gd = (*it).geodesic();
	for( size_t t=0 ; t<gd.size() ; ++t )
	  result.push_back( gd[t]+1 );
      } else {
	
	Permutation p = ( n%2 == 1 ? (*it).inverse() * omega : omega * (*it).inverse() );
	
	vector<int> gd = p.geodesic();
	for( int t=gd.size( )-1 ; t>=0 ; --t )
	  result.push_back( -gd[t]-1 );
      }
    }
    Word omega_w = Word(omega.geodesicWord( ));
    omega_w = -omega_w;
    for( int j=decomp.size( ) ; j<-power ; ++j )
      result = omega_w*result;
  } else
    result = getWord( );
  
  return result;
}
示例#17
0
int Shape::getNumEl() const
{
	int n = 1;
	for (int i=0; i<getRank(); ++i) {
		n *= getDim(i);
	}
	return n;
}
示例#18
0
int main() {

  char *w = "googre\0", *base[] = {
    "monk\0", "bolton\0", "goo gle\0"
  };

  char **trav = base, **end = base + sizeof(base)/sizeof(base[0]);
  int setRank = getRank(w, w);
  while (trav != end) {
    printf("\033[33mTo get %s from %s\033[00m\n", w, *trav);
    int rank = getRank(*trav, w); //w, *trav);
    printf("Base: %d Rank : %d\n", setRank, rank);
    ++trav;
  }

  return 0;
}
示例#19
0
void ChocoboEditor::setWins(int wins)
{
	if(wins <0){wins = 0;}
	else if (wins>255){wins = 255;}
	sb_wins->setValue(wins);
	choco_data.raceswon = wins;
	getRank();
}
示例#20
0
文件: SeedingData.cpp 项目: plpla/ray
void SeedingData::call_RAY_SLAVE_MODE_SEND_SEED_LENGTHS(){
	if(!m_initialized){
		for(int i=0;i<(int)m_SEEDING_seeds.size();i++){
			int length=getNumberOfNucleotides(m_SEEDING_seeds[i].size(),
				m_parameters->getWordSize());
			m_slaveSeedLengths[length]++;
		}
		m_iterator=m_slaveSeedLengths.begin();
		m_initialized=true;
		m_communicatorWasTriggered=false;


		m_virtualCommunicator->resetCounters();
	}

	if(m_inbox->size()==1&&(*m_inbox)[0]->getTag()==RAY_MPI_TAG_SEND_SEED_LENGTHS_REPLY)
		m_communicatorWasTriggered=false;
	
	if(m_communicatorWasTriggered)
		return;

	if(m_iterator==m_slaveSeedLengths.end()){
		Message aMessage(NULL,0,MASTER_RANK,
			RAY_MPI_TAG_IS_DONE_SENDING_SEED_LENGTHS,getRank());
		m_outbox->push_back(aMessage);
		(*m_mode)=RAY_SLAVE_MODE_DO_NOTHING;
		return;
	}
	
	MessageUnit*messageBuffer=(MessageUnit*)m_outboxAllocator->allocate(MAXIMUM_MESSAGE_SIZE_IN_BYTES);
	int maximumPairs=MAXIMUM_MESSAGE_SIZE_IN_BYTES/sizeof(MessageUnit)/2;
	int i=0;
	while(i<maximumPairs && m_iterator!=m_slaveSeedLengths.end()){
		int length=m_iterator->first;
		int count=m_iterator->second;
		messageBuffer[2*i]=length;
		messageBuffer[2*i+1]=count;
		i++;
		m_iterator++;
	}

	Message aMessage(messageBuffer,2*i,MASTER_RANK,
		RAY_MPI_TAG_SEND_SEED_LENGTHS,getRank());
	m_outbox->push_back(aMessage);
}
示例#21
0
 PySparseTensor innerProduct(const nta::UInt32 dim1, const nta::UInt32 dim2, const PySparseTensor& B) const
 {
   // Only works on rank 2 tensors right now
   if((getRank() != 2) || (B.getRank() != 2))
     throw std::invalid_argument("innerProduct only works for rank 2 tensors.");
   PySparseTensor C(PyTensorIndex(getBound(1-dim1),B.getBound(1-dim2)));
   tensor_.inner_product_nz(dim1, dim2, B.tensor_, C.tensor_, std::multiplies<nta::Real>(), std::plus<nta::Real>());
   return C;
 }
示例#22
0
void tarch::parallel::Node::writeTimeOutWarning( const std::string& className, const std::string& methodName, int communicationPartnerRank ) {
  std::ostringstream out;
  out << "operation " << className << "::" << methodName << " on node "
      << getRank() << " had to wait more "
      << "than " << _timeOutWarning << " seconds "
      << "for a message from node " << communicationPartnerRank << ". Application "
      << "will terminate after " << _deadlockTimeOut << " seconds because "
      << "of a deadlock";
  _log.warning( "writeTimeOutWarning(...)", out.str() );
}
示例#23
0
void organizeXOfKind(uint8_t * const hand, const uint8_t value) {
    uint32_t i,j,k;
    for(i=k=0; i<HAND_SIZE; ++i)
        if(getRank(hand[i]) == value)
            swap(hand,i,k++);
    for(i=k; i<HAND_SIZE; swap(hand,i++,k))
        for(j=i+1,k=i; j<HAND_SIZE; ++j)
            if((hand[j] & RANK_MASK) > (hand[k] & RANK_MASK))
                k=j;
}
示例#24
0
string Card::toString()
{
       string s = getRank();
       if (mySuit == 'c') s = s + char(5);
       else if (mySuit == 'd') s = s + char(4);
       else if (mySuit == 'h') s = s + char(3);
       else if (mySuit == 's') s = s + char(6);
       else s = "invalid suit";
       return s;
}
示例#25
0
void ReadAnnotation::write(ostream*f){
	int rank=getRank();
	int readIndex=getReadIndex();
	int positionOnStrand=getPositionOnStrand();
	char strand=getStrand();
	f->write((char*)&rank,sizeof(int));
	f->write((char*)&readIndex,sizeof(int));
	f->write((char*)&positionOnStrand,sizeof(int));
	f->write((char*)&strand,sizeof(char));
}
int main(int argc, char **argv) {
  if (argc == 1) {
    execlp("mpirun", "mpirun", "-n", std::to_string(WORKERS_NUM + 1).data(), argv[0], "1", NULL);
  }

  auto dataChannel = std::make_shared<thd::DataChannelMPI>();
  assert(dataChannel->init());
  assert(dataChannel->getNumProcesses() == (WORKERS_NUM + 1));
  std::cout << "OK (id: " << dataChannel->getRank() << ")" << std::endl;
  return 0;
}
示例#27
0
// translate the numeric rank of a card to a meaningful symbol.
// return the number of characters written to pRank, excluding
// the terminating '\0'.
int CCard::getCharRank(char* pRank, int maxLength) const
{
	// assume no characters are written to pRank
	int numChars = 0;

	if ((getRank() >= Ace) && (getRank() <= King)) {
		// rank is in range of Rank enum, proceed with translation

		// most ranks require a single character
		numChars = 1;

		switch(getRank())
		{
		case Ace:
			strcpy(pRank, "A");
			break;
		case Ten:
			strcpy(pRank, "10");
			// this is only rank that requires 2 characters
			numChars = 2;
			break;
		case Jack:
			strcpy(pRank, "J");
			break;
		case Queen:
			strcpy(pRank, "Q");
			break;
		case King:
			strcpy(pRank, "K");
			break;
		default:
			// ranks 2 through 9
			numChars = sprintf(pRank, "%d", getRank());
			break;
		}
	}

	pRank[numChars] = '\0';

	return(numChars);
}
示例#28
0
void ProofNode::print() {
    cout<<"<--------------->"<<endl;
    cout<<"-PROOF NODE-"<<endl;
    cout<<"Rank    : "<< getRank() 		<<endl;
    cout<<"Level   : "<< getLevel()		<<endl;
    cout<<"isInter : "; ((interFlag)?cout<<"true":cout<<"false");cout<<endl;
    cout<<"isEnd   : "; ((endFlag)?cout<<"true":cout<<"false");cout<<endl;
    cout<<"rgtOrDwn: "; ((rgtOrDwn)?cout<<"true":cout<<"false");cout<<endl;
    cout<<"Hash    : "<< getHash()		<<endl;
    cout<<"Length  : "<< length		<<endl;
    cout<<"<--------------->"<<endl;
}
示例#29
0
void SeedingData::call_RAY_SLAVE_MODE_SEND_SEED_LENGTHS(){
	if(!m_initialized){

		m_virtualCommunicator->resetCounters();

		m_initialized = true;
	}

	Message aMessage(NULL,0,MASTER_RANK,
		RAY_MPI_TAG_IS_DONE_SENDING_SEED_LENGTHS,getRank());
	m_outbox->push_back(&aMessage);
	(*m_mode)=RAY_SLAVE_MODE_DO_NOTHING;
}
示例#30
0
/********************************************************
* getInfo()												*
* Returns all the info of the pizza in a nice format	*
* No arguments											*
********************************************************/
string Hexagon::getInfo()
{
	// Let's write all the info of the pizza in a nice format
	// But these doubles and ints will get us in trouble

	// We start writing things in a nice format
	string start = "\nHexagon";

	// And now we handle the first double
	string wa = "\nArea of pizza: " + to_string(wholeArea) + " square in.";

	// For the ints, we need to get the rank in a string
	// So we use a helper method to do that for us
	string wr = "\nSize of pizza: " + getRank(whole);

	// We continue in the same fashion for the slice info
	string sa = "\nArea of slice: " + to_string(sliceArea) + " square in.";
	string sr = "\nSize of slice: " + getRank(slice);

	// Put it all together and return it
	string info = start + wa + wr + sa + sr;
	return info;
}