<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>Jesper Niedermann's .NET Blog - Games &amp; Puzzles</title>
    <link>http://www.niedermann.dk/</link>
    <description>about .NET and related technologies</description>
    <language>en-us</language>
    <copyright>Jesper Niedermann</copyright>
    <lastBuildDate>Fri, 13 Nov 2009 23:11:29 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.2.8279.16125</generator>
    <managingEditor>jesper@niedermann.dk</managingEditor>
    <webMaster>jesper@niedermann.dk</webMaster>
    <item>
      <trackback:ping>http://www.niedermann.dk/Trackback.aspx?guid=d70452c9-013d-49b4-82cc-b5290ae51893</trackback:ping>
      <pingback:server>http://www.niedermann.dk/pingback.aspx</pingback:server>
      <pingback:target>http://www.niedermann.dk/PermaLink,guid,d70452c9-013d-49b4-82cc-b5290ae51893.aspx</pingback:target>
      <dc:creator>Jesper Niedermann</dc:creator>
      <wfw:comment>http://www.niedermann.dk/CommentView,guid,d70452c9-013d-49b4-82cc-b5290ae51893.aspx</wfw:comment>
      <wfw:commentRss>http://www.niedermann.dk/SyndicationService.asmx/GetEntryCommentsRss?guid=d70452c9-013d-49b4-82cc-b5290ae51893</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I am currently developing the game Klimakonflikt with 5 other guys. It is a Retro
arcade game, Pac-man style, with nice 2D Graphics and music. Here is a screenshot
from the game:
</p>
        <p>
          <a href="http://www.niedermann.dk/content/binary/WindowsLiveWriter/RetroXNAGameKlimakonfliktunderdevelopmen_1B4/klimakonflikt_screenshot_4.png">
            <img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="klimakonflikt_screenshot" border="0" alt="klimakonflikt_screenshot" src="http://www.niedermann.dk/content/binary/WindowsLiveWriter/RetroXNAGameKlimakonfliktunderdevelopmen_1B4/klimakonflikt_screenshot_thumb_1.png" width="415" height="295" />
          </a>
        </p>
        <p>
The current release, documentation and source code can be downloaded from here <a href="http://klimakonflikt.codeplex.com" target="_blank">http://klimakonflikt.codeplex.com</a> 
</p>
        <p>
The game is inherently for 2 players but we are working on the single player edition.
The AI in the current release is pretty daft, but in the next release it will be much
improved. Also we are working on a WPF leveleditor, powerups and other fun stuff.
</p>
        <p>
One of my co-developers Jakob has released a blog about the game and XNA development
in general at <a href="http://xnafan.net" target="_blank">http://xnafan.net</a></p>
        <img width="0" height="0" src="http://www.niedermann.dk/aggbug.ashx?id=d70452c9-013d-49b4-82cc-b5290ae51893" />
      </body>
      <title>Retro XNA Game Klimakonflikt under development</title>
      <guid isPermaLink="false">http://www.niedermann.dk/PermaLink,guid,d70452c9-013d-49b4-82cc-b5290ae51893.aspx</guid>
      <link>http://www.niedermann.dk/2009/11/13/RetroXNAGameKlimakonfliktUnderDevelopment.aspx</link>
      <pubDate>Fri, 13 Nov 2009 23:11:29 GMT</pubDate>
      <description>&lt;p&gt;
I am currently developing the game Klimakonflikt with 5 other guys. It is a Retro
arcade game, Pac-man style, with nice 2D Graphics and music. Here is a screenshot
from the game:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.niedermann.dk/content/binary/WindowsLiveWriter/RetroXNAGameKlimakonfliktunderdevelopmen_1B4/klimakonflikt_screenshot_4.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="klimakonflikt_screenshot" border="0" alt="klimakonflikt_screenshot" src="http://www.niedermann.dk/content/binary/WindowsLiveWriter/RetroXNAGameKlimakonfliktunderdevelopmen_1B4/klimakonflikt_screenshot_thumb_1.png" width="415" height="295"&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
The current release, documentation and source code can be downloaded from here &lt;a href="http://klimakonflikt.codeplex.com" target="_blank"&gt;http://klimakonflikt.codeplex.com&lt;/a&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
The game is inherently for 2 players but we are working on the single player edition.
The AI in the current release is pretty daft, but in the next release it will be much
improved. Also we are working on a WPF leveleditor, powerups and other fun stuff.
&lt;/p&gt;
&lt;p&gt;
One of my co-developers Jakob has released a blog about the game and XNA development
in general at &lt;a href="http://xnafan.net" target="_blank"&gt;http://xnafan.net&lt;/a&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.niedermann.dk/aggbug.ashx?id=d70452c9-013d-49b4-82cc-b5290ae51893" /&gt;</description>
      <comments>http://www.niedermann.dk/CommentView,guid,d70452c9-013d-49b4-82cc-b5290ae51893.aspx</comments>
      <category>.NET</category>
      <category>Games &amp; Puzzles</category>
      <category>WPF</category>
      <category>XNA</category>
    </item>
    <item>
      <trackback:ping>http://www.niedermann.dk/Trackback.aspx?guid=e0b4bd51-4730-4be3-a518-cd95a234e1d0</trackback:ping>
      <pingback:server>http://www.niedermann.dk/pingback.aspx</pingback:server>
      <pingback:target>http://www.niedermann.dk/PermaLink,guid,e0b4bd51-4730-4be3-a518-cd95a234e1d0.aspx</pingback:target>
      <dc:creator>Jesper Niedermann</dc:creator>
      <wfw:comment>http://www.niedermann.dk/CommentView,guid,e0b4bd51-4730-4be3-a518-cd95a234e1d0.aspx</wfw:comment>
      <wfw:commentRss>http://www.niedermann.dk/SyndicationService.asmx/GetEntryCommentsRss?guid=e0b4bd51-4730-4be3-a518-cd95a234e1d0</wfw:commentRss>
      <slash:comments>5</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I must admit that I have never understood why it was fun to solve Sudoku's. But as
a programmer I was fascinated with the idea of making the perfect Sudoku puzzle generator
algorithm from the very first time I heard of Sudoku. Of course I wanted to make it
so general that it could not only make the boring old 9x9 sudoku. But sodukus of any
size 4x4, 9x9, 16x16, 25x25 and so on...
</p>
        <p>
This resulted in a .NET 1.1 WinForms program 4-5 years ago in which I could randomly
generate all sudoku combinations from 4x4 to 36x36. I created an algorithm that started
in the upper left corner and put in a random number then moving to the next square
put in a new random number from the remaining numbers. This meant that the algorithm
had to backtrack when coming to a deadend where no number was valid. This approach
guaranteed that all possible Sudokus could be generated, but it was extremely slow.
Well for 9x9 sudokus it was less than a second but for 36x36 sudokus it was around
16 hours :O)
</p>
        <p>
A few weeks ago I thought it was time to try out <a href="http://silverlight.net" target="_blank">Silverlight</a> and
make a small program to test Microsofts "new" programming platform, but I had to come
up with an idea for a small program. And for some reason Sudoku popped up again.
</p>
        <p>
And I came up with a novel idea for an extremely fast generator (try it <a href="http://www.niedermann.dk/Sudoku/Sudoku.aspx" target="_blank">here</a>).
It has been said that no ideas are new anymore and I am pretty sure that I am not
the first to think of this since the algorithm is pretty obvious. I start with a valid
Sudoku as a template and then apply transformations of the columns, the rows and the
numbers themselves. 
</p>
        <p>
To generate a valid Sudoku I first generate the template. The template is generated
by starting with 1 in the upper left corner and then counting upwards. Next I go to
the 4th row and start in the second column counting from 1 again like this:
</p>
        <p>
          <a href="http://www.niedermann.dk/content/binary/WindowsLiveWriter/ExtremelyfastSudokusofanysizeprogrammedi_1092B/s1.jpg">
            <img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="244" alt="s1" src="http://www.niedermann.dk/content/binary/WindowsLiveWriter/ExtremelyfastSudokusofanysizeprogrammedi_1092B/s1_thumb.jpg" width="243" border="0" />
          </a>
        </p>
        <p>
Next I go to the 7th row and the 3rd columm and so on. So I add 3 rows (the square
root of 9) each time. In a 16x16 sudoku I add 4 rows each time. The final template
is generated in a few milliseconds even in a 400x400 Sudoku. The final template for
a 9x9 sudoku looks like this:
</p>
        <p>
          <a href="http://www.niedermann.dk/content/binary/WindowsLiveWriter/ExtremelyfastSudokusofanysizeprogrammedi_1092B/s2.jpg">
            <img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="244" alt="s2" src="http://www.niedermann.dk/content/binary/WindowsLiveWriter/ExtremelyfastSudokusofanysizeprogrammedi_1092B/s2_thumb.jpg" width="217" border="0" />
          </a>
        </p>
        <p>
The template is itself a valid Sudoku.
</p>
        <p>
Now I make the transformation using an observation I have made. In any valid Sudoku
I can make another valid Sudoku by switching the columns within each block of 3 columns.
As indicated in red colour for the first block above.
</p>
        <p>
Secondly I can do the same for the rows.
</p>
        <p>
And last I can transform the numbers themselves so that all 1's are transformed to
a number from 1 to 9. all 2's are transformed to one of the remaining 8 numbers and
so on.
</p>
        <p>
I could also have applied a 4th transformation  that switched the big blocks
as columns and rows, but I don't think that it will add much value.
</p>
        <p>
In all this the entire puzzle can be generated in milliseconds for even extremely
big Sudokus.
</p>
        <p>
Try it out yourself at <a href="http://www.niedermann.dk/Sudoku/Sudoku.aspx" target="_blank">http://www.niedermann.dk/Sudoku/Sudoku.aspx</a></p>
        <h2>A few calculations
</h2>
        <h1>
        </h1>
        <p>
Now for some thoughts on completeness.
</p>
        <p>
A 4x4 Sudoku has 4x3x2x3x2x2 = 288 possible combinations. Not counting combinations
for empty tiles. In my original algorithm I was sure I covered all these combinations.
</p>
        <p>
When using my new algorithm I can generate 2x2x2x2x4x3x2 = 384 possible transformations
for a 4x4 Sudoku. This is more than the number of possible Sudokus. Which means that
some of these transformations must result in the same Sudokus. And furthermore I do
not know if there are Sudokus not covered by the transformations. 
</p>
        <p>
In a 9x9 Sudoku there are 1,83493E+21 possible Sudokus and I can generate 264.539.520
of those or 2.380.855.680 if I had used the extra big block transformations. Not complete
at all, but on the other hand a very large amount of Sudokus and at lightning speed.
</p>
        <h2>Empty tiles
</h2>
        <p>
A Sudoku isn't really a Sudoku without the empty tiles left for the person to fill
out.
</p>
        <p>
I just generate the empty tiles by choosing them at random. This method could probably
lead to either very boring Sudokus or Sudokus that are impossible to solve. One day
I might device some clever algorithm for emptying tiles in a more interesting fashion
:O)
</p>
        <h2>Silverlight
</h2>
        <p>
My conlusions on this my very first silverlight project is that it is extremely easy
to make something appealing in silverlight. On the other hand there are som downsides.
It is difficult to communicate between different silverlight hosts. I can only pass
strings. When you hit the print button I open another browser window. And I actually
have to serialize the Sudoku Grid and deserialize it again in the print window.
</p>
        <p>
Another downside is that is not really browser agnostic. I have tried with 3 browsers
IE8, IE7 and Firefox 3.5. Right now the only one working properly is IE8. In IE7 the
new browser I open for printing has no menu, and so you cannot really print :O) In
Firefox the silverlighthost cannot be resized, which is apparently a known issue.
But it is a problem in the Sudoku generator because I offer Sudokus of any size. This
means that in Firefox only 4x4 and 9x9 Sudokus will look good.
</p>
        <p>
BTW: The rendering of a very large Sudoku takes some time of course even though the
generation is over in milliseconds. 
</p>
        <p>
For my next silverlight project I think I will try out Prism and also the Out-of-browser
experience.
</p>
        <img width="0" height="0" src="http://www.niedermann.dk/aggbug.ashx?id=e0b4bd51-4730-4be3-a518-cd95a234e1d0" />
      </body>
      <title>Extremely fast Sudokus of any size programmed in silverlight 3</title>
      <guid isPermaLink="false">http://www.niedermann.dk/PermaLink,guid,e0b4bd51-4730-4be3-a518-cd95a234e1d0.aspx</guid>
      <link>http://www.niedermann.dk/2009/08/03/ExtremelyFastSudokusOfAnySizeProgrammedInSilverlight3.aspx</link>
      <pubDate>Mon, 03 Aug 2009 21:16:48 GMT</pubDate>
      <description>&lt;p&gt;
I must admit that I have never understood why it was fun to solve Sudoku's. But as
a programmer I was fascinated with the idea of making the perfect Sudoku puzzle generator
algorithm from the very first time I heard of Sudoku. Of course I wanted to make it
so general that it could not only make the boring old 9x9 sudoku. But sodukus of any
size 4x4, 9x9, 16x16, 25x25 and so on...
&lt;/p&gt;
&lt;p&gt;
This resulted in a .NET 1.1 WinForms program 4-5 years ago in which I could randomly
generate all sudoku combinations from 4x4 to 36x36. I created an algorithm that started
in the upper left corner and put in a random number then moving to the next square
put in a new random number from the remaining numbers. This meant that the algorithm
had to backtrack when coming to a deadend where no number was valid. This approach
guaranteed that all possible Sudokus could be generated, but it was extremely slow.
Well for 9x9 sudokus it was less than a second but for 36x36 sudokus it was around
16 hours :O)
&lt;/p&gt;
&lt;p&gt;
A few weeks ago I thought it was time to try out &lt;a href="http://silverlight.net" target="_blank"&gt;Silverlight&lt;/a&gt; and
make a small program to test Microsofts "new" programming platform, but I had to come
up with an idea for a small program. And for some reason Sudoku popped up again.
&lt;/p&gt;
&lt;p&gt;
And I came up with a novel idea for an extremely fast generator (try it &lt;a href="http://www.niedermann.dk/Sudoku/Sudoku.aspx" target="_blank"&gt;here&lt;/a&gt;).
It has been said that no ideas are new anymore and I am pretty sure that I am not
the first to think of this since the algorithm is pretty obvious. I start with a valid
Sudoku as a template and then apply transformations of the columns, the rows and the
numbers themselves. 
&lt;/p&gt;
&lt;p&gt;
To generate a valid Sudoku I first generate the template. The template is generated
by starting with 1 in the upper left corner and then counting upwards. Next I go to
the 4th row and start in the second column counting from 1 again like this:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.niedermann.dk/content/binary/WindowsLiveWriter/ExtremelyfastSudokusofanysizeprogrammedi_1092B/s1.jpg"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="244" alt="s1" src="http://www.niedermann.dk/content/binary/WindowsLiveWriter/ExtremelyfastSudokusofanysizeprogrammedi_1092B/s1_thumb.jpg" width="243" border="0"&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
Next I go to the 7th row and the 3rd columm and so on. So I add 3 rows (the square
root of 9) each time. In a 16x16 sudoku I add 4 rows each time. The final template
is generated in a few milliseconds even in a 400x400 Sudoku. The final template for
a 9x9 sudoku looks like this:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.niedermann.dk/content/binary/WindowsLiveWriter/ExtremelyfastSudokusofanysizeprogrammedi_1092B/s2.jpg"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="244" alt="s2" src="http://www.niedermann.dk/content/binary/WindowsLiveWriter/ExtremelyfastSudokusofanysizeprogrammedi_1092B/s2_thumb.jpg" width="217" border="0"&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
The template is itself a valid Sudoku.
&lt;/p&gt;
&lt;p&gt;
Now I make the transformation using an observation I have made. In any valid Sudoku
I can make another valid Sudoku by switching the columns within each block of 3 columns.
As indicated in red colour for the first block above.
&lt;/p&gt;
&lt;p&gt;
Secondly I can do the same for the rows.
&lt;/p&gt;
&lt;p&gt;
And last I can transform the numbers themselves so that all 1's are transformed to
a number from 1 to 9. all 2's are transformed to one of the remaining 8 numbers and
so on.
&lt;/p&gt;
&lt;p&gt;
I could also have applied a 4th transformation&amp;nbsp; that switched the big blocks
as columns and rows, but I don't think that it will add much value.
&lt;/p&gt;
&lt;p&gt;
In all this the entire puzzle can be generated in milliseconds for even extremely
big Sudokus.
&lt;/p&gt;
&lt;p&gt;
Try it out yourself at &lt;a href="http://www.niedermann.dk/Sudoku/Sudoku.aspx" target="_blank"&gt;http://www.niedermann.dk/Sudoku/Sudoku.aspx&lt;/a&gt;
&lt;/p&gt;
&lt;h2&gt;A few calculations
&lt;/h2&gt;
&lt;h1&gt;
&lt;/h1&gt;
&lt;p&gt;
Now for some thoughts on completeness.
&lt;/p&gt;
&lt;p&gt;
A 4x4 Sudoku has 4x3x2x3x2x2 = 288 possible combinations. Not counting combinations
for empty tiles. In my original algorithm I was sure I covered all these combinations.
&lt;/p&gt;
&lt;p&gt;
When using my new algorithm I can generate 2x2x2x2x4x3x2 = 384 possible transformations
for a 4x4 Sudoku. This is more than the number of possible Sudokus. Which means that
some of these transformations must result in the same Sudokus. And furthermore I do
not know if there are Sudokus not covered by the transformations. 
&lt;/p&gt;
&lt;p&gt;
In a 9x9 Sudoku there are 1,83493E+21 possible Sudokus and I can generate 264.539.520
of those or 2.380.855.680 if I had used the extra big block transformations. Not complete
at all, but on the other hand a very large amount of Sudokus and at lightning speed.
&lt;/p&gt;
&lt;h2&gt;Empty tiles
&lt;/h2&gt;
&lt;p&gt;
A Sudoku isn't really a Sudoku without the empty tiles left for the person to fill
out.
&lt;/p&gt;
&lt;p&gt;
I just generate the empty tiles by choosing them at random. This method could probably
lead to either very boring Sudokus or Sudokus that are impossible to solve. One day
I might device some clever algorithm for emptying tiles in a more interesting fashion
:O)
&lt;/p&gt;
&lt;h2&gt;Silverlight
&lt;/h2&gt;
&lt;p&gt;
My conlusions on this my very first silverlight project is that it is extremely easy
to make something appealing in silverlight. On the other hand there are som downsides.
It is difficult to communicate between different silverlight hosts. I can only pass
strings. When you hit the print button I open another browser window. And I actually
have to serialize the Sudoku Grid and deserialize it again in the print window.
&lt;/p&gt;
&lt;p&gt;
Another downside is that is not really browser agnostic. I have tried with 3 browsers
IE8, IE7 and Firefox 3.5. Right now the only one working properly is IE8. In IE7 the
new browser I open for printing has no menu, and so you cannot really print :O) In
Firefox the silverlighthost cannot be resized, which is apparently a known issue.
But it is a problem in the Sudoku generator because I offer Sudokus of any size. This
means that in Firefox only 4x4 and 9x9 Sudokus will look good.
&lt;/p&gt;
&lt;p&gt;
BTW: The rendering of a very large Sudoku takes some time of course even though the
generation is over in milliseconds. 
&lt;/p&gt;
&lt;p&gt;
For my next silverlight project I think I will try out Prism and also the Out-of-browser
experience.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.niedermann.dk/aggbug.ashx?id=e0b4bd51-4730-4be3-a518-cd95a234e1d0" /&gt;</description>
      <comments>http://www.niedermann.dk/CommentView,guid,e0b4bd51-4730-4be3-a518-cd95a234e1d0.aspx</comments>
      <category>Games &amp; Puzzles</category>
    </item>
  </channel>
</rss>