Download
triangular peg solitaire n.
Skip this Video
Loading SlideShow in 5 Seconds..
Triangular Peg Solitaire PowerPoint Presentation
Download Presentation
Triangular Peg Solitaire

Triangular Peg Solitaire

97 Vues Download Presentation
Télécharger la présentation

Triangular Peg Solitaire

- - - - - - - - - - - - - - - - - - - - - - - - - - - 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.