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;
}
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() );
}
Exemple #3
0
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" );
    }
}
/// \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() );
}