Exemplo n.º 1
0
/**********************************************************************
* Purpose: This function returns bool for if a move is valid
*
* Entry: This function takes a top and bottom card.
*
* Exit: This function returns a bool.
*
************************************************************************/
bool Board::isValid(Card move, Card bottom)
{
	bool valid(false);
	Rank move_rank = move.GetRank();
	Suit move_suit = move.GetSuit();

	Rank bottom_rank = bottom.GetRank();
	Suit bottom_suit = bottom.GetSuit();

	// Red onto a black card case
	if (move_suit == HEART || move_suit == DIAMOND)
	{
		if (bottom_suit == CLUB || bottom_suit == SPADE)
		{
			if (move_rank == (bottom_rank - 1))
				valid = true;
		}
	}

	// Black onto a red card case
	if (move_suit == CLUB || move_suit == SPADE)
	{
		if (bottom_suit == HEART || bottom_suit == DIAMOND)
		{
			if (move_rank == (bottom_rank - 1))
				valid = true;
		}
	}

	return valid;
}
Exemplo n.º 2
0
//------------------------------------------------------------------------------
// PrepForTrick - Ensure the user can onbly play valid Tricks.
//------------------------------------------------------------------------------
void CardManager::PrepForTrick(void)
{
    if ( cpuTrick->GetSize() > 0 )
    {
        Card* cpuCard    = cpuTrick->GetCard(0);
        bool  validCards = false;
        int   i          = 0;

        // Loop through the user's hand checking if there is a card
        // that can be played.
        while ( !validCards && i < playerHand->GetSize() )
        {
            if ( playerHand->GetCard(i++)->GetSuit() == cpuCard->GetSuit() )
                validCards = true;
        }

        // Now disable the other cards if valid ones were found.
        if ( validCards )
        {
            Card* card;

            for ( i = 0; i < playerHand->GetSize(); i++ )
            {
                card = playerHand->GetCard(i);

                if ( card->GetSuit() != cpuCard->GetSuit() )
                    card->setFlag(QGraphicsItem::ItemIsMovable, false);
            }
        }
    }
}
Exemplo n.º 3
0
/**********************************************************************
* Purpose:	add card to home cell
* Entry: 	Card card
* Exit:		bool
************************************************************************/
bool HomeCell::Add(Card card)
{
	bool valid = true;

	if (card.GetRank() == Card::ACE ||
		(!m_home[card.GetSuit() - Card::HEART]->IsEmpty() &&
		(card.GetRank() == (m_home[card.GetSuit() - Card::HEART]->Peek().GetRank() + 1))))
	{
		m_home[card.GetSuit() - Card::HEART]->Push(card);
	}
	else
		valid = false;

	return valid;
}
Exemplo n.º 4
0
// Assumes the input set only contains cards of a single kit
Set<Card>* DifferentialFilter::Enter( Set<Card>* pInput )
{
	pInput->Begin();
	if ( pInput->HasNext() )
	{
		Card* pCard = pInput->GetNext();
		int iSuit	= pCard->GetSuit();
		int iKit	= pCard->GetKit();

		Set<Card>* pCompleteKit = Deck::GetInstace()->GetKit( iSuit | iKit );
		Set<Card>* pResultSet = new Set<Card>();
		
		for (pCompleteKit->Begin(); pCompleteKit->HasNext();)
		{
			Card* pResultCard = pCompleteKit->GetNext();
			bool bRequired = true;

			for (pInput->Begin(); pInput->HasNext();)
			{
				Card* pInputCard = pInput->GetNext();
				if ( pResultCard->GetID() == pInputCard->GetID() )
				{
					bRequired = false;
					break;
				}
			}

			if (bRequired)
			{
				pResultSet->PushBack(pResultCard);
			}
		}

		return pResultSet;
	}

	return NULL;
}
Exemplo n.º 5
0
bool TableauToFoundation::PerformMovement(BoardLayout* layout)
{
  assert(layout);
  bool movement_performed;
  PileSet* pile_set = layout->GetPileSet();
  assert(pile_set);
  Card* card = NULL;
  Tableau* tableau = (*(pile_set->GetTableaus()))[m_origin_tableau];

  if(!tableau || (tableau->Size() == 0)) {
    movement_performed = false;
  }
  else {
    card = tableau->BottomCard();
    Foundation* foundation = pile_set->GetFoundation(card->GetSuit());
    if(!card || !foundation || !foundation->Push(card)) {
      // QUIT
      if(!card) {
        std::cout << "NO CARD IN TABLEAU:" << card->ToShortString();
      }
      else {
        std::cout << "CARD:" << card->ToShortString();
      }
      //

      movement_performed = false;
    }
    else {
      tableau->Pop();
      movement_performed = true;
    }

  }
  m_complete = false;
  return movement_performed;
}
Exemplo n.º 6
0
bool operator==(const Card& c1, const Card& c2) {
	return (c1.GetSuit() == c2.GetSuit() && c1.GetValue() == c2.GetValue());
}
Exemplo n.º 7
0
// Called when the left button is double clicked
// If a card is under the pointer and it can move elsewhere then move it.
// Move onto a foundation as first choice, a populated base as second and
// an empty base as third choice.
// NB Cards in the m_pack cannot be moved in this way - they aren't in play
// yet
void Game::LButtonDblClk(wxDC& dc, int x, int y)
{
    Pile* pile = WhichPile(x, y);
    if (!pile) return;

    // Double click on m_pack is the same as left button down
    if (pile == m_pack)
    {
        LButtonDown(dc, x, y);
    }
    else
    {
        Card* card = pile->GetTopCard();

        if (card)
        {
            int i;

            // if the card is an ace then try to place it next
            // to an ace of the same suit
            if (card->GetPipValue() == 1)
            {
                for(i = 0; i < 4; i++)
                {
                    Card* m_topCard = m_foundations[i]->GetTopCard();
                    if ( m_topCard )
                    {
                        if (m_topCard->GetSuit() == card->GetSuit() &&
                            m_foundations[i + 4] != pile &&
                            m_foundations[i + 4]->GetTopCard() == 0)
                        {
                            pile->RemoveTopCard(dc);
                            m_foundations[i + 4]->AddCard(dc, card);
                            DoMove(dc, pile, m_foundations[i + 4]);
                            return;
                        }
                    }
                }
            }

            // try to place the card on a foundation
            for(i = 0; i < 8; i++)
            {
                if (m_foundations[i]->AcceptCard(card) && m_foundations[i] != pile)
                {
                    pile->RemoveTopCard(dc);
                    m_foundations[i]->AddCard(dc, card);
                    DoMove(dc, pile, m_foundations[i]);
                    return;
                }
            }
            // try to place the card on a populated base
            for(i = 0; i < 10; i++)
            {
                if (m_bases[i]->AcceptCard(card) &&
                    m_bases[i] != pile &&
                    m_bases[i]->GetTopCard())
                {
                    pile->RemoveTopCard(dc);
                    m_bases[i]->AddCard(dc, card);
                    DoMove(dc, pile, m_bases[i]);
                    return;
                }
            }
            // try to place the card on any base
            for(i = 0; i < 10; i++)
            {
                if (m_bases[i]->AcceptCard(card) && m_bases[i] != pile)
                {
                    pile->RemoveTopCard(dc);
                    m_bases[i]->AddCard(dc, card);
                    DoMove(dc, pile, m_bases[i]);
                    return;
                }
            }
        }
    }
}
Exemplo n.º 8
0
// Called when the left button is double clicked
// If a card is under the pointer and it can move elsewhere then move it.
// Move onto a foundation as first choice, a populated base as second and
// an empty base as third choice.
// NB Cards in the m_pack cannot be moved in this way - they aren't in play
// yet
void Game::LButtonDblClk(wxDC& dc, int x, int y)
{
    Pile* pile = WhichPile(x, y);
    if (!pile) return;

    // Double click on m_pack is the same as left button down
    if (pile == m_pack)
    {
        LButtonDown(dc, x, y);
    }
    else
    {
        Card* card = pile->GetTopCard();

        if (card)
        {
            int i;

            // if the card is an ace then try to place it next
            // to an ace of the same suit
            if (card->GetPipValue() == 1)
            {
#if defined(__INTEL_COMPILER) && 1 /* VDM auto patch */
#   pragma ivdep
#   pragma swp
#   pragma unroll
#   pragma prefetch
#   if 0
#       pragma simd noassert
#   endif
#endif /* VDM auto patch */
                for(i = 0; i < 4; i++)
                {
                    Card* m_topCard = m_foundations[i]->GetTopCard();
                    if ( m_topCard )
                    {
                        if (m_topCard->GetSuit() == card->GetSuit() &&
                            m_foundations[i + 4] != pile &&
                            m_foundations[i + 4]->GetTopCard() == 0)
                        {
                            pile->RemoveTopCard(dc);
                            m_foundations[i + 4]->AddCard(dc, card);
                            DoMove(dc, pile, m_foundations[i + 4]);
                            return;
                        }
                    }
                }
            }

            // try to place the card on a foundation
#if defined(__INTEL_COMPILER) && 1 /* VDM auto patch */
#   pragma ivdep
#   pragma swp
#   pragma unroll
#   pragma prefetch
#   if 0
#       pragma simd noassert
#   endif
#endif /* VDM auto patch */
            for(i = 0; i < 8; i++)
            {
                if (m_foundations[i]->AcceptCard(card) && m_foundations[i] != pile)
                {
                    pile->RemoveTopCard(dc);
                    m_foundations[i]->AddCard(dc, card);
                    DoMove(dc, pile, m_foundations[i]);
                    return;
                }
            }
            // try to place the card on a populated base
#if defined(__INTEL_COMPILER) && 1 /* VDM auto patch */
#   pragma ivdep
#   pragma swp
#   pragma unroll
#   pragma prefetch
#   if 0
#       pragma simd noassert
#   endif
#endif /* VDM auto patch */
            for(i = 0; i < 10; i++)
            {
                if (m_bases[i]->AcceptCard(card) &&
                    m_bases[i] != pile &&
                    m_bases[i]->GetTopCard())
                {
                    pile->RemoveTopCard(dc);
                    m_bases[i]->AddCard(dc, card);
                    DoMove(dc, pile, m_bases[i]);
                    return;
                }
            }
            // try to place the card on any base
#if defined(__INTEL_COMPILER) && 1 /* VDM auto patch */
#   pragma ivdep
#   pragma swp
#   pragma unroll
#   pragma prefetch
#   if 0
#       pragma simd noassert
#   endif
#endif /* VDM auto patch */
            for(i = 0; i < 10; i++)
            {
                if (m_bases[i]->AcceptCard(card) && m_bases[i] != pile)
                {
                    pile->RemoveTopCard(dc);
                    m_bases[i]->AddCard(dc, card);
                    DoMove(dc, pile, m_bases[i]);
                    return;
                }
            }
        }
    }
}
Exemplo n.º 9
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;
}