Peg game plaything
That darn peg game
I'm an egg-no-ray-moose. At least, that's what the good folks at Cracker
Barrel make me out to be, since I can never seem to leave just one peg when
attempting their signature table game, the triangular grid with the jumping
pegs. Makes me feel a little self-conscious, y'know?
So when I recently decided I should really learn some java programming, I
chose the peg game as a good example project. Not that I needed to solve the
game programmatically to satisfy my curiosity — the internet is full of
nicely illustrated solutions. But the game made for a nice case study, where
I could throw in some object-oriented programming, a bit of recursion, and
play with graphics in applets.
And there you have it — a simple little java applet for your
entertainment. Here's how it works
- First choose a starting position: click on the pegs to toggle them on or
off, until you have just the setup you want to explore.
- Click on the "?" button to find the best solution (really, one of various
possible best solutions). This can take a few seconds; when the applet has
figured things out, the "?" button will change to a forward triangle
- Click on the forward button to see the first move, and keep on
clicking until the button turns gray. That's when there are no more moves left.
- At this point (or any point along the way), you can click the rewind
button to reset the pegs and start over.
Curious how it works? It's certainly not fancy, and my java coding
could undoubtedly use some improvement — but it works, and if you'd like
to have a look behind the scenes, feel free to look at the source codes, which
consist of a main calculation class (TriangleBoard) that figures out the best sequence
of moves, and an applet class (TriangleApplet)
to put up the front end and allow user interaction. Feel free to get in touch
(link at bottom of page) if you have any questions, or suggestions for
Visitors to this page have left the following comments
|Presh||Feb 27, 2015||Hi there is no main in the programe.I have same game program in assignement.can you please provide me detail code|
All the code is there to download in the links. There's no "main" because it's an applet, but you should be able to adapt readily for a stand-alone program.
I welcome comments about my web pages; feel free to use the form below to
leave feedback about this particular page. For the benefit of other visitors
to these pages, I will list any relevant comments you leave, and if
appropriate, I will update my page to correct mis-information. Faced with an
ever-increasing onslaught of spam, I'm forced to discard any comments including
html markups. Please submit your comment as plain text. If you have a
comment about the website as a whole, please leave it in my
guestbook. If you
have a question that needs a personal response, please
November 28, 2014