Time for another (Klondike) Solitaire submission! 264 frames (~4.5 seconds) faster than the published run on the same layout. I'm tired of not submitting stuff.
  • Music ON
  • Aims for fastest completion of one game (same layout as in mmbossman's run).
  • Plays at hardest level (3 card draw).
Version: FCEUX v2.1.4a.
Note that it works on both ROMS, so don't worry about the checksum.
If music is turned off, it saves like 3.5 seconds since it doesn't play the jingle at the beginning. But you wouldn't be able to get this layout, so who knows? I leave it on, because having the music off is never good.
It is entirely possible that the hardest level (3 card draw) is faster than 1 card draw, since you need less flips to get to where you want.

About the run

Well, I started out by disassembling the RNG in this game. Difficult, but it didn't take me more than 3 days. Details on that later.
So I decided to take a "break" (relatively speaking) and improve the published run.
Just as in the previous run, holding start at the beginning glitches out the intro. Since I had a frame to burn (just like mmbossman), I used it to change the card back image. Alternatively, I had the option to change the color, but decided against it since seeing blue "red" cards flying around is a rather alien concept. Also, nothing beats actual red. Except maybe purple or pink.
First, I looked for a sequence of play that reduces downtime (e.g. transferring large stacks takes a lot of time). Once I had that, I did it again and optimized movement. Some methods include the following:
  • You can press A at the same time as one or more direction keys to select a card.
  • You can press diagonals (e.g. up+left) and the cursor will go diagonally.
  • When going from one side to the other, it is faster to go through the very top row (with the deck and home slots), rather than the second row. Just the way the cursor works.
  • Often when transferring cards, it is faster to alternate left-right and right-left actions, if possible.
  • Near the end, it is faster to work off the part of the deck nearest the beginning (the first three cards on the flip after restoring the deck), since otherwise it takes a bit more time.

About the layout

Although the layout has a lot of cards that can easily be played, there are some undesirable things such has having both red jacks and both black sixes hidden in the upper right section of the pile. Furthermore, there is a black ten on top of one of the jacks. As anyone who plays Klondike Solitaire can tell you, this is not a good thing, as it severely restricts your options (indeed, playing the other black ten on the red jack that is not covered by the first black ten will pretty much ruin your game).
Is there a better layout that can make this faster? Possibly. But I haven't tried.

Possible improvements

Aside from a better layout, there might have been a strategy on the original layout that I missed.

Screenshots

Disassembly

Here's how the initial deck is determined:
  1. The initial deck is determined from address 0006-0007, which is two bytes (16-bit) and little-endian. This "RNG" is merely a counter that advances by 1 every frame.
  2. When the deck is to be generated (in this run, when address 0006 = 0x180), start with an empty 52-cell array and do the following.
  3. 16-bit-multiply address 0006-0007 by 0x28.
  4. Then add 0xE39. Then subtract 0x2D9.
  5. Look at this new 16-bit value. If the upper byte is between 0x03 and 0x82 inclusive, or the lower byte is greater or equal to 0xDA, or less or equal to 0x59, subtract 0x2D9 and repeat this step. Otherwise, continue.
  6. Take the low byte and mod it by the number of currently empty cells in the array (first time is 52, second is 51, ...). Call this number i. Starting from the end of the array (52nd cell), take the (i+1)th empty cell from the end (e.g. if i=0, take the first empty cell), skipping over any filled cells. Fill the (i+1)th empty cell so it is no longer empty, and the index of that cell (i.e. if it is the jth cell of the array, the index is j) is the value of the last card. Next time through is the second last card, then the third last card, etc.
  7. Take the last 16-bit number produced in step 5. 16-bit-multiply it with 0x28.
  8. Go back to step 4 until all cells in the array are filled (this determines the whole 52-card deck)
The values (1-52) of the cards correspond as follows, hearts are 1-13, diamonds 14-26, clubs 27-39, spades 40-52, and the ranks are A,2,3,... are in increasing order with A as 1/14/27/40 (depending on suit), 2 as 2/15/28/41, and so on.
Note that the game stores the deck differently, however. First of all, the values are from 0 to 51 (just subtract one). The card order (this applies only after the deck appears but before any cards are dealt), starting at address 03DD and going on for 52 bytes, is implemented similar to that of a linked list. That is, the current value in the array tells you the position in the array whose next number is the next value. A slight issue occurs with the very first value; it is actually in 0x39C, since its otherwise normal spot is taken up by the end-of-deck marker 0xFF.
Here's a C++ file that shows the exact process, and a FCEUX Lua script that takes an existing position and shows a representation of the board (must be run after the deck appears but before any cards are dealt to the piles).

Thanks

Thanks to mmbossman for the published run.

Mukki: Judging...
Mukki: Accepting as an improvement to the currently published run.
fsvgm777: Processing...
I fixed the ROM filename as well.


TASVideoAgent
They/Them
Moderator
Joined: 8/3/2004
Posts: 15628
Location: 127.0.0.1
This topic is for the purpose of discussing #3303: FractalFusion's NES Solitaire in 00:42.80
Joined: 12/22/2009
Posts: 291
Location: Michigan
Sexiness. It'd be interesting to see that lua that adelikat was talking about actually come full circle. Encoding.
Current projects: Yoshi's Island Disassembly Yoshi's Island any% TAS with Carl Sagan
Active player (451)
Joined: 3/21/2011
Posts: 127
Location: Virginia (United States)
Pretty cool run. Just a question, how hard is it to actually manipulate this?
YouTube Channel - Twitter Current projects: Sutte Hakkun, Hyper VI, RTDL, own hacking projects
Joined: 12/22/2009
Posts: 291
Location: Michigan
HD encode is done: Link to video
Current projects: Yoshi's Island Disassembly Yoshi's Island any% TAS with Carl Sagan
Joined: 6/4/2009
Posts: 570
Location: 33°07'41"S, 160°42'04"W
Definite yes vote. This is incredibly optimised.
Editor, Experienced player (860)
Joined: 8/12/2008
Posts: 845
Location: Québec, Canada
Yup, really enjoyed this one. Your TASes never cease to impress me, Fractal. Great work!
Editor, Experienced player (570)
Joined: 11/8/2010
Posts: 4038
This is an epic improvement. Nice job! Yes vote.
Player (118)
Joined: 5/13/2009
Posts: 700
Location: suffern, ny
This is cool! I really like this run. Fun Fact: A lot of people speculate that Napoleon invented Klondike Solitaire while he was in isolation.
[19:16] <scrimpy> silly portuguese [19:16] <scrimpy> it's like spanish, only less cool
Jungon
He/Him
Player (51)
Joined: 4/2/2009
Posts: 376
Location: Porto Alegre - Brazil
This is technically good, and really well played, just... I don't know if I'll be rewatching it a lot, and the entertainment wasn't really great, ... but it's enough for a Yes vote.. +D
*Jungon*/*Johnnyz* smilie weirdo =P ^^ o.o @__@ +D
mklip2001
He/Him
Editor
Joined: 6/23/2009
Posts: 2227
Location: Georgia, USA
This isn't really all that entertaining, but an improvement is an improvement. Nice work dissecting the RNG. And on the plus side, I think we can get another screenshot involving some queen stroking.
Used to be a frequent submissions commenter. My new computer has had some issues running emulators, so I've been here more sporadically. Still haven't gotten around to actually TASing yet... I was going to improve Kid Dracula for GB. It seems I was beaten to it, though, with a recent awesome run by Hetfield90 and StarvinStruthers. (http://tasvideos.org/2928M.html.) Thanks to goofydylan8 for running Gargoyle's Quest 2 because I mentioned the game! (http://tasvideos.org/2001M.html) Thanks to feos and MESHUGGAH for taking up runs of Duck Tales 2 because of my old signature! Thanks also to Samsara for finishing a Treasure Master run. From the submission comments:
Shoutouts and thanks to mklip2001 for arguably being the nicest and most supportive person on the forums.
Warepire
He/Him
Editor
Joined: 3/2/2010
Posts: 2178
Location: A little to the left of nowhere (Sweden)
While this has absolutely no entertainment value whatsoever it's a really nice TAS from a technical view. Also it beats the previous publication of this game. Yes vote.
Dwedit
He/Him
Joined: 3/24/2006
Posts: 692
Location: Chicago
Was this game done by the guy who made Dudes With Attitudes/Trolls on Treasure Island?
Joined: 2/6/2011
Posts: 130
Look at the rack of the Q <3 card, oh yeah, yes vote... because of the techincal value I mean
Experienced player (829)
Joined: 11/18/2006
Posts: 2426
Location: Back where I belong
Very nice! It's great to see some love for this, after 3+ years. Great job Fractal! EDIT: Worst published movie, imo. ;)
Living Well Is The Best Revenge My Personal Page
Joined: 1/8/2011
Posts: 74
Location: Saturn Valley Medical Center
Nice job. I play solitaire a lot so I'm pretty sure that this must have taken much planning. Yes vote.
Samus plays the SA-Xaphone
Editor, Expert player (2080)
Joined: 6/15/2005
Posts: 3284
kaizoman666 wrote:
Pretty cool run. Just a question, how hard is it to actually manipulate this?
Well, I didn't really do any luck manipulation. Just trying to improve the layout that mmbossman used. It took me a while and a lot of thinking, but nothing too much.
Post subject: Movie published
TASVideoAgent
They/Them
Moderator
Joined: 8/3/2004
Posts: 15628
Location: 127.0.0.1
This movie has been published. The posts before this message apply to the submission, and posts after this message apply to the published movie. ---- [1884] NES Solitaire by FractalFusion in 00:42.80
Editor, Expert player (2080)
Joined: 6/15/2005
Posts: 3284
Interesting note: Even though the game randomizes the deal using a 2-byte value (65536 values), there are only 994 distinct deals in this game, thanks to the bad randomization procedure. However, as I found out, the search space for even one deal is massively huge. After all, "solving" Klondike Solitaire is a study subject in the realm of the highest experts of computational mathematics. This after I made a Solitaire program in an attempt to search the space. At least I learned something new. I'll think about what my goal should be now, if I try to find a faster TAS.
Joined: 2/7/2008
Posts: 185
It took me a long time to work out what was going on with the Q of D. (Hands together like a prayer looked to me like some cleavage or hands behind her or something...) Not exciting but fun to watch while it lasts and another great example of the level of optimisation that could only be TASd. Very impressive. Nice work.
I'm just some random guy. Don't let my words get you riled - I have my opinions but they're only mine.