All Packages Class Hierarchy This Package Previous Next Index
Class map.MineMap
java.lang.Object
|
+----map.MineMap
- public class MineMap
- extends Object
- implements Map
The class Map implements a mine map. A strategy operates on a mine
map. By invoking the operations of probing and marking, the strategy
attempts to place the mine map in a state in which every cell that does
not contain a mine has been probed, without probing a cell that does
contain a mine.
- See Also:
- Strategy
-
columns()
- Provide the number of columns in this mine map.
-
display()
- Display the mine map on the standard output stream.
-
done()
- Is this game finished?
The game is finished if it has been won or if a cell with a
mine has been probed.
-
look(int, int)
- Look at a cell.
-
mark(int, int)
- Mark a cell.
-
mines_minus_marks()
- Provide the number of mines minus the
number of marks in this mine map.
-
pick(int)
- Pick a number at random.
-
probe(int, int)
- Probe a cell for a mine.
-
rows()
- Provide the number of rows in this mine map.
-
unmark(int, int)
- Unmark a cell.
-
won()
- Has this game been won?
A game is won if every cell which does not contain a mine has
been probed, but no cell with a mine has been probed.
pick
public int pick(int n)
- Pick a number at random.
- Parameters:
- n - a positive number (not checked)
- Returns:
- a nonnegative number less than n
won
public boolean won()
- Has this game been won?
A game is won if every cell which does not contain a mine has
been probed, but no cell with a mine has been probed.
done
public boolean done()
- Is this game finished?
The game is finished if it has been won or if a cell with a
mine has been probed.
probe
public int probe(int x,
int y)
- Probe a cell for a mine.
- If the game is finished, probe behaves like look.
- If the cell does not exist,
OUT_OF_BOUNDS
is returned.
- If the cell is marked,
MARKED
is returned.
- If the cell has a mine,
BOOM
is returned
and the game is lost.
- Otherwise, the number of adjacent mines is returned.
- Parameters:
- x - x coordinate of cell
- y - y coordinate of cell
look
public int look(int x,
int y)
- Look at a cell.
- If the cell does not exist,
OUT_OF_BOUNDS
is returned.
- If the cell is marked,
MARKED
is returned.
- If the cell has not been probed,
UNPROBED
is returned.
- If the cell has a probed mine,
BOOM
is returned.
- Otherwise, the number of adjacent mines is returned.
- Parameters:
- x - x coordinate of cell
- y - y coordinate of cell
mark
public int mark(int x,
int y)
- Mark a cell.
- If the game is finished, mark behaves like look.
- If the cell does not exist,
OUT_OF_BOUNDS
is returned.
- If the cell is marked,
MARKED
is returned.
- If the cell has not been probed, the cell is marked
and
MARKED
is returned.
- Otherwise, the number of adjacent mines is returned.
- Parameters:
- x - x coordinate of cell
- y - y coordinate of cell
unmark
public int unmark(int x,
int y)
- Unmark a cell.
- If the game is finished, unmark behaves like look.
- If the cell does not exist,
OUT_OF_BOUNDS
is returned.
- If the cell is marked, the cell is unmarked
and
UNPROBED
is returned.
- If the cell has not been probed,
UNPROBED
is returned.
- Otherwise, the number of adjacent mines is returned.
- Parameters:
- x - x coordinate of cell
- y - y coordinate of cell
mines_minus_marks
public int mines_minus_marks()
- Provide the number of mines minus the
number of marks in this mine map.
rows
public int rows()
- Provide the number of rows in this mine map.
columns
public int columns()
- Provide the number of columns in this mine map.
display
public void display()
- Display the mine map on the standard output stream.
Used only for debugging.
All Packages Class Hierarchy This Package Previous Next Index