Bug 91317 - Klondike (draw 3) incorrect unwinnable game message
Summary: Klondike (draw 3) incorrect unwinnable game message
Status: RESOLVED FIXED
Alias: None
Product: kpat
Classification: Applications
Component: general (show other bugs)
Version: unspecified
Platform: unspecified Linux
: NOR normal
Target Milestone: ---
Assignee: Stephan Kulow
URL:
Keywords:
: 94174 (view as bug list)
Depends on:
Blocks:
 
Reported: 2004-10-14 15:01 UTC by Alan Prescott
Modified: 2007-03-13 15:45 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments
The testcase showing the bug (4.55 KB, text/plain)
2004-10-23 22:19 UTC, Harald Oberhofer
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Alan Prescott 2004-10-14 15:01:54 UTC
Version:           2.2 (using KDE 3.3.0, SuSE)
Compiler:          gcc version 3.3.1 (SuSE Linux)
OS:                Linux (i686) release 2.4.21-243-smp4G

I have seen the 'Unwinnable game' message a few times while playing Klondike (draw 3) - this time I elected to continue and won the game - Should have saved and attached it - sorry!
Comment 1 Harald Oberhofer 2004-10-23 22:17:10 UTC
I can confirm this bug it seems to occur if in your first run you take a multiple of three cards of your stack. KPat then seems to believe that because on the next run you don't get any new cards you can't win anymore, which is not allways correct.

I have saved a game in which this happens.
My System:
kpat 2.2( using kde 3.3.1, Gentoo)
gcc version: 3.3.4-r1 Gentoo Linux
Linux: i686 2.6.8-gentoo-r8
Comment 2 Harald Oberhofer 2004-10-23 22:19:47 UTC
Created attachment 8010 [details]
The testcase showing the bug

This is the testcase showing the bug. 
If on the first run thorugh your stack you make all possible moves,
at the end of this run the false message should appear!
Comment 3 Alan Prescott 2004-10-29 14:11:36 UTC
Game No: 845718133
Run in Demo mode produces the message - if allowed to continue the game wins.
KPatience 2.2, KDE 3.3.1
Comment 4 Inge Wallin 2005-01-05 17:17:59 UTC
*** Bug 94174 has been marked as a duplicate of this bug. ***
Comment 5 Inge Wallin 2005-01-07 18:54:25 UTC
CVS commit by ingwa: 

Fix bug 91317: Klondike (draw 3) incorrect unwinnable game message

BUG: 91317


  M +6 -1      CHANGES   1.18
  M +15 -15    klondike.cpp   1.48


--- kdegames/kpat/CHANGES  #1.17:1.18
@@ -1,6 +1,11 @@
 2005-01-07 Inge Wallin <inge@lysator.liu.se>
 
+        Fix bug 91317: Klondike (draw 3) incorrect unwinnable game message
+        - Fix criteria for lost game in klondike.
+
+        ---- CVS commit here ----
+
         Fix bug 96531: KPat: Mod3 incorrect unwinnable game message
-        - mod3.cpp(isGameLost): Fix criteria for lost game.
+        - Fix criteria for lost game in mod3.
 
 2004-11-10 Inge Wallin <inge@lysator.liu.se>

--- kdegames/kpat/klondike.cpp  #1.47:1.48
@@ -351,13 +352,10 @@ bool Klondike::isGameLost() const
     kdDebug( 1111 ) << "Is the game lost?" << endl;
 
-    // If we did not even redeal once, and the deck is not empty yet, we cannot
-    // tell what the source pile contains, so we cannot tell whether the game
-    // is lost or not.
-    if ( !redealt && !deck->isEmpty() ) {
-        kdDebug( 1111 ) << "No, we don't know all cards in the pile yet." << endl;
+    if (!deck->isEmpty()) {
+        kdDebug( 1111 ) << "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
+    // 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 ) {
@@ -373,18 +371,20 @@ bool Klondike::isGameLost() const
     }
 
+    // Create a card list - srcPileCards - that contains all accessible
+    // cards in the pile and the deck.
     CardList srcPileCards;
     if ( EasyRules ) {
         srcPileCards = pile->cards();
-        srcPileCards += deck->cards();
     } else {
-        /* In the draw3 mode, not every card in the source pile is accessible,
-         * but only third one. For the cards in the deck, start from the back
-         * since the cards are in reverse order.
+        /* In the draw3 mode, not every card in the source pile is
+         * accessible, but only every third one.
          */
-        for ( int i = deck->cards().count() - 3; i > 2; i -= 3 ) {
-            srcPileCards += deck->cards()[ i ];
+        for ( unsigned int i = 2; i < pile->cards().count(); i += 3 ) {
+            kdDebug( 1111 ) << "Found card "<< pile->cards()[i]->name()<< endl;
+            srcPileCards += pile->cards()[ i ];
         }
-        if ( !deck->cards().isEmpty() && deck->cards().count() % 3 != 0 ) {
-            srcPileCards += deck->cards()[ 0 ];
+        if ( !pile->cards().isEmpty() && pile->cards().count() % 3 != 0 ) {
+            kdDebug( 1111 ) << "Found last card "<< pile->cards()[pile->cards().count() - 1]->name()<< endl;
+            srcPileCards += pile->cards()[ pile->cards().count() - 1 ];
         }
     }


Comment 6 Daniel Frein 2007-03-13 15:08:46 UTC
There still exist cases where kpat incorrectly reports an "klondike (draw 3)" game as unwinnable; game 809385859 demonstrates this bug (e.g. via demo mode) in kpat-2.2.2/KDE-3.5.5. (In addition, kpat most of the time fails to detect if a game is really insoluble, but that doesn't bother me).
Comment 7 Stephan Kulow 2007-03-13 15:14:17 UTC
it has been changed completly for KDE4 and I won't touch this KDE3 hack. Sorry, just continue
Comment 8 Daniel Frein 2007-03-13 15:45:41 UTC
Of cause, these are good news. Thank you very much (and the other authors as well).