void MoveToStr(int move, char *move_str) { static const char prom_char[5] = "nbrq"; // Move coordinates move_str[0] = File(Fsq(move)) + 'a'; move_str[1] = Rank(Fsq(move)) + '1'; move_str[2] = File(Tsq(move)) + 'a'; move_str[3] = Rank(Tsq(move)) + '1'; move_str[4] = '\0'; // Bugfix by Dave Kaye for compatibility with Knights GUI (Linux) and UCI specs // (needed if a GUI forces the engine to analyse in checkmate/stalemate position) if (strcmp(move_str, "a1a1") == 0) { strcpy(move_str, "0000"); } // Add promoted piece, if any if (IsProm(move)) { move_str[4] = prom_char[(move >> 12) & 3]; move_str[5] = '\0'; } }
//recalculates legal card set after new card is played void Table::updateLegalCards(Card card) { //only called if card is allowed int suit = card.getSuit(); int rank = card.getRank(); std::string cardName = card.getCardName(card.getRank(), card.getSuit()); legalCards_.erase(cardName); //special case: 7S played opens all other 7's if (legalCards_.find("7S") == legalCards_.begin()) { legalCards_.insert("7C"); legalCards_.insert("7D"); legalCards_.insert("7H"); legalCards_.insert("6S"); legalCards_.insert("8S"); legalCards_.erase("7S"); } else if (rank == (7-1)) { //index of 7 is 1 less due to enum numeration legalCards_.insert(card.getCardName(Rank(card.getRank() - 1), card.getSuit())); legalCards_.insert(card.getCardName(Rank(card.getRank() + 1), card.getSuit())); } else if (rank == (13-1) || rank == (1-1)) {} //king and ace else if (rank < (7-1)) { //cards less than 7 legalCards_.insert(card.getCardName(Rank(card.getRank() - 1), card.getSuit())); } else { //cards greater than 7 legalCards_.insert(card.getCardName(Rank(card.getRank() + 1), card.getSuit())); } }
void Table::updateLegalCards(Card card) { //only called if card is allowed int suit = card.getSuit(); int rank = card.getRank(); std::string cardName = card.getCardName(card.getRank(), card.getSuit()); legalCards_.erase(cardName); // std::cout << (legalCards_.find("7S") == legalCards_.end()) << std::endl; if (legalCards_.find("7S") == legalCards_.begin()) { legalCards_.insert("7C"); legalCards_.insert("7D"); legalCards_.insert("7H"); legalCards_.insert("6S"); legalCards_.insert("8S"); legalCards_.erase("7S"); } else if (rank == (7-1)) { //index of 7 is 1 less legalCards_.insert(card.getCardName(Rank(card.getRank() - 1), card.getSuit())); legalCards_.insert(card.getCardName(Rank(card.getRank() + 1), card.getSuit())); } else if (rank < (7-1)) { legalCards_.insert(card.getCardName(Rank(card.getRank() - 1), card.getSuit())); } else { legalCards_.insert(card.getCardName(Rank(card.getRank() + 1), card.getSuit())); } }
void cEval::ScorePawns(POS *p, eData *e, int sd) { U64 bbPieces, bbSpan, fl_phalanx; int sq, fl_unopposed, fl_weak, fl_defended; int op = Opp(sd); U64 bbOwnPawns = p->Pawns(sd); U64 bbOppPawns = p->Pawns(op); // Is color OK? assert(sd == WC || sd == BC); // Loop through the pawns, evaluating each one bbPieces = bbOwnPawns; while (bbPieces) { sq = BB.PopFirstBit(&bbPieces); // Get some information about the pawn we are evaluating bbSpan = BB.GetFrontSpan(SqBb(sq), sd); fl_defended = ((SqBb(sq) & e->bbPawnTakes[sd]) != 0); fl_unopposed = ((bbSpan & bbOppPawns) == 0); fl_weak = ((Mask.supported[sd][sq] & bbOwnPawns) == 0); fl_phalanx = (BB.ShiftSideways(SqBb(sq)) & bbOwnPawns); // Candidate passer if (fl_unopposed) { if (fl_phalanx) { if (BB.PopCnt((Mask.passed[sd][sq] & bbOppPawns)) == 1) Add(e, sd, F_PAWNS, passed_bonus_mg[sd][Rank(sq)] / 3, passed_bonus_eg[sd][Rank(sq)] / 3); } } // Doubled pawn if (bbSpan & bbOwnPawns) Add(e, sd, F_PAWNS, Param.doubled_malus_mg, Param.doubled_malus_eg); // Supported pawn if (fl_phalanx) Add(e, sd, F_PAWNS, Param.phalanx[sd][sq] , 2); else if (fl_defended) Add(e, sd, F_PAWNS, Param.defended[sd][sq], 1); // Weak pawn (two flavours) if (fl_weak) { if (!(Mask.adjacent[File(sq)] & bbOwnPawns)) Add(e, sd, F_PAWNS, Param.isolated_malus_mg + Param.isolated_open_malus * fl_unopposed, Param.isolated_malus_eg); // isolated pawn else Add(e, sd, F_PAWNS, Param.backward_malus_mg[File(sq)] + Param.backward_open_malus * fl_unopposed, Param.backward_malus_eg); // backward pawn } } }
int Count(DATA data){ bool exi=Find(data); if (exi){ int aaa=Rank(data); int bbb=Rank(data()); return bbb-aaa; } else return 0; }
void TUnionFind::Union(const int& Key1, const int& Key2) { const int root1 = Find(Key1); const int root2 = Find(Key2); TInt& rank1 = Rank(root1); TInt& rank2 = Rank(root2); if (rank1 > rank2) { Parent(root2) = root1; } else if (rank1 < rank2) { Parent(root1) = root2; } else if (root1 != root2) { Parent(root2) = root1; Rank(root1)++; } }
void init_distance() { int i,j,f[2],r[2]; for(i = 0; i < 64; i++) { f[0] = File(i); r[0] = Rank(i); for(j = 0; j < 64; j++) { f[1] = File(j); r[1] = Rank(j); distance[i][j] = max(abs(r[0]-r[1]), abs(f[0]-f[1])); } } }
Value::Value(const NDArrayViewPtr& data, const NDMaskPtr& mask) : m_data(data), m_mask(mask) { if (mask != nullptr) { auto dataShape = data->Shape(); auto maskShape = mask->Shape(); if (maskShape.Rank() > dataShape.Rank()) InvalidArgument("The rank (%d) of the mask of a Value object cannot exceed the rank (%d) of the data NDArrayView object", (int)maskShape.Rank(), (int)dataShape.Rank()); if (dataShape.SubShape(dataShape.Rank() - maskShape.Rank()) != maskShape) InvalidArgument("Invalid Value object; the data and mask are incompatible. The trailing dimensions of the data with shape %S do not match the dimensions of the mask with shape %S", AsStringForErrorReporting(dataShape).c_str(), AsStringForErrorReporting(maskShape).c_str()); } }
int Rank(int &root , Type key) { if ( K[root] == key ) { return SZ[LC[root]] + 1; } else if ( key < K[root] ) { return Rank(LC[root], key); } else { return SZ[LC[root]] + 1 + Rank(RC[root] , key); } }
void PrintSubTree(FILE *OutFile, TreeNode Node, int Indent) { int i,itsrank,itslocation; itsrank = Rank(Node); fprintf(OutFile, "[%5d] ", Node); for (i=1; i <= Indent; i++) fprintf(OutFile,". "); Write_String(OutFile, NodeName(Node)); fprintf(OutFile ,"(%1d)", itsrank); itslocation = SourceLocation(Node); if(itslocation!=UndefinedString) { fprintf (OutFile, " @ "); Write_String(OutFile, itslocation); } if (Decoration(Node) != 0) fprintf(OutFile, " Decoration: %1d", Decoration(Node)); fprintf(OutFile,"\n"); for (i=1; i <= itsrank; i++) PrintSubTree (OutFile, Child(Node, i), Indent+1); }
int getPassedPawnScore(ChessBoard * board, bool white) { BITBOARD pawns = (white) ? board->whitePawns : board->blackPawns; BITBOARD originalPawns = pawns; BITBOARD otherPawns = (white) ? board->blackPawns : board->whitePawns; BITBOARD* doubledPawnMask = (white) ? whiteDoubledPawnMask : blackDoubledPawnMask; BITBOARD* passedPawnMask = (white) ? whitePassedPawnMask : blackPassedPawnMask; int* passedPawnRankScale = (white) ? EvalParameters::whitePassedPawnRankScale : EvalParameters::blackPassedPawnRankScale; int passedPawnScore = 0; while (pawns != 0) { short pawnOffset = FirstOne(pawns); pawns ^= offset_to_mask(pawnOffset); if ((passedPawnMask[pawnOffset] & otherPawns) == 0) { // pawn is passed. give bonus // check if pawn is doubled BITBOARD isDoubled = doubledPawnMask[pawnOffset] & originalPawns; if (isDoubled == 0) { if (board->gamePhase == PHASE_ENDGAME) { passedPawnScore += EvalParameters::passedPawnBonus * passedPawnRankScale[8 - Rank(pawnOffset)]; } else { passedPawnScore += (1/4.0) * EvalParameters::passedPawnBonus * passedPawnRankScale[8 - Rank(pawnOffset)]; } } // no passed pawn bonus if pawn is doubled } } return passedPawnScore; }
void ribi::Chess::QtChessBoardWidget::DrawChessBoard( QPainter& painter, const int left, const int top, const int width, const int height, const Chess::Board * const board) { static const Chess::QtResources r; const int square_w = width / 8; const int square_h = height / 8; for (int y=0; y!=8; ++y) { for (int x=0; x!=8; ++x) { const int x_co = x * square_w; const int y_co = y * square_h; const boost::shared_ptr<Square> square { SquareFactory().Create(File(x),Rank(y)) }; if (board->GetPiece(square)) { const QPixmap p(r.Find(board->GetPiece(square)).c_str()); painter.drawPixmap(left + x_co,top + y_co,square_w,square_h,p); } else { const QPixmap p(r.Find(square).c_str()); painter.drawPixmap(left + x_co,top + y_co,square_w,square_h,p); } } } }
void Add() { if(kamo==0){ puts("データを作成するか、ファイルを読み込んでください"); return; } String name[NIN]; int i,s[KAMO_MAX]; printf("No%dの名前を入力してください\n",(preno++)+1); printf("→"); name[preno]=(String)malloc(STLEN); scanf("%s",name[preno]); fflush(stdin); while(strcmp(name[preno],"0")!=0){ puts("点数を入力してください"); for(i=0;i<kamo;i++){ printf("%s : ",kam[i]); scanf("%d",&s[i]); fflush(stdin); } addData(preno,name[preno],s); printf("No%dの名前を入力してください\n",(preno++)+1); printf("→"); name[preno]=(String)malloc(STLEN); scanf("%s",name[preno]); fflush(stdin); } preno--; Rank(); }
/* This api takes the user input - and looks up the word[s] in the inverted index. The candidate documents are then ranked based on tf-idf BOW (bag of words) model */ std::vector<std::pair<int,double> > ServeIndex(const std::string& word,int topK) { //tokenize and normalize the user text std::vector<std::string>& word_tokens = _wordBreaker->BreakEnglishText(word.c_str()); std::vector<std::pair<int,double> > results; //generate the candidate document set std::set<int> candSet; bool foundAny = false; for(size_t i=0;i<word_tokens.size();++i) { boost::unordered_map<std::string,IndexEntry>::iterator itor = _indexPtr->_wordIndex.find(word_tokens[i]); if( itor == _indexPtr->_wordIndex.end() ) continue; else{ //first entry which was found if(!foundAny){ candSet = itor->second._docSet; foundAny = true; } else{ std::set<int> temp; set_intersection(candSet.begin(),candSet.end(),(itor->second)._docSet.begin(),(itor->second)._docSet.end(),inserter(temp,temp.begin())); candSet.clear(); candSet = temp; } } } return Rank(word_tokens,candSet,topK); }
void Deck::reset () { clear (); for(int i=0;i<SUIT_COUNT;i++){ for (int j=0;j<RANK_COUNT;j++){ addCard (Card (Suit(i), Rank(j))); } } }
//____________________________________________________________________ void TCommunicator::AllReduceRecvScalar(Float_t &recvScalar, const TOperation& operation) { if (!fAllReduceRootScalar.empty()) { recvScalar = fAllReduceRootScalar.front(); fAllReduceRootScalar.pop(); } else { throw TMpiException(MPI_ERR_BUFFER, Rank(), __METHOD_LONG__, ALL_REDUCE_MSG, -1, bShowExceptionMessage); } }
//____________________________________________________________________ void TCommunicator::AllReduceRecvArray(Char_t *recvArray, Int_t size , const TOperation& operation) { if (!cAllReduceRootArray.empty()) { recvArray = cAllReduceRootArray.front(); cAllReduceRootArray.pop(); } else { throw TMpiException(MPI_ERR_BUFFER, Rank(), __METHOD_LONG__, ALL_REDUCE_MSG, -1, bShowExceptionMessage); } }
/* Tests to see if the side specified is in check. */ int InCheck(const Board *B,const int side) { int kpos,kx,ky; BITBOARD rq,bq,r,b,q,mask,tsq; /* We don't have any precalculated attack information * so we'll have to do this the hard way */ /* (1) Check for king attacks. Note that if the white king * can attack the black one then vice versa too. */ if (KingMoves[B->WhiteKing]&Mask[B->BlackKing]) return king; /* It's not a king attack so let's set up some more variables. */ if (side==WHITE) kpos = B->WhiteKing; else kpos = B->BlackKing; kx = File(kpos); ky = Rank(kpos); /* (2) Check for pawn and knight attacks */ if (side==WHITE) { if (ky>1 && (PawnAttacksWhite[kpos] & B->BlackPawns)) return pawn; if (B->BlackKnights & KnightMoves[kpos]) return knight; } if (side==BLACK) { if (ky<6 && (PawnAttacksBlack[kpos] & B->WhitePawns)) return pawn; if (B->WhiteKnights & KnightMoves[kpos]) return knight; } /* (3) *sigh* We'll have to check for sliding pieces then. This isn't actually * all that painful. First of all set up bitboards holding the relevant enemy * piece locations. r=Rooks, b=Bishops, q=Queens */ if (side==WHITE) { r = B->BlackRooks; q = B->BlackQueens; b = B->BlackBishops; } else { r = B->WhiteRooks; q = B->WhiteQueens; b = B->WhiteBishops; } /* Combined bitboard representing the locations of enemy rooks & queens */ rq = r|q; /* (3a) Horizontal/Vertical sliders : Rooks and queens first */ /* Solve this by inverting the problem - i.e. imagine the target king as * a rook/bishop/queen. See where it can move, and then & these squares * with the board positions of the required piece. If this is !=0 then * king is in check */ /* Check for rooks/queens on this rank. */ if (RankMask[ky] & rq) { mask = (B->All >> (ky*8)) & FullRank; tsq = MovesRank[kpos][mask]; if (tsq & r) return rook; if (tsq & q) return queen; }
// Prepare a deck by creating 52 cards // 13 ranks per suit & 4 suit void Deck::prepareDeck() { int cardCounter = 0; for (int i = 0; i < 4; i++) { for (int j = 0; j < RANK_COUNT; j++) { Card* card = new Card(Suit(i), Rank(j)); cards_[cardCounter] = card; cardCounter++; } } }
_TCHAR *LogBookData::NameWRank(void) { if(gStringMgr) { _TCHAR *rank = gStringMgr->GetString(gRanksTxt[Rank()]); _stprintf(nameWrank,"%s %s",rank,Pilot.Name); return nameWrank; } return Name(); }
/* uses rank() and c() to obtain the LastFirstFunc function */ int DynSuffixArray::LastFirstFunc(unsigned L_idx) { int fIdx(-1); //cerr << "in LastFirstFcn() with L_idx = " << L_idx << endl; unsigned word = m_L->at(L_idx); if((fIdx = F_firstIdx(word)) != -1) { //cerr << "fidx + Rank(" << word << "," << L_idx << ") = " << fIdx << "+" << Rank(word, L_idx) << endl; fIdx += Rank(word, L_idx); } return fIdx; }
CNodeShareInfo::CNodeShareInfo(std::vector<int>* procs, std::vector<int>* indices, int index) { inheritedindex=index; localprocrank=Rank();//from mpitools.h // int minrank=localprocrank; for(std::vector<int>::size_type i=0;i<procs->size();i++) { int pi=(*procs)[i]; remoteproclist.push_back(pi); // if(localprocrank>pi) // minrank=pi; remoteindexlist.push_back((*indices)[i]); } //bubble sort remoteproclist (make corresponding change to remoteindexlist) int tmp,rsize=remoteproclist.size(); for(std::vector<int>::size_type i=0;i<rsize;i++) { for(std::vector<int>::size_type j=i+1;j<rsize;j++) { if(remoteproclist[i]>remoteproclist[j]) { tmp=remoteproclist[i]; remoteproclist[i]=remoteproclist[j]; remoteproclist[j]=tmp; tmp=remoteindexlist[i]; remoteindexlist[i]=remoteindexlist[j]; remoteindexlist[j]=tmp; } } } // Find next higher rank nextrank=-1; nextindex=-1; for(std::vector<int>::size_type i=0;i<remoteproclist.size();i++) { if(localprocrank<remoteproclist[i]) { nextrank=remoteproclist[i]; nextindex=remoteindexlist[i]; break; } } if(localprocrank<=remoteproclist[0]) { _owns0=true; } else { _owns0=false; } owns=_owns0; };
bool System::testObser(void){ bool ret_val = true; if ( Rank(obser) != getVE() ){ ret_val = false; } ///~ si es falso informo antes! if ( notify != 0 && ret_val == false ) { notify->reportStatus(__func__,"Sistema NO observable"); } return ret_val; }
//Initialize by filling the card vector with all the cards in a deck Model::Model() { for (Suit i = CLUB; i != SUIT_COUNT; i = Suit(i+1)) { for (Rank k = ACE; k != RANK_COUNT; k = Rank(k+1)) { cards_.push_back(new Card(i, k)); } } }
void main(void) { int a[6] = {2, 6, 4, 3, 1, 5}; int r[6]; int n = 6; Rank(a,n,r); Rearrange(a,n,r); for (int i = 0; i < n; i++) cout << a[i] << ' '; cout << endl; }
void Player::CalculateScore() { for (unsigned int i = 0; i < MeldedCards.size(); i++) { string cardRank = MeldedCards[i].substr(0,MeldedCards[i].find('-')); int value = atoi(cardRank.c_str()); if (value < Rank(8) + RANK_OFFSET) Score += TWO_THROUGH_NINE_PTS; else if (value >= Rank(8) + RANK_OFFSET && value <= Rank(11) + RANK_OFFSET) Score += TEN_THROUGH_KING_PTS; else Score += ACE_POINTS; } for (unsigned int i = 0; i < Hand.size(); i++) { string cardRank = Hand[i].substr(0,Hand[i].find('-')); int value = atoi(cardRank.c_str()); if (value < Rank(8) + RANK_OFFSET) Score -= TWO_THROUGH_NINE_PTS; else if (value >= Rank(8) + RANK_OFFSET && value <= Rank(11) + RANK_OFFSET) Score -= TEN_THROUGH_KING_PTS; else Score -= ACE_POINTS; } }
void Write_Node(TreeNode Node) { int i; for (i=1; i <= Rank(Node); i++) Write_Node(Child(Node, i)); Write_String(Tree_File, NodeName(Node)); fprintf(Tree_File,"\n"); Write_String(Tree_File, SourceLocation(Node)); fprintf(Tree_File,"\n"); fprintf(Tree_File,"%1d\n", Element(Tree,Node+2)); }
virtual std::ostream& Print (std::ostream& os) const { Operator<T>::Print(os); os << " image size: rank(" << Rank() << ") side(" << ImageSize() << ") nodes(" << KSpaceSize() << ")" << std::endl; os << " nfft: maxit(" << Maxit() << ") eps(" << Epsilon() << ") alpha(" << Alpha() << ") m("<< m_m <<") sigma(" << Sigma() << ")" << std::endl; os << " have_kspace(" << m_have_kspace << ") have_weights(" << m_have_weights << ") have_b0(" << m_have_b0 << ")" << std::endl; os << " ft-threads(" << m_np << ")"; if (m_3rd_dim_cart) os << " 3rd dimension (" << m_ncart << ") is Cartesian."; return os; }
void solve() { int i, j, k; for(i = 0; i < Q; i ++) { if(b[i][0] == 'T') Top(ob[i]); else if(b[i][0] == 'Q') Query(ob[i]); else Rank(ob[i]); } }
void nist_test_suite() { if ( (testVector[0] == 1) || (testVector[TEST_FREQUENCY] == 1) ) Frequency(tp.n); if ( (testVector[0] == 1) || (testVector[TEST_BLOCK_FREQUENCY] == 1) ) BlockFrequency(tp.blockFrequencyBlockLength, tp.n); if ( (testVector[0] == 1) || (testVector[TEST_CUSUM] == 1) ) CumulativeSums(tp.n); if ( (testVector[0] == 1) || (testVector[TEST_RUNS] == 1) ) Runs(tp.n); if ( (testVector[0] == 1) || (testVector[TEST_LONGEST_RUN] == 1) ) LongestRunOfOnes(tp.n); if ( (testVector[0] == 1) || (testVector[TEST_RANK] == 1) ) Rank(tp.n); if ( (testVector[0] == 1) || (testVector[TEST_FFT] == 1) ) DiscreteFourierTransform(tp.n); if ( (testVector[0] == 1) || (testVector[TEST_NONPERIODIC] == 1) ) NonOverlappingTemplateMatchings(tp.nonOverlappingTemplateBlockLength, tp.n); if ( (testVector[0] == 1) || (testVector[TEST_OVERLAPPING] == 1) ) OverlappingTemplateMatchings(tp.overlappingTemplateBlockLength, tp.n); if ( (testVector[0] == 1) || (testVector[TEST_UNIVERSAL] == 1) ) Universal(tp.n); if ( (testVector[0] == 1) || (testVector[TEST_APEN] == 1) ) ApproximateEntropy(tp.approximateEntropyBlockLength, tp.n); if ( (testVector[0] == 1) || (testVector[TEST_RND_EXCURSION] == 1) ) RandomExcursions(tp.n); if ( (testVector[0] == 1) || (testVector[TEST_RND_EXCURSION_VAR] == 1) ) RandomExcursionsVariant(tp.n); if ( (testVector[0] == 1) || (testVector[TEST_SERIAL] == 1) ) Serial(tp.serialBlockLength,tp.n); if ( (testVector[0] == 1) || (testVector[TEST_LINEARCOMPLEXITY] == 1) ) LinearComplexity(tp.linearComplexitySequenceLength, tp.n); if ( (testVector[0] == 1) || (testVector[TEST_FFT80] == 1) ) DiscreteFourierTransform80(tp.n); }