SlideServe
Menu
Préférences
© SlideServe · v2026

Triangular Peg Solitaire Implementation with Jagged Array

dorothy-nicholson avatar
9 diapositives · 283 Views · Oct 26, 2014

This document discusses the implementation of the Triangular Peg Solitaire game using a skewed coordinate system represented by a jagged array. It details the construction of the game board, including the constructor parameters for magnitude and empty coordinates. Key methods such as `getSlot()` and `setSlot()` facilitate slot management, while `canMove()` and `canJump()` methods ensure valid peg movements according to game rules. References to mathematical theories and game strategies are also provided, making this a comprehensive resource for developers and game enthusiasts.

Triangular Peg Solitaire Implementation with Jagged Array - slide 1
01 / 9Triangular Peg Solitaire Implementation with Jagged Array
1 / 17

Télécharger la présentation

Triangular Peg Solitaire Implementation with Jagged Array
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  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.