Info
This question is closed. Reopen it to edit or answer.
Cracker Barrel Program (triangle solitare)
2 views (last 30 days)
Show older comments
Hi all. I have a project on making a Matlab program to solve this game: http://www.youtube.com/watch?v=ILKXEnX_YGM using only for loops and while loops and simple commands. Does anyone have any advice on how to start this? perhaps by setting up a matrix of one's, asking the user which peg is removed. that peg will then be zero. but where do i go from there? Thanks!
0 Comments
Answers (1)
Image Analyst
on 27 Apr 2014
5 Comments
Image Analyst
on 28 Apr 2014
Try using GUIDE to set up an axes control using fill() to create the triangle, and rectangle() to create the colored spots/pegs/holes at know, specified locations. Then when a turn starts they click a starting location and an ending location - use ginput(2) for this. This will give you the x,y locations of where they clicked and you can compare that to a list of known hole locations. Have an array that keeps track of where the pegs are so you can determine if a specified move is allowable or not. If it's a legal move, move the peg by drawing a new circle with rectangle (be sure to save it's handles so you can delete the peg later when it's jumped), and delete the jumped one with delete. Then use rectangle() to put up solid circles where the pegs still remain. Somewhat challenging for a beginner, but you should be able to get it done in 2 or 3 hours I would think.
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!