void Kings::deal() { CardList cards = deck->cards(); CardList::Iterator it = cards.begin(); int cn = 0; for (int stack = -1; stack < 8; ) { while (it != cards.end() && (*it)->rank() != Card::King) { if (stack >= 0) { store[stack]->add(*it, false, true); cn++; } ++it; } if (it == cards.end()) break; cn++; store[++stack]->add(*it, false, true); if (stack == 0) { cards = deck->cards(); // reset to start it = cards.begin(); } else ++it; } assert(cn == 104); }
void main() { BeastCubeManager beastCube; for(CubeID cube : CubeSet::connected()) { //LOG("###---Player %i---\n", cube); CardList c = (CardFactory::getCards(2)); for(int i = 0; i < c.count(); i++) { LOG("###%i %i\n", c[i].type, c[i].power); } Card beastCards[] = {c.pop_back(), c.pop_back()}; Beast m = BeastFactory::createBeast(beastCards, 2); LOG("###Player %i beast\nType: %i\nAttack:%i\nHealth:%i\nResolve:%i\nAnger:%i\n\n", -1, m.type, m.attack, m.health, m.resolve, m.anger); beastCube.init(cube, m); } while(1) System::paint(); }
void Card::removeChildrenWithTag(Tag *tag) { CardList *children = childrenWithTag(tag); for (CardList::iterator cardIter = children->begin(); cardIter != children->end(); cardIter++) { Card *child = *cardIter; if (child->parent != NULL) { child->parent->remove(child); } } delete children; }
// Discards the given card void Role::discardCard(const Card& card) { const CardList legalCards = legalMoves(); // Gets the cards which are legal to play // Determines whether the user is in a situation that they had to discard, if not throws exception if(legalCards.size() != 0) { throw IllegalDiscardException(); } // Removes card from hand, and adds to discard pile const Card* deletedCard = player_->hand_.remove(card); player_->discards_.add(deletedCard); triggerPlayerUpdate(true); }
void TalismanCard::OnCleanUpPhase( Engine* pEngine ) { Player* pPlayer = pEngine->GetCurrentPlayer(); CardList buyList = pPlayer->GetBuyList(); for( CardListIter iter = buyList.begin(); iter != buyList.end(); iter++ ) { if( !(*iter)->IsVictoryCard() ) { pPlayer->GainCardOnDiscard( (*iter) ); } } }
// Plays the given card in the game void Role::playCard(const Card& card) { const CardList legalCards = legalMoves(); // gets the card which are legal to play // Determines whether the card being played is legal to play, otherwise exception is thrown int cardIndex = legalCards.find(card); if(cardIndex == -1) { throw IllegalPlayException(); } //Removes the card from the hand, and returns it so it can be added to the table const Card* played = player_->hand_.remove(card); player_->getGame()->addToTable(played); triggerPlayerUpdate(true); }
// returns a vector of 13 cards for a player to use CardList Deck::dealPlayerHand() { CardList hand; // grab next 13 cards and copy them to hand vector for (int i = 0; i < HAND_SIZE; i++) { int index = CARD_COUNT - cards_left_ + i; if (index >= 0) { hand.add(cards_[index]); } } // mark those 13 cards as used cards_left_ -= HAND_SIZE; return hand; }
CardList Cards::ToCardList(SortType sorttype)const { CardList cardlist; for(QSet<Card>::ConstIterator it=m_cards.begin();it!=m_cards.end();it++) { cardlist<<*it; } if(sorttype==Asc) { qSort(cardlist.begin(),cardlist.end(),qLess<Card>()); } if(sorttype==Desc) { qSort(cardlist.begin(),cardlist.end(),qGreater<Card>()); } return cardlist; }
// Add cards from pile to deck, in reverse direction void Klondike::redeal() { CardList pilecards = pile->cards(); if (EasyRules) // the remaining cards in deck should be on top // of the new deck pilecards += deck->cards(); for (int count = pilecards.count() - 1; count >= 0; --count) { Card *card = pilecards[count]; card->setAnimated(false); deck->add(card, true, false); // facedown, nospread } redealt = true; }
bool Fortyeight::checkAdd(int, const Pile *c1, const CardList &c2) const { if (c1->isEmpty()) return true; // ok if in sequence, same suit return (c1->top()->suit() == c2.first()->suit()) && (c1->top()->rank() == (c2.first()->rank()+1)); }
void CellarCard::OnActionPhase( Engine* pEngine ) { Player* pPlayer = pEngine->GetCurrentPlayer(); IAI* pAI = pPlayer->GetAI(); CardList cardsToDiscard; cardsToDiscard = pAI->OnCellar(); if( pPlayer->AreCardsInHand( cardsToDiscard ) ) { pPlayer->DiscardFromHand( cardsToDiscard ); pPlayer->DrawCardsToHand( cardsToDiscard.size() ); } else { // TODO: Add error throw std::wstring( L"Error: CellarCard::OnActionPhase()" ); } }
int CardList::operator==(CardList& list){ if(this->length() != list.length()){ return 0; } for(int i=0;i<this->length();i++){ if((*this)[i] != list[i]){ return 0; } } return 1; }
void GameLogDialog::showDeal(const int row) { Q_ASSERT(row < model->gameLog().size()); QString output; for (int i=1; i<=3; i++) { output += QString("%1: ").arg(model->player(i)->nick()); CardList cl; foreach(const Card& c, model->gameLog().at(row).cardList[i-1]) cl.insert(const_cast<Card*>(&c)); cl.mySort(); for( int ci = 0; ci < cl.count(); ci++ ) { output += cl.at(ci)->toUniString(); output += ' '; } output += '\n'; } QMessageBox::about(0, tr("Deal #") + QString::number(row + 1), output); }
bool Clock::checkAdd( int ci, const Pile *c1, const CardList& c2) const { Card *newone = c2.first(); if (ci == 0) { if (c1->isEmpty()) return true; return (newone->rank() == c1->top()->rank() - 1); } else { if (c1->top()->suit() != newone->suit()) return false; if (c1->top()->rank() == Card::King) return (newone->rank() == Card::Ace); return (newone->rank() == c1->top()->rank() + 1); } }
//Given the cards already played by all players and a player's hand, determines the legal cards which can be played by the player CardList GameLogic::legalMoves(const CardList& table, const CardList& hand) { CardList legalMoves; // used to store legal cards // In the case the table is empty, this means this play has 7 of spades, so he has to be forced to play it if(table.size() == 0) { // finds the 7S card, so we only got one instance of it int index = hand.find(Card(SPADE, SEVEN)); const Card* sevenSpades = hand[index]; legalMoves.add(sevenSpades); return legalMoves; } // loops through hand to determine which ones are legal to play for (int index = 0; index < hand.size(); index++) { const Card * card = hand[index]; // Stores the index of lower rank and higher rank card to determine whether it exists or not int lowerRankIndex = -1; int higherRankIndex = -1; // Determines whether a lower rank or higher rank card exists if (card->getRank() != ACE) { Card lowerRank = Card(card->getSuit(), (Rank) (card->getRank() - 1)); lowerRankIndex = table.find(lowerRank); } if (card->getRank() != KING) { Card higherRank = Card(card->getSuit(), (Rank)(card->getRank() + 1)); higherRankIndex = table.find(higherRank); } // Determines whether the current card is legal to play if (card->getRank() == SEVEN || lowerRankIndex !=-1 || higherRankIndex != -1) { legalMoves.add(card); } } return legalMoves; }
CardList *Card::childrenWithTag(Tag *tag) { CardList *matches = new CardList(); for(CardList::iterator iter = attached.begin(); iter != attached.end(); iter++) { Card *child = *iter; if (child->match(tag) != NULL) { if (rand()%2 == 0) matches->push_back(child); else matches->push_front(child); } if (child != this) { CardList *childMatches = child->childrenWithTag(tag); for(CardList::iterator childIter = childMatches->begin(); childIter != childMatches->end(); childIter++) { matches->push_back(*childIter); } delete childMatches; } } return matches; }
bool Klondike::isGameLost() const { kdDebug( 11111 ) << "Is the game lost?" << endl; if (!deck->isEmpty()) { kdDebug( 11111 ) << "We should only check this when the deck is exhausted." << endl; return false; } // Check whether top of the pile can be added to any of the target piles. if ( !pile->isEmpty() ) { for ( int i = 0; i < 4; ++i ) { if ( target[ i ]->isEmpty() ) { continue; } if ( pile->top()->suit() == target[ i ]->top()->suit() && pile->top()->rank() - 1 == target[ i ]->top()->rank() ) { kdDebug( 11111 ) << "No, the source pile's top card could be added to target pile " << i << endl; return false; } } } // Create a card list - srcPileCards - that contains all accessible // cards in the pile and the deck. CardList srcPileCards; if ( EasyRules ) { srcPileCards = pile->cards(); } else { /* In the draw3 mode, not every card in the source pile is * accessible, but only every third one. */ for ( unsigned int i = 2; i < pile->cards().count(); i += 3 ) { kdDebug( 11111 ) << "Found card "<< pile->cards()[i]->name()<< endl; srcPileCards += pile->cards()[ i ]; } if ( !pile->cards().isEmpty() && pile->cards().count() % 3 != 0 ) { kdDebug( 11111 ) << "Found last card "<< pile->cards()[pile->cards().count() - 1]->name()<< endl; srcPileCards += pile->cards()[ pile->cards().count() - 1 ]; } } // Check all seven stores for ( int i = 0; i < 7; ++i ) { // If this store is empty... if ( play[ i ]->isEmpty() ) { // ...check whether the pile contains a king we could move here. CardList::ConstIterator it = srcPileCards.begin(); CardList::ConstIterator end = srcPileCards.end(); for ( ; it != end; ++it ) { if ( ( *it )->rank() == Card::King ) { kdDebug( 11111 ) << "No, the pile contains a king which we could move onto store " << i << endl; return false; } } // ...check whether any of the other stores contains a (visible) // king we could move here. for ( int j = 0; j < 7; ++j ) { if ( j == i || play[ j ]->isEmpty() ) { continue; } const CardList cards = play[ j ]->cards(); CardList::ConstIterator it = ++cards.begin(); CardList::ConstIterator end = cards.end(); for ( ; it != end; ++it ) { if ( ( *it )->realFace() && ( *it )->rank() == Card::King ) { kdDebug( 11111 ) << "No, store " << j << " contains a visible king which we could move onto store " << i << endl; return false; } } } } else { // This store is not empty... Card *topCard = play[ i ]->top(); // ...check whether the top card is an Ace (we can start a target) if ( topCard->rank() == Card::Ace ) { kdDebug( 11111 ) << "No, store " << i << " has an Ace, we could start a target pile." << endl; return false; } // ...check whether the top card can be added to any target pile for ( int targetIdx = 0; targetIdx < 4; ++targetIdx ) { if ( target[ targetIdx ]->isEmpty() ) { continue; } if ( target[ targetIdx ]->top()->suit() == topCard->suit() && target[ targetIdx ]->top()->rank() == topCard->rank() - 1 ) { kdDebug( 11111 ) << "No, store " << i << "'s top card could be added to target pile " << targetIdx << endl; return false; } } // ...check whether the source pile contains a card which can be // put onto this store. CardList::ConstIterator it = srcPileCards.begin(); CardList::ConstIterator end = srcPileCards.end(); for ( ; it != end; ++it ) { if ( ( *it )->isRed() != topCard->isRed() && ( *it )->rank() == topCard->rank() - 1 ) { kdDebug( 11111 ) << "No, the pile contains a card which we could add to store " << i << endl; return false; } } // ...check whether any of the other stores contains a visible card // which can be put onto this store, and which is on top of an // uncovered card. for ( int j = 0; j < 7; ++j ) { if ( j == i ) { continue; } const CardList cards = play[ j ]->cards(); CardList::ConstIterator it = cards.begin(); CardList::ConstIterator end = cards.end(); for ( ; it != end; ++it ) { if ( ( *it )->realFace() && ( *it )->isRed() != topCard->isRed() && ( *it )->rank() == topCard->rank() - 1 ) { kdDebug( 11111 ) << "No, store " << j << " contains a card which we could add to store " << i << endl; return false; } } } } } kdDebug( 11111 ) << "Yep, all hope is lost." << endl; return true; }
TEST_F( libRocketDataGridTest, UIDataViewList ) { Point2i pos1(60,25); std::string doc_file1 = "dataview.rml"; UIDataViewList store1; EXPECT_EQ( true, store1.set_context(&this->desktop) ); EXPECT_EQ( true, store1.load_document_file( doc_file1 ) ) << this->test_set() << " object should not be invalid; is the context and document file valid?"; // Ensure that the visual debugger's beacon (err icon) appears on-screen. Rocket::Core::Log::Message( Rocket::Core::Log::LT_ASSERT, "Hello, world!" ); this->model.reset( new CardsPageDataSource("cards_db") ); this->db.reset( new CardCollection() ); EXPECT_TRUE( model != nullptr ); EXPECT_TRUE( db != nullptr ); EXPECT_EQ( true, db->load_db() ) << "Could not initialize nom::CardsPageDataSource data interface."; CardList deck; CardList cards = db->cards(); // Load in the entire cards database for( auto itr = cards.begin(); itr != cards.end(); ++itr ) { deck.push_back( *itr ); } // Deck of cards for the data source model->append_cards( deck ); store1.show(); EXPECT_TRUE( store1.set_column_title(1, "CARDS P. " + std::to_string(model->page() + 1) ) ); EXPECT_EQ( true, store1.visible() ); EXPECT_EQ( pos1, store1.position() ); // Default values sanity EXPECT_EQ( "cards", model->table_name() ); EXPECT_EQ( 11, model->per_page() ); EXPECT_EQ( 0, model->page() ); EXPECT_EQ( 10, model->map_page_row( 10, 0 ) ) << "Selection should be between 0..11"; EXPECT_EQ( 2, model->map_page_row( 13, 1 ) ) << "Selection should be between 0..11"; EXPECT_EQ( 10, model->map_page_row( 21, 1 ) ) << "Selection should be between 0..11"; EXPECT_EQ( "CARDS P. 1", store1.column_title(1) ); EXPECT_EQ( "NUM.", store1.column_title(2) ); store1.register_event_listener( store1.document(), "keydown", new nom::UIEventListener( [&] ( Rocket::Core::Event& ev ) { on_keydown( ev, &store1, db, model, this->phand ); } )); store1.register_event_listener( store1.document(), "mouseup", new nom::UIEventListener( [&] ( Rocket::Core::Event& ev ) { on_mouseup( ev, &store1, db, model, this->phand ); } )); // Synthesized user input events; we hope to capture these before the end of // the first frame Rocket::Core::Element* target = nullptr; Rocket::Core::Dictionary lclick; Rocket::Core::Dictionary rclick; lclick.Set("button","0"); // Left click rclick.Set("button","1"); // Left click // We must update the context before our cards model is filled this->desktop.update(); target = store1.document()->GetElementById("Geezard"); if( target ) { target->DispatchEvent("mouseup", lclick); // Should have zero cards remaining } target = store1.document()->GetElementById("Red Bat"); if( target ) { target->DispatchEvent("mouseup", lclick); target->DispatchEvent("mouseup", lclick); target->DispatchEvent("mouseup", lclick); // Should have one cards remaining } target = store1.document()->GetElementById("Red Bat"); if( target ) { target->DispatchEvent("mouseup", rclick); // Should have two cards remaining } target = store1.document()->GetElementById("Cockatrice"); if( target ) { target->DispatchEvent("mouseup", lclick); target->DispatchEvent("mouseup", lclick); target->DispatchEvent("mouseup", lclick); // Should have zero cards remaining } // NOM_LOG_INFO( NOM_LOG_CATEGORY_TEST, store1.dump() ); EXPECT_EQ( NOM_EXIT_SUCCESS, this->on_run() ); EXPECT_TRUE( this->compare() ); }
void Klondike::getHints() { target_tops[0] = target_tops[1] = target_tops[2] = target_tops[3] = Card::None; for( int i = 0; i < 4; i++ ) { Card *c = target[i]->top(); if (!c) continue; target_tops[c->suit() - 1] = c->rank(); } Card* t[7]; for(int i=0; i<7;i++) t[i] = play[i]->top(); for(int i=0; i<7; i++) { CardList list = play[i]->cards(); for (CardList::ConstIterator it = list.begin(); it != list.end(); ++it) { if (!(*it)->isFaceUp()) continue; CardList empty; empty.append(*it); for (int j = 0; j < 7; j++) { if (i == j) continue; if (play[j]->legalAdd(empty)) { if (((*it)->rank() != Card::King) || it != list.begin()) { newHint(new MoveHint(*it, play[j])); break; } } } break; // the first face up } tryToDrop(play[i]->top()); } if (!pile->isEmpty()) { Card *t = pile->top(); if (!tryToDrop(t)) { for (int j = 0; j < 7; j++) { CardList empty; empty.append(t); if (play[j]->legalAdd(empty)) { newHint(new MoveHint(t, play[j])); break; } } } } }
void main() { Game game = Game(); CardList cards; //Player playerOne; BeastCubeManager beastCube(&game); Hand gameHand(0); //Hand::playerOneCards = (CardFactory::getCards(5)); //Hand::playerTwoCards = (CardFactory::getCards(4)); //Hand::convertToMenu(1, Hand::playerOneCards); Hand::drawHand(); Menu m(Hand::handBuffer, &gAssets, Hand::playerOneHand); m.anchor(0); //Make beasts for(int cube = 1; cube < CubeSet::connected().count(); ++cube) { LOG("###---Player %i---\n", cube); //CardList c = (CardFactory::getCards(2)); CardFactory::getCards(&cards, 2); for(int i = 0; i < cards.count(); i++) { LOG("###Card for beast creation: %i %i\n", cards[i].type, cards[i].power); } Card beastCards[] = {cards.pop_back(), cards.pop_back()}; Beast m = BeastFactory::createBeast(beastCards, 2); LOG("###Beast created:\n Type: %i\n Attack:%i\n Health:%i\n Resolve:%i\n Anger:%i\n\n", m.type, m.attack, m.health, m.resolve, m.anger); beastCube.init(cube, m); cards.clear(); } struct MenuEvent e; uint8_t item; int target = 0; while(1) { System::paint(); while (m.pollEvent(&e)) { if(game.newTurn) { //LOG("New turn!\n"); //Hand::drawCard(game.activePlayerIndex + 1); //if(game.activePlayerIndex == 0) // m.init(Hand::handBuffer, &gAssets, Hand::playerOneHand); //else // m.init(Hand::handBuffer, &gAssets, Hand::playerTwoHand); Hand::drawHand(); game.newTurn = false; } switch (e.type) { case MENU_ITEM_PRESS: // // Game Buddy is not clickable, so don't do anything on press // if (e.item >= 3) { // // Prevent the default action // continue; // } else { // m.anchor(e.item); // } // if (e.item == 4) { // static unsigned randomIcon = 0; // randomIcon = (randomIcon + 1) % e.item; // m.replaceIcon(e.item, Hand::playerOneHand[randomIcon].icon, Hand::playerOneHand[randomIcon].label); // } if(target != 0) { Card c; c = Hand::playerOneCards[e.item]; game.cardAction(&beastCube.beasts[target], &c); beastCube.refresh(target); game.newTurn = true; } break; case MENU_EXIT: // this is not possible when pollEvent is used as the condition to the while loop. // NOTE: this event should never have its default handler skipped. ASSERT(false); break; case MENU_NEIGHBOR_ADD: //LOG("found cube %d on side %d of menu (neighbor's %d side)\n", //e.neighbor.neighbor, e.neighbor.masterSide, e.neighbor.neighborSide); target = e.neighbor.neighbor; break; case MENU_NEIGHBOR_REMOVE: //LOG("lost cube %d on side %d of menu (neighbor's %d side)\n", // e.neighbor.neighbor, e.neighbor.masterSide, e.neighbor.neighborSide); if(e.neighbor.neighbor == target) { target = 0; } break; case MENU_ITEM_ARRIVE: LOG("arriving at menu item %d\n", e.item); Hand::currentCardIndex = item = e.item; break; case MENU_ITEM_DEPART: //LOG("departing from menu item %d, scrolling %s\n", item, e.direction > 0 ? "forward" : "backward"); break; case MENU_PREPAINT: // do your implementation-specific drawing here // NOTE: this event should never have its default handler skipped. break; case MENU_UNEVENTFUL: // this should never happen. if it does, it can/should be ignored. ASSERT(false); break; } m.performDefault(); } // Handle the exit event (so we can re-enter the same Menu) ASSERT(e.type == MENU_EXIT); m.performDefault(); //LOG("Selected Game: %d\n", e.item); } }
/// \todo Split up into smaller testing units TEST_F( libRocketDataGridTest, DataSourceModel ) { // Disable assertion handling prompts for these tests (just report instead) // nom::set_assertion_handler(log_assert_handler, nullptr); // Disable assertion handling prompts for these tests and ignore the report // nom::set_assertion_handler(null_assert_handler, nullptr); // Buffer objects used for verifying storage model results nom::StringList row; nom::StringList cols; cols.push_back( "name" ); cols.push_back( "num" ); this->model.reset( new CardsPageDataSource("cards_db") ); // Baseline sanity tests EXPECT_TRUE( this->model != nullptr ); EXPECT_EQ( "cards", this->model->table_name() ) << "Table name string should be the default initialized value."; EXPECT_EQ( true, this->model->empty() ) << "Resulting storage size should be empty (zero)."; // NOM_LOG_INFO( NOM_LOG_CATEGORY_TEST, this->model->dump() ); // Creation tests CardList cards; cards.push_back( Card( 0, "Geezard", 999 ) ); EXPECT_EQ( 1, this->model->append_cards( cards ) ) << "Resulting storage size should be one item."; EXPECT_EQ( 2, this->model->append_card( Card( 89, "testme", 22 ) ) ) << "Resulting storage size should be two items."; // Overwrite 'testme' card EXPECT_EQ( 2, this->model->insert_card( 1, Card( 1, "Fungar", 777 ) ) ) << "Resulting storage size should remain two."; EXPECT_EQ( false, this->model->empty() ) << "Storage should not be empty."; // NOM_LOG_INFO( NOM_LOG_CATEGORY_TEST, this->model->dump() ); // Destruction tests // Destroy 'Fungar' card EXPECT_EQ( 1, this->model->erase_card( 1 ) ) << "Resulting storage size should be one."; // ...and verify the results row.clear(); this->model->row(row, 0, cols ); EXPECT_EQ( "Geezard", row.at(0) ); EXPECT_EQ( "999", row.at(1) ); cards.clear(); cards.push_back( Card( 2, "Bite Bug", 2 ) ); cards.push_back( Card( 3, "Red Bat", 5 ) ); cards.push_back( Card( 89, "Diablos", 666 ) ); // Overwrite all but the first card in the model, shifting said first card to // the end of the container. EXPECT_EQ( 4, this->model->insert_cards( 0, cards ) ) << "Resulting storage size should be four items."; // Ensure that the first card is at the end of the container row.clear(); this->model->row( row, this->model->num_rows() - 1, cols ); EXPECT_EQ( "Geezard", row.at(0) ); EXPECT_EQ( "999", row.at(1) ); // NOM_LOG_INFO( NOM_LOG_CATEGORY_TEST, this->model->dump() ); // Destroy all but 'Geezard' card EXPECT_EQ( 1, this->model->erase_cards( 0, 3 ) ) << "The Geezard card should be the only item remaining."; // ...and verify the results row.clear(); this->model->row(row, 0, cols ); EXPECT_EQ( "Geezard", row.at(0) ); EXPECT_EQ( "999", row.at(1) ); this->model->erase_cards(); EXPECT_EQ( true, this->model->empty() ) << "Resulting storage size should be emptied (zero)."; row.clear(); this->model->erase_cards(); NOM_LOG_INFO( NOM_LOG_CATEGORY_TEST, this->model->dump() ); }
void CardList::concat(CardList& list) { for(int i=0;i<list.length();i++){ this->add(list[i]); } }
/* * aLeftPlayer: next in turn * aRightPlayer: prev in turn * 0, 1th * 1th, 2nd */ Card *AlphaBetaPlayer::makeMove (Card *lMove, Card *rMove, Player *aLeftPlayer, Player *aRightPlayer, bool isPassOut) { qDebug() << type() << "("<< mPlayerNo << ") moves"; card_t hands[3][10]; card_t desk[3]; int crdLeft = 0; int trumpSuit = 0; Player *plst[3]; //again: plst[0] = plst[1] = plst[2] = 0; plst[mPlayerNo-1] = this; plst[aLeftPlayer->number()-1] = aLeftPlayer; plst[aRightPlayer->number()-1] = aRightPlayer; // build hands for (int c = 0; c < 3; c++) { Q_ASSERT(plst[c]); CardList *clst = &(plst[c]->mCards); //for (int f = 0; f < 10; f++) hds[c][f] = hands[c][f] = 0; int pos = 0; for (int f = 0; f < clst->size(); f++) { Card *ct = clst->at(f); if (!ct) continue; hands[c][pos++] = CARD(ct->face(), ct->suit()-1); if (pos > crdLeft) crdLeft = pos; } for (int f = pos; f < 10; f++) hands[c][f] = 0; xsortCards(hands[c], pos); } if (!lMove && !rMove && crdLeft == 10) { return AiPlayer::makeMove(lMove, rMove, aLeftPlayer, aRightPlayer, isPassOut); } // find game const eGameBid bid = m_model->currentGame(); gPassOutOrMisere = (bid == g86 || bid == g86catch || bid == raspass); trumpSuit = bid%10-1;//(bid-(bid/10)*10)-1; /* if (bid == g86catch || bid == g86 || bid == raspass) { return Player::moveSelectCard(lMove, rMove, aLeftPlayer, aRightPlayer); } */ if (bid == g86catch || bid == g86 || bid == raspass) { trumpSuit = 4; } if (trumpSuit < 0) trumpSuit = 4; fprintf(stderr, "po:%s; lm:%s, rm:%s\n", isPassOut?"y":"n", lMove?"y":"n", rMove?"y":"n"); if (isPassOut && rMove && !lMove) { // это распасы, первый или второй круг, первый ход gPassOutSuit = rMove->suit()-1; fprintf(stderr, "pass-out: %i\n", gPassOutSuit); rMove = 0; } else gPassOutSuit = -1; // build desk int turn = 0; if (lMove) { desk[turn++] = CARD(lMove->face(), lMove->suit()-1); if (rMove) desk[turn++] = CARD(rMove->face(), rMove->suit()-1); } else if (rMove) { desk[turn++] = CARD(rMove->face(), rMove->suit()-1); } // build hands for (int f = 0; f < 3; f++) { xHands[f].suitCount[0] = xHands[f].suitCount[1] = xHands[f].suitCount[2] = xHands[f].suitCount[3] = 0; xHands[f].suitStart[0] = xHands[f].suitStart[1] = xHands[f].suitStart[2] = xHands[f].suitStart[3] = 11; xHands[f].tricks = plst[f]->tricksTaken(); int st; for (int z = 0; z < 10; z++) { if (hands[f][z]) { xHands[f].faces[z] = FACE(hands[f][z]); st = xHands[f].suits[z] = SUIT(hands[f][z]); if (xHands[f].suitCount[st]++ == 0) xHands[f].suitStart[st] = z; } else xHands[f].faces[z] = 0; } } // build desk for (int f = 0; f < turn; f++) { xDeskFaces[f] = FACE(desk[f]); xDeskSuits[f] = SUIT(desk[f]); } int a, b, c, move; int me = this->number()-1; xCardsLeft = crdLeft; gTrumpSuit = trumpSuit; gIterations = 0; printf("%shand 0:", this->number()==0?"*":" "); printHand(&(xHands[0])); printf("%shand 1:", this->number()==1?"*":" "); printHand(&(xHands[1])); printf("%shand 2:", this->number()==2?"*":" "); printHand(&(xHands[2])); printDesk(turn); // оптимизации /* if (turn > 0) { // можем вообще взять? if (hands[me].suitCount( } */ stTime = QTime::currentTime(); stTime.start(); abcPrune(turn, me, -666, 666, 666, &a, &b, &c, &move); qDebug() << "face:" << FACE(hands[me][move]) << "suit:" << SUIT(hands[me][move])+1 << "move:" << move << "turn:" << turn << "moves:" << crdLeft << "trump:" << trumpSuit << "iters:" << gIterations << ""; /* for (int h = 0; h < 3; h++) { fprintf(stderr, (h == me)?"*":" "); fprintf(stderr, "hand %i:", h); for (int f = 0; f < 10; f++) { if (hands[h][f]) { fprintf(stderr, " %2i.%i(%3i)", FACE(hands[h][f]), SUIT(hands[h][f]), hands[h][f]); } else { fprintf(stderr, " %2i.%i(%3i)", 0, 0, hands[h][f]); } } fprintf(stderr, "\n"); } fprintf(stderr, "desk:"); for (int f = 0; f < turn; f++) { fprintf(stderr, " %2i.%i(%3i)", FACE(desk[f]), SUIT(desk[f]), desk[f]); } fprintf(stderr, "\n"); */ Q_ASSERT(move >= 0); Card *moveCard = getCard(FACE(hands[me][move]), SUIT(hands[me][move])+1); qDebug() << "move:" << moveCard->toString(); mCards.remove(moveCard); mCardsOut.insert(moveCard); return moveCard; }
void GolemCard::OnActionPhase( Engine* pEngine ) { // TODO: Not sure how to implement the Golem playing two cards since it is // not the player playing the cards since the cards in Hand are not // avaliable throw std::wstring( L"GolemCard::OnActionPhase - To be implemented..." ); Player* pPlayer = pEngine->GetCurrentPlayer(); IAI* pAI = pPlayer->GetAI(); CardList revealedCardList; CardList actionCardList; do { Card* pRevealedCard = pPlayer->RevealCardFromDeck(); if( pRevealedCard->IsNullCard() ) { break; } else if( pRevealedCard->IsActionCard() && pRevealedCard->CardId() != CARDID::GOLEM ) { actionCardList.push_back( pRevealedCard ); } else { revealedCardList.push_back( pRevealedCard ); } } while( actionCardList.size() < 2 ); pPlayer->PutCardsInDiscard( revealedCardList ); CardList reorderedCardList = pAI->OnGolem( revealedCardList ); if( Card::CardListsMatch( revealedCardList, reorderedCardList ) ) { CardListIter cardIter; pPlayer->SetGolemFlag( true ); for( cardIter = reorderedCardList.begin(); cardIter != reorderedCardList.end(); cardIter++ ) { Card* pCardToPlay = (Card*)*cardIter; pCardToPlay->OnActionPhase( pEngine ); } pPlayer->SetGolemFlag( false ); pPlayer->PutCardsInPlay( actionCardList ); } else { // TODO: report error throw std::wstring( L"Error: ScoutCard::OnActionPhase" ); } }
void GameBoard::initialize(const CardList& cards) { CardList columnCards; columnCards.reserve(6); const int k_numColumnsInFirstGroup = 4; const int k_numColumnsInSecondGroup = 6; const int k_numCardsInColumnFisrtGroup = 5; const int k_numCardsInColumnSecondGroup = 4; for(int i = 0; i < k_numColumnsInFirstGroup; i++) { CardList::const_iterator it_from = cards.begin() + i * k_numCardsInColumnFisrtGroup; CardList::const_iterator it_to = cards.begin() + (i + 1) * k_numCardsInColumnFisrtGroup; columnCards.insert(columnCards.begin(), it_from, it_to); m_cardColumns[i].initialize(columnCards); columnCards.clear(); } const int k_totalCardsInFirstGroup = 20; //k_numColumnsInFirstGroup * k_numCardsInColumnFisrtGroup; for(int i = 0; i < k_numColumnsInSecondGroup; i++) { CardList::const_iterator it_from = cards.begin() + k_totalCardsInFirstGroup + i * k_numCardsInColumnSecondGroup; CardList::const_iterator it_to = cards.begin() + k_totalCardsInFirstGroup + (i + 1) * k_numCardsInColumnSecondGroup; columnCards.insert(columnCards.begin(), it_from, it_to); m_cardColumns[k_numColumnsInFirstGroup + i].initialize(columnCards); columnCards.clear(); } m_cardDeck.initialize(SpiderGame::k_seriesToPass); m_buildedStackDeck.reset(); m_scoreBoard.reset(); }