Info

This question is closed. Reopen it to edit or answer.

Cracker Barrel Program (triangle solitare)

2 views (last 30 days)
Larry
Larry on 26 Apr 2014
Closed: MATLAB Answer Bot on 20 Aug 2021
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!

Answers (1)

Image Analyst
Image Analyst on 27 Apr 2014
  5 Comments
Larry
Larry on 28 Apr 2014
Well since the question was flagged due to the fact that it is my final project, I assume someone thinks I'm trying to cheat. This is the sole reason why I haven't posted what I have thus far. I don't want anyone to work off of my progress (greedy as that sounds). And thanks for the advice. I just feel like a book would help me see some examples that I could learn from.
Image Analyst
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.

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!