Subversion Repositories sokoban

Rev

Blame | Last modification | View Log | RSS feed

  1. package gdi.ws0809.test;
  2.  
  3. import java.io.File;
  4.  
  5. /**
  6.  * All public unit tests access your implementation using methods of this interface exclusively.
  7.  * You have to provide an implementation of SokobanTestAdapter to map the methods of this interface
  8.  * to you implementation.
  9.  *
  10.  * @version 1.1
  11.  * @author daniel, Steven Arzt
  12.  *
  13.  */
  14. public interface SokobanTest {
  15.  
  16.         /**
  17.          * Load a level and parse it into the internal representation.
  18.          * The loaded level is now the  and should
  19.          * e.g. be shown in the GUI.
  20.          *
  21.          * @param lvl The file from which to load the level
  22.          * @throws Exception in case the level is not syntactically correct
  23.          */
  24.         void loadLevel(File lvl) throws Exception;
  25.        
  26.         /**
  27.          * Returns the String representation of the <i>current</i> level.
  28.          *
  29.          * @return the String representation
  30.          */
  31.         String currentLevelToString();
  32.        
  33.         /**
  34.          * Returns whether the <i>current</i> level is solved.
  35.          *
  36.          * @return True if the current level has been solved, otherwise false
  37.          */
  38.         boolean isSolved();
  39.  
  40.         /**
  41.          * Gets the current level's width
  42.          *
  43.          * @return The width of the current level
  44.          */
  45.         int getLevelWidth();
  46.  
  47.         /**
  48.          * Gets the current level's height
  49.          *
  50.          * @return The height of the current level
  51.          */
  52.         int getLevelHeight();
  53.  
  54.         /**
  55.          * Gets the total number of walls in the current levels
  56.          *
  57.          * @return The number of walls in the current level
  58.          */
  59.         int getWallCount();
  60.  
  61.         /**
  62.          * Gets the total number of crates in the current levels
  63.          *
  64.          * @return The number of crates in the current level
  65.          */
  66.         int getCrateCount();
  67.  
  68.         /**
  69.          * Gets the total number of goals in the current levels
  70.          *
  71.          * @return The number of goals in the current level
  72.          */
  73.         int getGoalCount();
  74.        
  75.         /**
  76.          * Move the worker according to the rules. The direction to move is either
  77.          * right, left, up or down, encoded as 'R','L','U' or 'D'.
  78.          *  
  79.          * @param direction The encoded direction to move the worker
  80.          */
  81.         void moveWorker(char direction);
  82.  
  83.         /**
  84.          * Load a set of levels from a directory. The levels should be
  85.          * sorted alphabetically. It should not load the first level yet.
  86.          * Loading the first level should only happen after a call to
  87.          * startNextLevel().
  88.          *
  89.          * @param levelDir the directory from which to load the levels
  90.          */
  91.         void setLevelDir(File levelDir);
  92.  
  93.  
  94.         /**
  95.          * The next level in a set of levels loaded with loadLevelDir
  96.          * becomes the <i>current</i> level. If there is no more level
  97.          * left, an exception may be thrown.
  98.          */
  99.         void startNextLevel() throws Exception;
  100.  
  101.         /**
  102.          * Return the steps performed in the <i>current</i> level, since
  103.          * the last restart of the level. Remember that only the legal moves
  104.      * count.
  105.          *
  106.          * @return performed steps.
  107.          */
  108.         int getStepsInCurrentLevel();
  109.  
  110.         /**
  111.          * Tells the Sokoban implementation to write the current
  112.          * highscores to disk, as detailed in the documentation.
  113.          */
  114.         void writeHighScoreFile();
  115.  
  116.         /**
  117.          * Set the player name used for highscores.
  118.          *
  119.          * @param name The player name.
  120.          */
  121.         void setPlayerName(String name);
  122.  
  123.         /**
  124.          * Gets the X coordinate of the worker's current position
  125.          *
  126.          * @return The worker's position's current X coordinate
  127.          */
  128.         int getWorkerPositionY();
  129.  
  130.         /**
  131.          * Gets the Y coordinate of the worker's current position
  132.          *
  133.          * @return The worker's position's current Y coordinate
  134.          */
  135.         int getWorkerPositionX();
  136.        
  137.         /**
  138.          * Gets whether there is a crate at the position identified by the specified
  139.          * X and Y coordinate
  140.          *
  141.          * @param i The X coordinate of the grid position to check
  142.          * @param j The Y coordinate of the grid position to check
  143.          * @return True if there is a crate at the specified position, otherwise
  144.          * false
  145.          */
  146.         boolean isCrateAt(int i, int j);
  147.  
  148.         /**
  149.          * Gets whether there is a wall at the position identified by the specified
  150.          * X and Y coordinate
  151.          *
  152.          * @param i The X coordinate of the grid position to check
  153.          * @param j The Y coordinate of the grid position to check
  154.          * @return True if there is a wall at the specified position, otherwise
  155.          * false
  156.          */
  157.         boolean isWallAt(int i, int j);
  158.  
  159.         /**
  160.          * Gets whether there is a goal at the position identified by the specified
  161.          * X and Y coordinate
  162.          *
  163.          * @param i The X coordinate of the grid position to check
  164.          * @param j The Y coordinate of the grid position to check
  165.          * @return True if there is a goal at the specified position, otherwise
  166.          * false
  167.          */
  168.         boolean isGoalAt(int i, int j);
  169.  
  170.         /**
  171.          * Checks whether the crate at position (x, y) can be moved in direction c
  172.          *
  173.          * @param i The x coordinate of the crate to check
  174.          * @param j The y coordinate of the crate to check
  175.          * @param c The direction in which the crate move shall be tested
  176.          * @return True if the crate at the specified position can be moved in the
  177.          * given direction, otherwise false
  178.          */
  179.         boolean canMoveCrate(int i, int j, char c);
  180.  
  181.         /**
  182.          * Gets the name of the best player (the one with with the least moves)
  183.          * over all levels. If Player A has completed level L1 with 10 moves and
  184.          * level L2 with 15 moves and player B has completed level L2 with 11 moves,
  185.          * the correct return value would be "A" as he has achieved to complete a
  186.          * level with only 10 moves.
  187.          * If the highscore list is empty, an empty string shall be returned.
  188.          *
  189.          * @return The name of the player with the least moves
  190.          */
  191.         String getBestPlayerName();
  192.  
  193.         /**
  194.          * Clears the highscore list. You can either remove all entries from the
  195.          * "highscore.txt" file or remove the whole file. If there is no highscore
  196.          * file at the moment, nothing should happen.
  197.          */
  198.         void clearHighscoreList ();
  199.  
  200.         /**
  201.          * Creates a new entry in the highscore list if the given data describes a
  202.          * new highscore entry. If the specified entry already exists or has too
  203.          * many steps to be a highscore, nothing happens and false is returned.
  204.          *
  205.          * @param playername The name of the player that has achieved the score
  206.          * @param i A unique number identifying the level in which the score has
  207.          * been reached
  208.          * @param j The count of moves the player has needed to complete the
  209.          * specified level
  210.          * @param k The time the player has needed to solve the level in seconds
  211.          * @return True if a new entry in the highscore list has been created,
  212.          * otherwise false
  213.          */
  214.         boolean createHighscoreEntry (String playername, int i, int j, int k);
  215.  
  216.         /**
  217.          * Gets the count of entries in the highscore list
  218.          *
  219.          * @return The count of entries in the highscore list
  220.          */
  221.         int getHighscoreCount();
  222.        
  223.         /*===================================================================*/
  224.        
  225.         /**
  226.          * Undo the last move. If no move can be undone (e.g. no move has been performed) an Exception is thrown.
  227.          *
  228.          * @throws Exception notifying the client that no move could be undone
  229.          */
  230.         void undoLastMove() throws Exception;
  231.  
  232.         /**
  233.          * Redo the last undone move. If no move can be redone (e.g. no move has been undone) an Exception is thrown.
  234.          *
  235.          * @throws Exception notifying the client that no move could be redone
  236.          */
  237.         void redoLastUndoneMove() throws Exception;
  238.  
  239.         /**
  240.          * Save the current game state to the File.
  241.          *
  242.          * @param f the file to save the game state in.
  243.          */
  244.         void saveGame(File f);
  245.  
  246.         /**
  247.          * Save the current game state to the File.
  248.          *
  249.          * @param f the file to save the game state in.
  250.          */
  251.         void loadGame(File f);
  252.  
  253.         /*===================================================================*/
  254.  
  255.         /**
  256.          * Returns whether the current level is in a deadlock position.
  257.          *
  258.          * @return returns whether the current level is in a deadlock position.
  259.          */
  260.         boolean isDeadlock();
  261.  
  262.         /**
  263.          * Moves the worker with the steps specified in the move sequence string
  264.          * which needs to be in the RLUD format.
  265.          *
  266.          * @param Sequence The move sequence in the RLUD format
  267.          */
  268.         void moveWorkerSequence(String Sequence);
  269.        
  270.         /**
  271.          * Checks whether all objects in the current level are located in
  272.          * a continuous wall boundary.
  273.          * @return True if the level is validly surrounded by walls, otherwise
  274.          * false
  275.          */
  276.         boolean checkWallBounding ();
  277.  
  278.         /*===================================================================*/
  279.  
  280.         /**
  281.          * Computes a solution to the current level. The level itself remains unchanged.
  282.          *
  283.          * @parm maxTime Maximal search time in milliseconds. The method should return null if no solution could be computed within this time frame.
  284.          * @return A solution to the level in URLD notation or null, if no solution has been found
  285.          */
  286.         String solveLevel(int maxTime);
  287.  
  288. }
  289.