The Answer is 51!

This is definitely a Frequently Asked Question.

In the Goodsol Solitaire Forum, there is a question that keeps coming up; in fact, some people ask it in the very same forum thread in which I have already answered it comprehensively. Instead of repeating myself, I am posting it here for ease of linking and because some readers may find it interesting. (I have always enjoyed this kind of mental exercise, even if I have had less time for it recently.)

The question is:

What is the fewer number of moves to win a game of Spider Solitaire?

Here is the answer:

51

The explanation (from the forum):

The lowest move count would be fewer than 101 moves, and one could probably construct a deal which demonstrates this. The chances of actually winning a game of Spider in Pretty Good Solitaire in fewer moves is almost impossibly low, however.

The base calculation is actually fairly simple: Normally, each card lower than a king, of which there are 96, needs to be moved at least once, and there are five extra moves needed to get all of the cards from the stock. This gives a total of 101 moves.

However, each of the moves from the stock could produce a sequence in one or more columns, so the above number could be reduced by as many as 10 moves each, if the cards line up perfectly. That would give a theoretical lowest limit of 51 moves, and it could be a challenge to create a deal by hand that would work (although I believe that it is definitely possible).

Now, the practical proof (a forum followup):

Anyway, as an intellectual challenge, I actually constructed (stacked) a deck for Spider that produces a game that can be solved in only 51 moves. Not only that, but every move is obvious and no legal move is left unmade. (In other words, it plays perfectly naturally.)

Without further ado…

Starting at the top of the deck (comprised of 2 packs, 104 cards):

(tableau)
KS KH 9H 5H KD 9D 5D KC 9C 5C
KC JC 8C 4D 5C QS 2D 9S 6S 3C
KD QD TD 9D 8D 7D 6D 9S 8S 7S
JD QH 9H 6H 3H KS QS 6S 5S 4S
KH TH 7H 4H AH JS TS 3S 2S AS
JH 8H 5H 2H

(stock)
5D TC 7C 3D 4C JS AD 8S 5S 2C
QC 9C 6C 4H AC TS 4D 7S 4S 4C
3S QH 8H 3H QD 8D 3D QC 8C 3C
2S JH 7H 2H JC 7D 2D JC 7C 2C
AS TH 6H AH TD 6D AD TC 6C AC

If one starts with this deck, the game can and will be solved in only 51 moves.

Enjoy!

2007 NCAA Men's Hockey Champions!

The Spartans won it all this year.

Michigan State University beat the Eagles of Boston College this evening to win the NCAA Men’s Hockey Championship. The Spartans played a very exciting game to come from behind and win. There were no goals in the first period, only the third time in history for a 0-0 score at the first intermission in a championship game. BC took a 1-0 lead over MSU in the second period, which held through the second intermission. Again, this was just the third time for a championship game to have only a single goal by the second break. The teams were very evenly matched, even if the ESPN commentators refused to acknowledge it.

In the middle of the third period, MSU won a face off in the neutral zone and their top scorer, Tim Kennedy, simply drove straight in and scored with a beautiful shot to the side of the net to tie the game at 1. At that time, I predicted a 3-1 win for Michigan State, with the final goal scored on an empty net. The pace of the game picked up and, amazingly, with 18.9 seconds left, Justin Abdelkader put in the game winner (off a beautiful assist from Kennedy). Boston College came out with an empty net and after a few tense seconds, the puck was cleared to Spartan Chris Mueller who put in an insurance goal with 1.2 seconds on the clock. The celebration started and the Eagle’s coach, in a classy act, had the officials run the remaining time off and sound the final horn.

Final score: Michigan State 3, Boston College 1.

We saw a few familiar faces on TV celebrating in the crowd in St. Louis, including a close/direct shot of a friend. The best part of the post-game festivities, though, was the interview with the MSU goalkeeper, Jeff Lerg, who said he knew they could win it, “if I made every save I was supposed to make, plus added two or three more big ones.” The biggest disappointment was that MSU won its 3rd National Championship in Hockey, 21 years after the previous one (1986), on a weekend when most students were home for Easter, so downtown East Lansing had no fan gathering. (The snow and 24 degree temperature did not help.)

I will always remember the date of this victory for MSU, as it comes on my son’s 18th birthday. Happy Birthday, James!

NCAA Frozen Four Semifinals

What a game!

I took a short-ish break from development this afternoon to watch the first semifinal game of the NCAA Frozen Four (Div I), the National Championship in men’s college hockey. As much as I like watching college hockey, I only made time because the Michigan State University Spartans were in this game against the Black Bears of Maine.

Unfortunately, Maine scored only 27 seconds into the game, and then they scored again less than 3 minutes later to take a 2-0 lead in the fourth minute. Fortunately, MSU shut them out for the remaining 56 minutes (and 36 seconds) while scoring 4 goals of its own. It was an excellent and exciting game for the duration and, thanks to TiVo, I was able to watch it in less than real time, omitting the inane chatter and repetition during the two intermissions. Final score: Michigan State 4, Maine 2.

It looks like now I will have to take another break from the crunch on Saturday at 7:00pm (ESPN) for the NCAA National Championship game for Men’s Ice Hockey. One team will be Michigan State, and the other will be either North Dakota or Boston College, depending on the second semifinal (to start within the hour); either way, I know who I will be cheering for.

Development Paradox

This is a contradiction within management of game development.

I have been engrossed in a frenzy of game programming lately. (Note that “engrossed” is just another way of saying “crunch mode” that I willingly accepted.) Despite managing myself, I am struggling with an issue that affects the development of many games and applications, a contradiction in goals.

On the one hand, good development management practice suggests that one deal with the unknowns early in the process. These unknowns, tasks which are the most difficult to estimate correctly, especially those involving partial information, have a natural tendency to be the longer (and often more tedious) tasks to complete. Another important goal is to get the fundamental foundation of the project (e.g., libraries and elemental routines) as solid and complete, and tested, as possible.

On the other hand, unless one is totally isolated and/or committed, it is important to be able to show tangible progress on a project in terms of visuals or notable features (or perhaps of number of tasks completed). Even if one is completely on his own, it helps morale and provides motivation to get a measurable degree of advancement, rather than updating “50% done” to “90% done” (especially since most such numbers are completely arbitrary anyway).

My current major project has many unknowns (due to the new platform), and loads of opportunities for choosing between minimal implementation of a base class, merely to support a specific task, and a complete and proper implementation, with testing, to handle all anticipated needs. Specifically, when porting a solid library of routines from Windows, I have the choice whether or not to port routines that may not be used in this particular game, but will definitely be needed down the road.

The approach that I have been taking is… well, I will just leave this as an enigma for now.

(As this post runs from “paradox” to “enigma”, I must end with a decisive quote.)

War! What is it good for? Absolutely NOTHING!
… War can’t give life; it can only take it away.
— Edwin Starr

Formula One 2007

I am excited for the start of a new season of F1 racing.

Tonight (a.k.a., tomorrow morning, Australian time), the first round of practice for the Australian Grand Prix gets underway in Melbourne. This is the first race of the 2007 season for Formula One, after about five months without direct competition. There are lots of changes that could make this a very interesting year.

I could write pages about the upcoming season, but in order to get enough work done before the race starts, I will stick to the main headlines. After 16 seasons, seven-time World Champion Michael Schumacher has retired. Reigning back-to-back World Champion Fernando Alonzo moved from Renault to McLaren, replacing Kimi Raikkonen, who is now at Ferrari with Felipe Massa, fastest in winter testing. American Scott Speed finally regained his ride at Toro Rosso and, in his only test, went faster than the more experienced drivers at their lead team, Red Bull. (Note: Scuderia Toro Rosso means Team Red Bull in Italian.) All teams are on the same tires this year, and each is required to use both available tire compounds during the race, which could lead to both more strategy and more passing.

One of the most interesting stories is the rookie class this year. Lewis Hamilton, 2006 GP2 Champion, and Heikki Kovalainen, 2006 F1 test driver and 2005 GP2 series runner-up, are both going to top teams (McLaren and Renault, respectively), while the highly rated German driver, Adrian Sutil, will be at Spyker. Sutil will have a chance to shine if he can wring extraordinary performance out of his car, which is expected to be toward the rear of the field. Kovalainen is the first Finnish driver with a perceptible personality and could outshine (or at least pressure) his much more experienced teammate. Hamilton is an impressive driver, in one of the top two teams, paired with the reigning F1 World Champion, and he stands an excellent chance of winning in his rookie season. (This Brit also happens to be the first black driver in F1, so if he performs well, expect lots of comparisons with Tiger Woods.)

So what does all of this have to with game development? In the official McLaren preview of the Australian Grand Prix, the following quote is attributed to Lewis Hamilton (in the first paragraph):

My brother and I have always been playing Formula 1 games on the computer, and now I am going to be one of the cars in those games!

Very cool, indeed.

New development platform

I have had a beneficial break from Windows lately.

Over the past few weeks, our development efforts have shifted toward a new platform, and I have to admit that I have been enjoying the relatively Vista-free existence. Being less accustomed to the new tools and libraries, there is more for me to learn. Ironically, though, it feels like I am being more productive, due to actually writing original code that is not (and cannot be) copied from other projects. Of course, there is plenty of porting, too, but the system independent stuff actually works with minimal modification.

During the month or so prior to this change, my days were spent doing lots of quality assurance on pieces of code for Windows Vista and then applying the tested alterations to each of our shipping products. The one new product was a replacement for a piece of software (from another company) that broke under Vista and was not expected to be updated. It was fulfilling to get each of those products completed and out the door, but I had also gotten my fill of dealing with Vista idiosyncrasies.

All of my primary communication software (and most of my development tools) are on Windows, but when programming for [the new platform], I do not need to use Windows at all. Last week, I only modified three (!) files on my main development hard drive (making backup almost pointless). On the other hand, I am also physically separated from my email, newsgroups (including the ASP and AISIP), and preferred browser. This means that I can be more productive in terms of programming, but at the cost of being more disconnected. This is why the frequency of blog posts here has fallen (and will stay depressed for a while).

As I started writing this, I realized that my two primary associations with the word “vista” are “horizon” and “sunset“. I guess that what Microsoft is subtly indicating is that Vista heralds the sunset of Windows dominance and we should now be looking for new horizons. I am there.

QB Grand Championship

This entire post is a spoiler; do not read it.

QuizBusters in NeonThe week before last, my son, James, played in the Green Division Championship for QuizBusters. He was one of four players competing for East Lansing High School, the #1 seed in the tournament, and their opponents were from Hartland High School, which was (unsurprisingly) the #2 seed. It definitely looked like this would be the strongest team they had faced yet, and this turned out to be true.

In the initial, ‘Quick 10‘, round of the game, it looked like East Lansing could be on their way to another rout, taking nine of the ten questions and jumping to a 90-10 lead right away. However, that was misleading, as Hartland started a comeback with the ‘Toss Up‘ questions, during which James answered a tough question (“The 16th Amendment”) but his team uncharacteristically failed to get the first bonus question (about The Will Rogers Follies on Broadway), earning only 10 of a possible 50 points. After the first ‘Pop Quiz‘ round, the score was tied at 170, and we were getting nervous.

Fortunately, East Lansing finally hit their stride and managed to earn some sweeps, taking the next 170 points to double Hartland’s score, and from there the game never got close again. East Lansing won the Championship by a final score of 540-290, which was the closest game all season. In fact, East Lansing did not have twice Hartland’s final score, and this was the only QB game this season where they did not at least triple the opponent. The victory came complete with $5000 scholarship offers from Michigan State University, where James has already been accepted. Nice.

This past week, East Lansing faced the White Division Champions, Kent City, in the QuizBusters Grand Championship. Watching the weekly games on television, it is clear that the Green Division teams, from the bigger schools, tend to be better than the White Division teams. This game played out to form, and it really was not much of a game, East Lansing winning 530-90. However, they did complete one of their side goals for the season, sweeping all ten of the ‘Quick 10’ questions (to take an initial 100-0 lead). Of course, winning the game also added a one year book scholarship for each player, so that will help James even more.

For those interested in watching the games, the Division Quarterfinals, versus Okemos, will be aired on April 1st (no fooling), the Division Semifinals, versus Howell, will air on April 29th, the Green Division Championship will show May 13th, and finally, the Grand Championship will be shown on May 20th. All of the games are (reputedly) viewable online after they air on WKAR, and the web site also lists the full broadcast schedule for all games.

Grand ChampionsThe varsity QuizBusters team before the Division Championship.

East Lansing The East Lansing team celebrates the Grand Championship.

Vista gotchas

Watch out for some programming issues in Vista.

Now that I have Windows Vista installed and running, albeit only as a test platform, I have discovered some programming pitfalls that are not among the major issues reported. So, as a service to my readers, here are two unexpected issues that my affect the operation of some programs under Vista.

First, the standard C function, tmpfile(), does not function correctly in the more restrictive LUA (Limited User Account) of Vista, nor probably of XP. The tmpfile() function is (supposed to be) a portable routine for creating a temporary file. Unfortunately, the Visual C++ 6 implementation (at least) attempts to create the file in the program directory, to which a program no longer has write access, as opposed to a temporary directory elsewhere. The result is, simply, that the function fails. Honestly, this is not a very common function in most code, but this problem does affect some cross-platform libraries, such as certain builds of the (commonly used) JPEG library from the Independent JPEG Group, rendering some (but not all) JPEG files unreadable.

The other undocumented issue is with the Win32 API function, ShellExecute(), which is commonly used (and the recommended way) to launch document and executable files, including external web pages, from within another program. The behavior of the Vista implementation of ShellExecute() does not match that of Windows XP or earlier versions of Windows, in that it no longer recognizes a slash (/) as a directory separator. In other words, attempting to launch a file named “game/setup.exe” will work in XP and fail in Vista, whereas “game\setup.exe” (or, rather, “game\\setup.exe”, as a C string constant) will function correctly in both situations. Of course, the obvious workaround is to simply replace slashes with backslashes, but that does not help the applications that are already shipped and installed, and now broken by Vista.

I will acknowledge that this sort of problem creeps in with any operating system change by pointing out that I recently found a nice crash bug in Windows 98. If you create a dialog box with no controls, intended as a container, and then explicitly create a control with the dialog box as a parent (i.e., add a control), the program will crash in USER32 as soon the dialog box is displayed. The workaround is simply to add a hidden control to the container dialog box template, but trying to figure out why a simple call to ShowWindow() would crash a program is more than a little frustrating.

Now you all know how I spent the last couple of weeks.

Need for video games

New research provides evidence for what we already knew.

A recent article by Reuters, Video game playing may fulfill innate human need, gives some conclusions from research into the positive effects of video games, or more specifically into what makes game play compelling. This research is somewhat unusual in that it does not start with the intent to study game violence (nor the goal to prove a negative impact of games). The research was conducted by Immersyve, a “virtual environment think tank”, in collaboration with the University of Rochester (home of the “Nipple of Knowledge”).

The research, or at least the limited information available online, suggests that games can fulfill basic needs in a meaningful way, and that those games which do so “predict better psychological outcomes for players” as well as “commercial success for games.” This is one point that I made (albeit without research citations at hand) when testifying before a committee of the Michigan Senate a couple of years ago. The gist of the results, obviously, is that players who have their needs met by a game will tend to continue to play and enjoy that game, whereas players will move on from games will do not fulfill such needs as well.

Personally, I have some clear ideas about what kinds of game experiences produce psychological well-being, and I will be interested to see how my perceptions match with the research results, as well as whether there are different types of game players who respond innately to different stimuli.

Pretty Good MahJongg 2.32

This is our fourth product release in 2007.

Yesterday, Goodsol Development released Pretty Good MahJongg 2.32, an update to our unique tile solitaire game. This product contains not only traditional tile matching, with 280 different layouts (plus a layout editor), but also includes 55 different solitaire and puzzle games played with mahjongg tiles, most of which are original and exclusive to this product. One can download a 30-day trial version here.

This version of Pretty Good MahJongg, as with all of our recent release updates, provides better compatibility with Windows Vista, including a nice new program icon. Admittedly, this is the smallest of the updates, since we had already released an update back in November (2006) which added HTML Help to this title. In fact, that was the reason that we shipped the other updates (Pretty Good Solitaire 11.0.1, Action Solitaire 1.12, and Most Popular Solitaire 1.12) before this one.

One wonderful thing about our industry, and in particular, the virtual working environment, is that it is not as susceptible to certain types of business interruption (as long as ones internet connection remains functional). This release (as well as final build and testing) was published while Springfield was buried in snow. It was not substantially delayed by a driveway in need of shoveling nor by the tons of snow on the ground outside. Meanwhile, here in East Lansing, we have had relatively little snow, but we have not been forced to venture out into the very cold temperatures recently.

Anyway, this release completes all the Windows Vista updates for our major titles (though Thomas Warfield will still be updating his “Wizard” products that use the same library that we wrote for Pretty Good Solitaire). However, we still have an aggressive release schedule planned, and the fifth release is already in alpha testing. We currently have playable prototypes for the next two Goodsol titles, one needing some polish before beta testing, and the other awaiting artwork and requiring additional games to be implemented.

Everything looks positive, except this cold…