This is a program that I wrote just for kicks to solve triangle peg solitaire:
The goal of the puzzle is to remove pegs, one at a time, by jumping one peg over another, ending with just one peg remaining. This program uses a depth first search of all possible moves to find a sequence of moves that solves the puzzle. It's written in JavaScript and uses the HTML5 canvas element to animate the solution. You can see a working version of the program at http://www.geomtech.com/tripeg.
The code files are:
-
Contains the structures and logic to solve the puzzle. This file is self-contained, in the sense that it has no external dependencies and it does no graphics or DOM manipulation; it could be used verbatim to create a command-line program to print the solution; see the comments in the file for details.
-
Contains code that uses the HTML5 canvas element to draw and animate the puzzle.
-
src/tripeg-ui.js, index.html, and tripeg.css
These files use jQuery, Twitter Bootstrap, and tripeg-graphics.js to create a user interface for the puzzle in a browser window. The button icons are from Font Awesome.
-
A little utility that I wrote to help manage sequences of animations in the browser.
-
This is Paul Irish's requestAnimationFrame polyfill. The code in animator.js uses requestAnimationFrame to cause the browser to call custom drawing code on the next screen update.
-
This subdirectory contains a suite of Jasmine unit tests for tripeg-logic.js; to run them:
install nodejs (and npm, if it wasn't automatically installed with nodejs) npm install npm install -g grunt-cli grunt test
-
This is the final minified JS file for use in a browser. This file is not human-readable, at least not by normal humans. Read the above files instead.