ITI0011:HW01 Mall

Allikas: Kursused
Mine navigeerimisribale Mine otsikasti

Siin lehel on ITI0011 aine esimese kodutöö (Aardejaht) mall:

<source lang="java"> public class HW01 {

   /**
    * Value to return in makeMove in case
    * the cell was empty.
    */
   public static final int CELL_EMPTY = 0;
   /**
    * Value to return in makeMove in case
    * the cell contained treasure.
    */
   public static final int CELL_TREASURE = 10;
   /**
    * Value for a cell which is hidden
    * (the contents of the cell is not visible).
    * Used in bonus part 1.
    */
   public static final int CELL_HIDDEN = 100;
   /**
    * Value to return in makeMove in case
    * the cell does not exist.
    */
   public static final int CELL_ERROR = -1;
   /**
    * Used to indicate that the score is wrong.
    * Used by getHighscoreScoreAtIndex()
    */
   public static final int HIGHSCORE_WRONG = Integer.MIN_VALUE;
   /**
    * Minsweeper-like clearing in case of empty cells.
    */
   public static final int GAME_TYPE_MINESWEEPER = 1;
   /**
    * Cell contains the distance to the closest treasure.
    */
   public static final int GAME_TYPE_HOT_COLD = 2;
   /**
    * Makes move to cell in certain row and column
    * and returns the contents of the cell.
    * Use CELL_* constants in return.
    * @param row Row to make move to.
    * @param col Column to make move to.
    * @return Contents of the cell.
    */
   public static int makeMove(int row, int col) {
       if (row == -1) return CELL_ERROR;
       return CELL_EMPTY;
   }
   /**
    * Creates a map with certain measures and treasures.
    * You should store the created map internally.
    * This means you can choose your own implementation of how to store
    * the map.
    * The treasures should be put on the map randomly using setCell method.
    * @param height Height of the map.
    * @param width Width of the map.
    * @param treasures The number of treasures on the map.
    * @return Whether map was created.
    */
   public static boolean createMap(int height, int width, int treasures) {
       // initialize map (for example 2D-array)
       //   - set all cells empty (is this needed?)
       // do some random for every treasure and add them to map:
       setCell(2, 3, CELL_TREASURE);
       if (height == -3) return false;
       return false;
   }
   /**
    * Sets the cell value for the active map (created earlier using
    * createMap method).
    * This method is required to test certain maps
    * @param row Row index.
    * @param col Column index.
    * @param cellContents The value of the cell.
    * @return Whether the cell value was set.
    */
   public static boolean setCell(int row, int col, int cellContents) {
       if (row == -123) return false;
       return false;
   }
   /**
    * Gets the used move count by the player.
    * @return The number of moves done.
    */
   public static int getMoveCount() {
       return 1;
   }
   /**
    * Returns cell contents at the given row and column.
    * @param row Row index
    * @param col Column index
    * @return Cell contents according to CELL_* constants.
    * In case the cell contains number of treasures, returns this number.
    */
   public static int getCell(int row, int col) {
       // open with treasure number => 4
       // treasure => CELL_TREASURE
       // open with treasure number == 0 => 0 or CELL_EMPTY
       // hidden (not yet opened)
       return CELL_HIDDEN;
   }


   /**
    * Adds a player name and score to one of the highscore tables.
    * @param id Highscore table to use. This can be
    *           configuration or name etc. In case the game has several
    *           highscore tables (one for minesweeper version, one for
    *           hot-cold version) they have to have different ids.
    * @param name The name of the player.
    * @param score The score of the player.
    * @return The index where the player is put. In case
    * the name is too short, the table with id does not exist
    * or the score is too low, returns -1.
    */
   public static int addHighscore(String id, String name, int score) {
       return 1;
   }
   /**
    * Gets the score from the concrete table at concrete index.
    * @param id The highscore table to use.
    * @param index The index of the score to be returned
    * @return The score at the index. If the table does not exist
    * or the index is not acceptable, returns -1.
    */
   public static int getHighscoreScoreAtIndex(String id, int index) {
       return HIGHSCORE_WRONG;
   }
   /**
    * Gets the name of the player from the conrete table
    * at concrete index.
    * @param id The highscore table to use.
    * @param index The index of the player to be returned.
    * @return The name at the index. If the table does not exist
    * or the index is not acceptable, return null.
    */
   public static String getHighscoreNameAtIndex(String id, int index) {
       return null;
   }
   /**
    * Returns all the available highscore table ids.
    * @return An array of table ids.
    */
   public static String[] getHighscoreTables() {
       return null;
   }
   /**
    * Resets (clears) highscore table.
    * @param id The id of the table to be reset.
    */
   public static void resetHighscores(String id) {
       //
   }


   /**
    * Starts a game with the given mode.
    * This allows the game to switch between "minesweeper" and "hot-cold"
    * variants. Even if you only choose to implement the "hot-cold" variant
    * this method is required to test it. Minesweeper variant is the default.
    * @param type The type of game to start.
    */
   public static void startGame(int type) {
   }
   /**
    * Returns the distance to the closest treasure.
    * The distance indicates the minimum steps it takes to get from
    * the given (row, col) to the closest treasure.
    * Step can be taken to every adjacent cell (horisontal, vertical and
    * diagonal). From one cell you can step to 8 other cells.

*

     * Example:
     * ...C
     * .B..
     * A...
     * ..DP
     * 
    *
    * distances:
    * AP = 3
    * BP = 2
    * CP = 3
    * DP = 1
    *
    * @param row Row index
    * @param col Col index
    * @return The distance to the closest treasure
    */
   public static int getDistanceToClosestTreasure(int row, int col) {
       return 0;
   }

}

</source>