f-log

just another web log

07 Mar 2011 18:52
[continued from flog]
So the main program executed a loop that simply looked for 'unprocessed' boards and 'processed' them.
The initial game board layout was set as 'unprocessed', this meant that there were more pegs to test for moves, as each peg was tested.
Oi! Board, give me the next peg;
dear peg, you able to move North?
OK, then that move is made on a copy of the current board and stored in the data tree as a branch from the initial root board.
dear peg, you able to move South?
No?
East?West?
Oi! Board, give me the next peg;
What do you mean 'no more pegs' ?
Right, set this board as 'processed'.
Start loop again, get next 'unprocessed' board ...

Finally there are no more boards, search for solutions in the data tree, boards that have only one peg left.
Calculate the number of parents for each solution, find the shortest and display it.

6 solutions found, shortest has 5 moves
XX...XX
XX.O.XX
..OOO..
...O...
...O...
XX...XX
XX...XX

XX...XX
XX.O.XX
..O..O.
...O...
...O...
XX...XX
XX...XX

XX...XX
XX.O.XX
..OO.O.
.......
.......
XX...XX
XX...XX

XX...XX
XX.O.XX
....OO.
.......
.......
XX...XX
XX...XX

XX...XX
XX.O.XX
...O...
.......
.......
XX...XX
XX...XX

XX...XX
XX...XX
.......
...O...
.......
XX...XX
XX...XX
There were 35 moves stored in the tree


Am I releasing the code ? no, its a bit messy and has no way of entering new board layouts, hacking the source is the only way.
Still, if you are in desperate need of a C# peg solitaire solver you can email me for a copy.
IReallyNeedAPegSolitaireSolver@jumpstation.co.uk

EOL
03 Mar 2011 21:37
[continued from flog]
I could now find pegs, check for moves and make moves. Next I needed recursion. Recursion is like fractions or the area of a triangle when you are at school, they are taught and for many people never used.
All software engineers are taught recursion and up until now I have not needed it.
I wanted a ready made off the shelf object type to hold my recursive branching data, where each branch was each possible move from a previous move on the board.
Strangely there is no .Net Tree data type, I tried to use XML but this totally unnecessary.
A simple object with a collection of that same object inside was all that was needed.
i.e. a branch that contained one fruit and any number of branching branches that also contained one fruit and any number of branching branches ....

The fruit was the state of the board after each peg moved. Originally I tried to store the move itself but this got very complicated very quickly.
Recursion meant I could find a 'fruit' in the middle of the branches by always starting at the root branch, the 'tree'.
When the solution was found, only one peg was left on the board, I needed to show the steps leading to that state, so each branch had a parent property.
This meant I could take the completed board and look at its parent branch and then look at the parents branch all the way back to the starting branch.
Lots of tests were added here as I needed more and more methods to do jobs for me.
02 Mar 2011 20:32
[continued from flog]
I began with pseudo code, for each peg on the board try and move it and do this recursively until the solution is found.
Wow, that was easy...
We had been introducing testing to new projects at work. Testing is one of those things that software developers do not do naturally, they know it is the right thing to do but usually miss it out completely or tack it on at the end of a project.
Once a developer has actually used testing frameworks for automated testing from the beginning of a project all that changes, instead of reluctance to testing they actively embrace it.
So it was with my peg solitaire solver.

I started with the basics, creating a board, pegs and walls, then a number of methods to locate pegs from coordinates and coordinates from pegs.
Testing a sample board with know peg locations.
Then the logic for moving pegs. A Peg can move either North, South, East or West but only if it 'jumps' over another peg (like draughts)
Tests were created that showed that a move was valid for a known peg.
In the past I may have tested the functionality but then removed it once it was working, with my slowly building battery of tests all the functionality was tested as I made changes, picking up issues outside of an area that I was specifically working on very quickly.
01 Mar 2011 22:03
[continued from flog]
Why did I need a solution to Peg Solitaire ?
Back in 2007/8 I played and completed http://en.wikipedia.org/wiki/Professor_Layton_and_the_Curious_Village a great story lead collection of bizzare puzzles.
The in 2008/9 I played but have yet to complete http://en.wikipedia.org/wiki/Professor_Layton_and_the_Diabolical_Box which worked in the same fashion.

PL&CV had a number of repeating puzzles that became harder and more annoying, these were the ones that required a little bit of help from the internet http://professorlaytonwalkthrough.blogspot.com/
I realised then that the solution could have been computed.

On of the repeating themes in PL&PB was, you guessed it Peg Solitaire. After completing nearly all the puzzles in the game I was left with a number of peg solitaire puzzles that I could have completed by hand but I decided not too.

01 Mar 2011 22:01
[continued from flog]
I wanted this to be more than a hack-a-thon, so a fair amount of time went into investigation and testing.
The main requirement was no outside solutions, it would have been trivial to download a working program from the net.
This one had to be all mine.
loading results, please wait loading animateloading animateloading animate
[More tags]
rss feed

email

root

flog archives


Disclaimer:
This page is by me for me, if you are not me then please be aware of the following
I am not responsible for anything that works or does not work including files and pages made available at www.jumpstation.co.uk I am also not responsible for any information(or what you or others do with it) available at www.jumpstation.co.uk
In fact I'm not responsible for anything ever, so there!

[Pay4Foss banner long]