diff options
author | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
---|---|---|
committer | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
commit | c90c389a8a8d9d8661e9772ec4144c5cf2039f23 (patch) | |
tree | 6d8391395bce9eaea4ad78958617edb20c6a7573 /kpat/pile_algorithms.cpp | |
download | tdegames-c90c389a8a8d9d8661e9772ec4144c5cf2039f23.tar.gz tdegames-c90c389a8a8d9d8661e9772ec4144c5cf2039f23.zip |
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdegames@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kpat/pile_algorithms.cpp')
-rw-r--r-- | kpat/pile_algorithms.cpp | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/kpat/pile_algorithms.cpp b/kpat/pile_algorithms.cpp new file mode 100644 index 00000000..7ca3469c --- /dev/null +++ b/kpat/pile_algorithms.cpp @@ -0,0 +1,69 @@ +#include "pile.h" +#include <kdebug.h> + +bool Pile::add_klondikeTarget( const CardList& c2 ) const +{ + Card *newone = c2.first(); + if (isEmpty()) + return (newone->rank() == Card::Ace); + + return (newone->rank() == top()->rank() + 1) + && (top()->suit() == newone->suit()); +} + +bool Pile::add_klondikeStore( const CardList& c2 ) const +{ + Card *newone = c2.first(); + if (isEmpty()) { + return (newone->rank() == Card::King); + } + + return (newone->rank() == top()->rank() - 1) + && (top()->isRed() != newone->isRed()); +} + +bool Pile::add_gypsyStore( const CardList& c2) const +{ + Card *newone = c2.first(); + if (isEmpty()) + return true; + + return (newone->rank() == top()->rank() - 1) + && (top()->isRed() != newone->isRed()); +} + +bool Pile::add_freeCell( const CardList & cards) const +{ + return (cards.count() == 1 && isEmpty()); +} + +bool Pile::remove_freecellStore( const Card *c) const +{ + // ok if just one card + if (c == top()) + return true; + + // Now we're trying to move two or more cards. + + // First, let's check if the column is in valid + // (that is, in sequence, alternated colors). + int index = indexOf(c) + 1; + const Card *before = c; + while (true) + { + c = at(index++); + + if (!((c->rank() == (before->rank()-1)) + && (c->isRed() != before->isRed()))) + { + kdDebug(11111) << c->name() << " - " << before->name() << endl; + return false; + } + if (c == top()) + return true; + before = c; + } + + return true; +} + |