projects:peg_puzzle
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revision | |||
| projects:peg_puzzle [2020/02/09 21:56] – josh | projects:peg_puzzle [2020/02/09 22:03] (current) – josh | ||
|---|---|---|---|
| Line 40: | Line 40: | ||
| * col >= 0 and | * col >= 0 and | ||
| * col %%<=%% row | * col %%<=%% row | ||
| + | |||
| + | ===== Solution-Finding Methods ===== | ||
| + | |||
| + | ==== Forward Brute-Force ==== | ||
| + | |||
| + | We can first write a brute-force algorithm to look for all solutions to the puzzle following an algorithm something like this: | ||
| + | |||
| + | - for each peg present: | ||
| + | - for each movement direction: | ||
| + | - if movement in this direction is valid: | ||
| + | - perform and record the move | ||
| + | - recurse on the new board state | ||
| + | - if movement of no peg was possible: | ||
| + | - record the game | ||
| + | |||
| + | This will evaluate every possible game. | ||
| + | |||
| + | ==== Reverse Brute-Force ==== | ||
| + | |||
| + | If we are looking for solutions that end in a particular end state, we can also use a reverse algorithm starting with a desired ending board state (for example, one peg left in the top position): | ||
| + | |||
| + | - for each hole present: | ||
| + | - for each movement direction: | ||
| + | - if movement from that direction could have happened: | ||
| + | - perform and record the move | ||
| + | - recurse on the new board state | ||
| + | |||
projects/peg_puzzle.1581303417.txt.gz · Last modified: by josh
