1 / 18

Software Design Specification for a Triangular Peg Board Game By Leo Gonzalez

Software Design Specification for a Triangular Peg Board Game By Leo Gonzalez. Introduction This document describes the design of a single player interactive triangular peg board game with a variable number of pegs. . Rules.

kimama
Download Presentation

Software Design Specification for a Triangular Peg Board Game By Leo Gonzalez

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. Software Design Specification for a Triangular Peg Board GameBy Leo Gonzalez

  2. IntroductionThis document describes the design of a single player interactive triangular peg board game with a variable number of pegs.

  3. Rules • A legal move consists of a peg jumping horizontally or diagonally over an adjacent peg and into an empty hole. The peg that is jumped is removed from the board. A peg cannot jump over a hole. The player wins if there is only one peg remaining on the board. If no legal move is possible and there is more than one peg on the board, the player loses.

  4. System Overview • This program uses an object oriented design using C++.

  5. General Constraints • The program will be launched from the command line. The display will consist of text and the player will type commands to allow the software to run on a wide variety of hardware.

  6. The Algorithm • The algorithm of the main program can be summarized in the following pseudocode that is repeated until the user exits the program. Repeat : Prompt user for command If command is valid, execute Else Notify that command is not valid Until: Player quits

  7. Use Cases Peg Board MOVE UNDO SOLVE RESET BOARD DISPLAY MOVES PLAYER DISPLAY BOARD Figure 1

  8. Goals and Guidelines • This design tries to improve efficiency by minimizing the number of game states that are searched when the player directs the program to find a solution.

  9. User Interface • The display will use text to simulate a peg board. This is a 3 level board. 0,0:0 0,1:1 1,1:1 0,2:1 1,2:1 2,2:1 • The coordinate system is based on George Bell’s Skew Cartesian coordinates system. The player will move by entering in the To and From coordinates. For example 2,2 0,0 would jump the peg located at 2,2, to 0,0 with the resulting board of …

  10. 0,0:1 0,1:1 1,1:0 0,2:1 1,2:1 2,2:0

  11. Internal Representation • The program defines a PegBoard Class and a MoveList Class. The PegBoard Class uses the MoveList class to represent both the moves made by the player. When the player commands the program to solve, the PegBoard creates lists of legal unique moves to be searched. These classes are shown in Figure 2. The interaction between the Player and the classes is shown in Figure 3. The PegBoard class uses a two dimensional array to represent the current board state. The MoveList class uses a pair of two dimensional arrays to represent the From and Two coordinates.

  12. Class Diagram PegBoard Class Private: pegs integer[] [] numLevels integer movesMade MoveList possibleMoves MoveList[] solve() backtrack() checkSymmetry() Public: getNumLevels() getPeg(int row, int col) setPeg(int row, int col) setNumLevels(int n) move(int fromRow, int fromCol, int toRow, int toCol) solve() displayBoard() displayMoves() newBoard(int lvlNum) MoveList Class Private: numMoves from int[][] to int[][] Public: getMoveFrom(int n,int result[]) getMoveTo(int n,int result[]) addMove(int from[], int to[]) removeMove(n) getNumMoves() Figure 2

  13. Policies and Tactics • The program will use a depth first search algorithm with backtracking to find a game state that is reachable from the current state in which there is only one peg left. If there is no such game state, the player will be notified that there is no possible solution from the current board configuration. The player will always have the option to undo moves and try to find a solution from a previous state.

  14. Because every move removes exactly one peg from play, every possible solution will have exactly n-1 moves, where n is the number of pegs. Therefore, any solution found will have the minimum number of moves. When searching for a solution, the program will identify pegs that will lead to identical game states as other pegs, and removing them from consideration as possible moves. This solution is more efficient than a brute force approach. The recursive algorithm for finding a solution is as follows

  15. Solve Algorithm Create a possibleMoves list Check current board for symmetry Add unique pegs to possibleMoves list For each possible move in the list execute move if one peg left, return solution. Else solve current board. Backtrack If it backtracks to the top level, and there are no possible moves left, no solution was found.

  16. Testing • The program should be tested with different sequences of commands as the player has the option to enter any command at any time. Solutions that are found by the program should be tested by hand to confirm their accuracy. Multiple levels of board should also be tested.

  17. Bibliography “Solitaire Puzzle with Backtracking”, by Paolo Martinoli http://www.codeproject.com/KB/cpp/SolitairePuzzle.aspx “Triangular peg Solitaire”, by George Bell http://www.geocities.com/gibell.geo/pegsolitaire/tindex.html#gpjr “Solving Triangular Peg Solitaire” by George I. Bell. Journal of Integer Sequences, Vol. 11(2008), Article 08.4.8 http://arxiv.org/PS_cache/math/pdf/0703/0703865v6.pdf

More Related