Udostępnij za pośrednictwem


Finally (some) piece of mind with My Pocket Solitaire

This post continues My Pocket Solitaire series.

Previously I have been writing about My Pocket Solitaire and how it has been coming back to me several times over the years. But finally some time ago I published new version of My Pocket Solitaire to Store (application requires Windows 10) which includes two features which have given me (some) piece of mind after the release Smiley:

  • See how many solutions are still available
  • Navigate between the solutions

I'll show what I mean by those features. First let's take a look at the start up position:
Start of Game

Immediately you will see from the top that how many solutions are still available from the start position. That gets updated automatically when you make moves:
First move

Also you can see that certain positions are highlighted with white rectangle. Those indicate that "this move will lead to solution". This allows quite easy navigation between different solutions. Of course it's now quite easy to play the game and get to the winning state:
End state of game

Technical solution

How was this achieved then? Originally I was thinking to embed those solutions into the application package. That would have of course made the application package quite big and that wasn't what I wanted. So I started to look for alternative solutions.

I could of course create Web App into Azure which could provide these solutions to client. But then I thought that it would be a bit too much this time. Because this time I wanted "serverless" backend Smiley.

Therefore I came up with the solution to put the game solution data to the Azure Blob Storage and address then directly from client using "known urls". After all I knew in the client how many moves player has done (I call this "level") and each board state can be identified with unique identifier. Combining these two I have way to create "fixed" urls which point into Blob Storage. And when I set the data to be "public" I can directly address those blobs from any client. This means that I have single file in Blob Storage for each board combination which leads to solutions. Board position which doesn't lead to solution would be 404 (Not found) and that is handled in the client as "does not lead to solution".

In order to push these solutions to the Blob Storage I created simple .NET Application which pushed the data into Azure. And in Client it was easy to create fixed url HTTP requests and receive solutions counts from storage. Retrieving single board state is quite fast so user interface updates actually quite nicely. I also cache retrieved solutions for the duration of the gaming session so it's fast to navigate the sames moves again and again.

End results is quite nice user interface with minimal maintenance on the backend. Exactly what I wanted Smiley!

Anyways... Happy hacking!

BR,

J