Triangular Peg Solitaire J Wallace April 21 2009

  • Slides: 9
Download presentation
Triangular Peg Solitaire J. Wallace April 21, 2009

Triangular Peg Solitaire J. Wallace April 21, 2009

UML

UML

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

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

Constructor public Board(int magnitude, int empty_x, int empty_y) { board = new boolean[magnitude][]; int

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); } } }

get. Slot() and set. Slot() public boolean get. Slot(int x, int y) { return

get. Slot() and set. Slot() public boolean get. Slot(int x, int y) { return board[x][y-x]; } public void set. Slot(int x, int y, boolean filled) { board[x][y-x] = filled; }

can. Jump() bool can. Move(int src_x, int src_y, int dest_x, int dest_y) { bool

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

can. Jump() continued // Find the middle slot int middle_x =. . . int

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

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

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

References Berlekamp, E. R. , Conway, J. H. , & Guy, R. K. (1982).

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. 200902 -03 from http: //www. allacademic. com/meta/p 206352_index. html.