예제 #1
0
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);
}
예제 #2
0
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;
}
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;
}
예제 #4
0
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) );
        }
    }
}
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;
}
예제 #6
0
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;
}
예제 #7
0
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;
                }
            }
        }
    }
}
예제 #8
0
파일: GolemCard.cpp 프로젝트: npburg/domlib
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" );
    }
}
예제 #9
0
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() );
}