1 / 9

Triangular Peg Solitaire

Triangular Peg Solitaire. J. Wallace April 21, 2009. UML. 0. 1. 2. 3. 4. 0. 0. 1. 2. 3. 4. 0. 1. 1. 2. 3. 4. 1. 2. 2. 3. 4. 2. 3. 3. 4. 3. 4. 4. 4. Data Representation. Skewed coordinate system using jagged array. Constructor.

Download Presentation

Triangular Peg Solitaire

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Triangular Peg Solitaire J. Wallace April 21, 2009

  2. UML

  3. 0 1 2 3 4 0 0 1 2 3 4 0 1 1 2 3 4 1 2 2 3 4 2 3 3 4 3 4 4 4 Data Representation • Skewed coordinate system using jagged array

  4. Constructor public Board(int magnitude, int empty_x, int empty_y) { board = new boolean[magnitude][]; int translated_x = empty_x; int translated_y = empty_y - empty_x; for(int i = 0; i < board.length; i++) { board[i] = new boolean[magnitude - i]; for(int j = 0; j < board[i].length; j++) { board[i][j] = (i != translated_x || j != translated_y); } } }

  5. getSlot() and setSlot() public boolean getSlot(int x, int y) { return board[x][y-x]; } public void setSlot(int x, int y, boolean filled) { board[x][y-x] = filled; }

  6. canJump() bool canMove(int src_x, int src_y, int dest_x, int dest_y) { bool horizontalMove = ... bool diagonalMove = ... // It must be either horinontal or diagonal if(!horizontalMove || !diagonalMove) return false // Make sure its not trying to jump to same slot if(horizontalMove && diagonalMove) return false // Find the distances for both x and y int xDist = ... int yDist = ... // If xDist or yDist is not 2 then you're trying to jump too short or far if(xDist != 2 || yDist != 2) return false

  7. canJump() continued // Find the middle slot int middle_x = ... int middle_y = ... // Check that the pegs are in the right slots if(!getSlot(src_x, src_y) || !getSlot(middle_x, middle_y) || getSlot(dest_x, dest_y)) return false return true }

  8. 3-, 6-, and trapezoid-purge Image credit: Bell, G. (2007)

  9. References • Berlekamp, E. R., Conway, J. H., & Guy, R. K. (1982). Winning Ways for Your Mathematical Plays, Vol. 2. London: Academic Press. • Brandeth, G. (1984). The Book of Solo Games. New York: Peter Bedrick Books. • Mohr, M. S. (1997). The New Games Treasury. New York: Mariner Books. • Bell, G.(2007) “Solving Triangular Peg Solitaire.”Paper presented at the annual meeting of the Mathematical Association of America, The Fairmont Hotel, San Jose, CA.2009-02-03from http://www.allacademic.com/meta/p206352_index.html.

More Related