Example #1
0
// Checks if the card is a legal card to be played
bool Player::checkCardPlayable(const Card* card, const std::vector<Card*> cardsOnTable) const {
    
    // Seven of Spade
    if(card->getRank() == SEVEN && card->getSuit() == SPADE) return true;

    for(unsigned int index = 0; index < cardsOnTable.size(); index++){
        Card* inGameCard = cardsOnTable[index];
        //if the card is the same rank
        if(card->getRank() == SEVEN) return true;
        // If the card is the same suit but one rank below
        if(card->getSuit() == inGameCard->getSuit() && card->getRank() == (inGameCard->getRank()-1)) return true;
        // If the card is the same suit but one rank above
        if(card->getSuit() == inGameCard->getSuit() && card->getRank() == (inGameCard->getRank()+1)) return true;
    }
    return false;
}
Example #2
0
void Deposit_Card::transfer(Card& otherCard, const double money)
{
	if (Deposit_Card::getBalance() < 0)
	{
		cout << "卡处于透支状态, 不能转出, 请充值" << endl;
		return;
	}
	if (Deposit_Card::getBalance() < money)
	{
		cout << "卡里只有" << Deposit_Card::getBalance() << "元, 不足" << money << "元, 无法转账" << endl;
		return;
	}
	Deposit_Card::setBalance(Deposit_Card::getBalance() - money);
	otherCard.receiveMoney(money);
	cout << "成功转给" << otherCard.getCardholderName() << " " << money << "元" << endl;
}
Example #3
0
Boolean Trick::hasJack() {

	for ( CArray<PlayersCard*>::iterator i = book->BeginIterator() ;
			 i != book->EndIterator();
			 i++) {

		Card *tmp = (*i)->c;

		if ( tmp->Suit() == gManager->tbl->trump && tmp->Face() == Card::jack ) {
			return true;
		}
	}
	
	return false;

}
Example #4
0
Property::Property(Card& card, uint32_t id)
	: DrmObject(card, id, DRM_MODE_OBJECT_PROPERTY)
{
	m_priv = new PropertyPriv();
	m_priv->drm_prop = drmModeGetProperty(card.fd(), id);
	m_name = m_priv->drm_prop->name;
}
Example #5
0
bool LayoutPiles::Add_Card_no_empty(int p, Card c) {
        if(p >= 0 && p < 4) { //center piles
        if(layout_piles[p].size()==0) {
            return false;
        }
        else if(layout_piles[p].get_top_card().is_valid_move(c)) {
            layout_piles[p].add_card(c);
            return true;            
        }
    }
    else if(p >= 4 && p < 8) { //corner piles
        if(layout_piles[p].size()==0 && c.get_rank() == 'K') {
            layout_piles[p].add_card(c);
            return true;
        }
        else if(layout_piles[p].size()==0) {
            return false;
        }
        else if(layout_piles[p].get_top_card().is_valid_move(c)) {
            layout_piles[p].add_card(c);
            return true;
        }
    }
    return false;
}
Example #6
0
	void GameBoard::buildTower(Player& p, const Card& c, const BoardPosition& bp,int phase){
		/*A player can build a tower at the current location of one of the player's pieces. 
		For building a tower, the player needs to play a cards with a number according to 
		the height of the tower and have enough blocks to build the tower. 
		The height of the tower is controlled by the phase of the game. 
		The player receives points corresponding to the number of blocks of the tower. 
		The player's piece is returned to the player's side of the board 
		(and can be re-added to the board in a future turn).
		pays with the action card c for a tower to be build by the player on board position bp. 
		It will throw an exception illegalBuild if the tower cannot be built (invalid). 
		It must update a Player because of the construction.*/
		int x=bp.x;
		int y=bp.y;
		if((((Piece*)myItem[x][y])->getName()==p.getInitial('x')))
		{
			if(p.increaseBlocks(0)>=phase&&c.getDistance()==phase+1)
			{
				p.decreaseBlocks(phase+1);
				p.increasePoints(phase+1);
				myItem[x][y]=new Tower(c);
				p.addPiece();
			}
			else
				throw myException("illegalBuild");
		}
		else
			throw myException("illegalBuild");
	};
Example #7
0
bool LayoutPiles::Add_Card(int p, Card c) { 
    if(p >= 0 && p < 4) { //center piles
        if(layout_piles[p].size()==0) {//if no card there
            layout_piles[p].add_card(c);
            return true;
        }
        else if(layout_piles[p].get_top_card().is_valid_move(c)) {//if valid move onto pile
            layout_piles[p].add_card(c);
            return true;            
        }
    }
    else if(p >= 4 && p < 8) { //corner piles
        if(layout_piles[p].size()==0 && c.get_rank() == 'K') {//if adding a king to a corner pile
            layout_piles[p].add_card(c);
            return true;
        }
        else if(layout_piles[p].size()==0) {//can't add non kings to corners
            return false;
        }
        else if(layout_piles[p].get_top_card().is_valid_move(c)) {//if valid move
            layout_piles[p].add_card(c);
            return true;
        }
    }
    return false;
}
void InterfaceDrawVisitor::DrawTableausInLine(std::vector<Tableau*>* tableaus,
                                              const uint8_t& line) const
{
  assert(tableaus);
  for (auto tableau_it : *tableaus) {
    Card* card = tableau_it->CardAt(line);
    if(card) {
      std::cout.width(6);
      std::cout << std::right << card->ToShortString();
    }
    else {
      std::cout.width(6);
      std::cout << std::right << "";
    }
  }
}
Example #9
0
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);
    }
}
int main(int argc, char* argv[]) {
    QApplication app(argc, argv);
    QTextStream cout(stdout);    
    CardDeck deck;
    CardHand *hand;
    Card *aceCard = new Card(0, 0);
    cout << "image to acecard: " << aceCard->getImage() << endl;
    cout << "Deals to user 2 cards: " << flush;
    hand = deck.deal(2);
    cout << hand->toString() << endl;
    cout << "value of deal: " << hand->getValue() << endl;
    cout << "add ace card." << endl;
    hand->append(aceCard);
    cout << "now value of deal is: " << hand->getValue() <<endl;
    return 0;
}
Example #11
0
  //
  // Member Methods
  //
  // Post: Runs the game
  void Dealer::play( )
  {
    deck_.shuffle();

    for (short i = 0; i < game_->starting_hand(); ++i ) {
      user_.take_card( deck_.deal( ) );
      ai1_.take_card( deck_.deal( ) );
      partner_.take_card( deck_.deal( ) );
      ai2_.take_card( deck_.deal( ) );
    } 

    Card trump = deck_.deal();
    game_->trump( trump.suit() );
    deck_.discard( trump );
    print();
  }
    // ---------------------------------------------------------------------------------
    // shuffle - shuffles the deck
    // Caller can specify the number of shuffles if more time shuffling is desired,
    // but the results of a single shuffle should be sufficient.
    // The default shuffle is 100 x deckSize_ random 2-card swaps
    // ---------------------------------------------------------------------------------
    void shuffle(unsigned int aNumberOfShuffles = 1)
    {
        // Seed the random number generator
        srand((unsigned int)(time(NULL) & 0xFFFFFFFF));

        for (unsigned int shuffleCount = 0; shuffleCount < aNumberOfShuffles; ++shuffleCount)
        {
            // Considering the deck size, perform 100x passes
            // through a random selection of 2-card swaps
            for (unsigned int passCount = 0; passCount < 100; ++passCount)
            {
                for (unsigned int cardCount = 0; cardCount < deckSize_; ++cardCount)
                {
                    unsigned int indexA = rand() % deckSize_;
                    unsigned int indexB = rand() % deckSize_;

                    // Put card A before card B
                    ppCards_[indexB]->insertBefore(ppCards_[indexA]);

                }
            }
        }

        pTopOfDeck_ = pTopOfDeck_->getFirst();
    }
Example #13
0
void TributeCard::OnActionPhase( Engine* pEngine )
{
    Player* pPlayer = pEngine->GetCurrentPlayer();
    Player* pPlayerToLeft = pEngine->GetNextPlayer( pPlayer );
    CardList cardsDrawnList = 
        pPlayerToLeft->RevealCardsFromDeck( 2 );
    CardListIter cardIter;

    Card* pFirstCard = *cardIter;

    if( pFirstCard->IsActionCard() )
    {
        pPlayer->PlusActions( 2 );
    }

    if( pFirstCard->IsTreasureCard() )
    {
        pPlayer->PlusCoins( 2 );
    }

    if( pFirstCard->IsVictoryCard() )
    {
        pPlayer->DrawCardsToHand( 2 );
    }

    cardIter++;
    Card* pSecondCard = *cardIter;
    
    if( pSecondCard->CardId() != pFirstCard->CardId() )
    {
        if( pSecondCard->IsActionCard() )
        {
            pPlayer->PlusActions( 2 );
        }

        if( pSecondCard->IsTreasureCard() )
        {
            pPlayer->PlusCoins( 2 );
        }

        if( pSecondCard->IsVictoryCard() )
        {
            pPlayer->DrawCardsToHand( 2 );
        }
    }

}
Example #14
0
bool operator!=(Card & c1, Card & c2){
    bool sameColor = (c1.get_color()==c2.get_color());
    bool sameShading = (c1.get_shading() == c2.get_shading());
    bool sameShape = (c1.get_shape() == c2.get_shape());
    bool sameNumber = (c1.get_number() == c2.get_number());
    
    return !(sameColor && sameShading && sameShape && sameNumber);
    
}
Example #15
0
/* Return the split card to be moved and reduced the current hand value */
const Card Box::MoveSplitCard()
{
	Card TempCard;

	TempCard = Hand.at(1);
	qDebug() << "TempCard = " << TempCard.GetName() << " (" << TempCard.GetValue() << ") of " << TempCard.GetSuit();
	HandValue -= Hand.at(1).GetValue();
	Hand.pop_back();
	/* AcesHeld must be reassessed after a split */
	string CompareString = Hand.front().GetName();
	if (CompareString.compare("Ace") == 0)
	{
		AcesHeld = 1;
		HandValue = 11;
	}
	return TempCard;
}
    // ---------------------------------------------------------------------------------
    // showCards - simple display function to see the suit and rank of a card in
    // a specific position
    // ---------------------------------------------------------------------------------
    void showCards()
    {
        // Find the top of the deck by picking any card and traversing the
        // previous pointers until NULL is found
        Card *pThis = this->getFirst();

        unsigned int i = 1;
        do
        {
            printf("CARD %3d: %8s of %8s\n", i, RankNames[pThis->getRank()], SuitNames[pThis->getSuit()]);

            ++i;
            pThis = pThis->getNext();

        } while (pThis != NULL);

    }
Example #17
0
//============================================================================
// Name        : GainCard()
// Author      : LSH
// Version     : 1.1
// Param       : ahand, adeck, adiscard
// Return      : NULL
// Deprecated  : Using
// See         : card.cpp/ActionBureaucrat
// Todo        : Gain card some card
// Bug         : No bug
//============================================================================
void Player::GainCard(string name, int count, place dest){
	for(int i=0;i<count;i++){
		Card *c = new Card;
		c->SetCard(name);
		cout << c->GetName() << ", " << c->GetCost() << endl;
		if(dest ==DISCARD){
			adiscard.push_back(*c);
		}
		else if(dest == HAND){
			ahand.push_back(*c);
		}
		else if(dest == DECK){
			adeck.push_front(*c);
		}
		cout << "name : " << c->GetName() << endl;
	}
};
//
// CardSet::locate() - 内部での target のカードの位置を返す(-1: ない)
//
int CardSet::locate(const Card & target) const
{
	for(int i = 0; i < numcard; i++)
		if(target.equal(cards[i]))
			return i;

	return -1;	// 見つからなかった
}
Example #19
0
Deck::Deck()
{
	Card tempCard;
	for(int i = 0; i < 4; i++)
	{
		for(int j = 0; j < 13; j++)
		{
			if(j !=0)
				tempCard.setVal(Card::Face(j+1));
			else
				tempCard.setVal(Card::Face(j));
			tempCard.setSuit(Card::Suit(i));
			cards.push_back(tempCard);
		}
	}
	count = 0;
}
Example #20
0
int GameMao::findCardIndex(Player& y, Card x)
{

	for(unsigned int i = 0; i < y.getHand().size(); i++)
		if (y.getHand()[i].name() == x.name())
			return i;
	return 0;
}
Example #21
0
char Computer::moveFrom() {

	Card * stockTop = this->stockPile->top();

/* EXTRA CREDIT ATTEMPT
	Card * buildTop = nullptr;
*/

	/* Check stock pile for wild card. */
	if (stockTop->getVal() == 0) {
		return '0';
	} 

/* EXTRA CREDIT ATTEMPT
	for (int i = 0; i < 4; i++) {
		if (!this->buildChoices[i]->isEmpty()
				&& this->buildChoices[i]->top() != nullptr
				&& this->buildChoices[i]->top()->getVal() + 1 == stockTop->getVal()) {
			this->moveCard = stockTop;
			return '0';
		}
	}
*/

	/* Check hand for wild card. */
	for (int i = 0; i < 5; i++) {
		if (this->hand->getCard(i) != nullptr
				&& this->hand->getCard(i)->getVal() == 0) {
			this->moveCard = this->hand->getCard(i);
			return i + 1 + ASCII_SHIFT;
		}
	}

	/* Check discard piles for wild card. */
	for (int i = 0; i < 4; i++) {
		if (!this->discardPiles[i]->isEmpty()
				&& this->discardPiles[i]->top()->getVal() == 0) {
			this->moveCard = this->discardPiles[i]->top();
			return i + 6 + ASCII_SHIFT;
		}
	}

	/* Otherwise, try random cards. */
	char ch = (rand() % NUM_MOVE_FROM) + ASCII_SHIFT;
	return ch;
}
Example #22
0
/*
	Determines whether the discard pile can accept a card
	based on GolfSolitaire rules. If the cards differ by 
	a value of |1|, it can be added to the pile. DeckPile
	cards are auto-accepted
*/
bool DiscardPile::canTake(Card aCard){

	if(thePile.empty())
		return true;
	if(!aCard.getFaceUp()){ //from the deck
		return true;
	}
	else{
		int rankDiff = aCard.getRank()-top().getRank();
		if(rankDiff==1 || rankDiff==-1 || thePile.empty())
			return true;
		else if((aCard.getRank()==13 && top().getRank()==1) || (aCard.getRank()==1 && top().getRank()==13)) //handles the case of Ace and King
			return true;
	}

	return false;
}
Example #23
0
//update the table of cards
void View::UpdateTablePics() {
	vector<Card*> tableCards = game_->getCardsonTable();
	int k = 0;
	for (int j=0; j<4; j++) {
		for (int i=0; i<RANK_COUNT; i++) {
			Card* temp = new Card( Suit(j), Rank(i) );
			if ( match(temp ,tableCards) ) {
				tableCardPics[k]->set(deck.image(temp->getRank(), temp->getSuit() ));

			}
			else {
				tableCardPics[k]-> set(deck.null());
			}
		k++;
		}
	}
}
Card *Card::childWithTag(Tag *tag)
{
    // Return ourself, if we match the tag.
    if (this->match(tag)) {
        return this;
    }

    for(CardList::iterator iter = attached.begin(); iter != attached.end(); iter++) {
        Card *child = *iter;
        Card *isMatch = child->childWithTag(tag);
        if (isMatch != NULL) {
            return isMatch;
        }
    }

    return NULL;
}
Example #25
0
/*
 * For some of the debugging and inspecting purposes
 * This hint() shows all the card that player holds on hand
 */
void Player::hint()
{
    vector<Card*>::const_iterator ci = cards_in_use_.begin();
    if (typeid(*this) == typeid(Player)) {
        cout << "Player has: ";
    } else {
        cout << "Dealer has: ";
    }
    
    while (ci != cards_in_use_.end()) {
        Card *c = *ci;
        c->show();
        ci++;
    }
    cout << "points: " << calc_points();
    cout << endl;
}
Example #26
0
/* returns -1 when card cannot be purchased, number of coins remaining after
 * purchase if buys remain, or zero otherwise.
 */
int Player::buyCard(Card card) {
    // try to buy card
    if (card.getCost() < coins && buys > 0) {
        coins -= card.getCost();
        buys--;
        discard_pile.push_back(card);
    }
    else {
        cout << "Player could not afford card: " << card;
        return -1;
    }
    if (buys > 0) {
        return coins;
    } else {
        return 0;
    }
}
Example #27
0
//  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;
}
Example #28
0
File: Deck.cpp Project: jbobrow/Set
void Deck::createCards()
{
    numCombinations = pow(numOptions,numProperties);

    Card *c;
    int count = 0;

    for( int i=0; i<3; i++ ) {

        for( int ii=0; ii<3; ii++ ) {

            for( int iii=0; iii<3; iii++ ) {

                for( int iiii=0; iiii<3; iiii++ ) {

                    c = new Card(count++);
                    c->setCount(i);
                    c->setColor(ii);
                    c->setFill(iii);
                    c->setShape(iiii);
                    c->setVisuals();

                    c->position.set( 50 * (iii*3 + iiii), 50 * (i*3 + ii), 0);
                    c->changeState(CARD_STATE_IN_DECK);

                    cards.push_back(c);
                    addChild(cards.back());
                }
            }
        }
    }
}
Example #29
0
void Checker::parse(ManagerBase* m, std::vector<Card>& src, CardContainer& res)
{
    std::sort(src.begin(), src.end(), CardSortCmp(m));
    res.clear();
    CardUnit single;
    single.mask.set(CardMask::Single);
    std::vector<CardUnit> pairUnit;
    Card pre;
    for (auto& i : src) {
        if (pre == i) {
            pairUnit.push_back({CardMask::Pair|CardMask(m, i),{i, i}});
            pre.set(Card::Null);
        } else {
            if (pre.value() != Card::Null) {
                single.mask.merge(CardMask(m, pre));
                single.cards.push_back(pre);
            }
            pre = i;
        }
    }
    if (pre.value() != Card::Null) {
        single.mask.merge(CardMask(m, pre));
        single.cards.push_back(pre);
    }
    if (!pairUnit.empty()) {
        size_t i = 0;
        for (size_t j = 1; j < pairUnit.size(); ++j) {
            if (canConcat(m, pairUnit[i].cards.back(), pairUnit[j].cards[0])) {
                pairUnit[i].cards.insert(pairUnit[i].cards.end(), pairUnit[j].cards.begin(), pairUnit[j].cards.end());
            } else {
                res.put(pairUnit[i]);
                i = j;
            }
        }
        res.put(pairUnit[i]);
        if (res.size() > 1 && pairUnit.size() > 2) {
            res.sort([](const CardUnit& u1, const CardUnit& u2) {
                return u1.cards.size() > u2.cards.size();
            });
        }
    }
    if (!single.cards.empty()) {
        res.put(single);
    }
}
Example #30
0
void GameMaster::beginRound() {
	cout << "A new round begins. It's player " 
		 << (_currentPlayerNumber + 1)
		 << "'s turn to play."
		 << endl;
	
	for(int i = 0; i < _deck.cards().size(); i++) {
		takeCurrentPlayerTurn();		
	}

	for(int i = 0; i < PLAYER_COUNT; i++) {
		Player *player = _players[i];
		vector<Card> discardPile = player->discardPile();

		int playerScore = 0;

		cout << "Player " << i + 1 << "'s discards: ";

		for(int j = 0; j < discardPile.size(); j++) {
			Card card = discardPile[j];

			cout << card;

			if(j < discardPile.size() - 1) {
				cout << " ";
			}

			playerScore += (card.getRank() + 1);
		}

		cout << endl;

		cout << "Player " << i + 1 << "'s score: " 
			 << _scores[i] << " + " << playerScore
			 << " = ";

		_scores[i] += playerScore;

		cout << _scores[i] << endl;

		player->returnCards();
	}

	_table = Table();
}