edu.rice.comp440.mine
Interface MineBoard


public interface MineBoard

This interface defines the Minesweeper board. This is meant to be an immutable data structure, only providing methods for data access.

Version:
$Revision: 1.3 $
Author:
jasandov

Method Summary
 int getCount(int x, int y)
          Returns the number of mines surrounding the target cell.
 int getCount(java.awt.Point p)
          Returns the number of mines surrounding the target cell.
 java.util.Set getEdge()
          Returns an immutable set containing Point objects representing the edge of the Minesweeper board.
 java.util.Set getFringe()
          Returns an immutable set containing Point objects representing the fringe of the Minesweeper board.
 int getHeight()
          Returns the height of the Minesweeper board
 java.awt.Point getLastMove()
          Returns the move that was last made on the board; returns null if no moves have been made
 int getMines()
          Retunrs the total number of mines in the Minesweeper board
 java.util.Set getNeighbors(int x, int y)
          Returns an immutable set containing Point objects representing the neighbors of the target cell.
 java.util.Set getNeighbors(java.awt.Point p)
          Returns an immutable set containing Point objects representing the neighbors of the target cell.
 int getOpenedCount()
          Returns the number of opened cells on the board; the return value will be in the range of 0 inclusive and getWidth() * getHeight() inclusive.
 int getWidth()
          Returns the width of the Minesweeper board
 boolean inBounds(int x, int y)
          Returns boolean indicating whether the target cell is in bounds of this Minesweeper board
 boolean inBounds(java.awt.Point p)
          Returns boolean indicating whether the target cell is in bounds of this Minesweeper board
 boolean isOpened(int x, int y)
          Returns a boolean indicating whether the target cell has been opened yet.
 boolean isOpened(java.awt.Point p)
          Returns a boolean indicating whether the target cell has been opened yet.
 void print()
          Prints a text representation of the board to System.out
 

Method Detail

getHeight

public int getHeight()
Returns the height of the Minesweeper board

Returns:
height of the Minesweeper board

getWidth

public int getWidth()
Returns the width of the Minesweeper board

Returns:
width of the Minesweeper board

getMines

public int getMines()
Retunrs the total number of mines in the Minesweeper board

Returns:
total number of mines

inBounds

public boolean inBounds(int x,
                        int y)
Returns boolean indicating whether the target cell is in bounds of this Minesweeper board

Parameters:
x - x-coordinate of the target cell; between 0 inclusive and getWidth()-1 inclusive
y - y-coordinate of the target cell; between 0 inclusive and getHeight()-1 inclusive
Returns:
boolean indicating whether the target cell is in bounds of this Minesweeper board
See Also:
inBounds(Point)

inBounds

public boolean inBounds(java.awt.Point p)
Returns boolean indicating whether the target cell is in bounds of this Minesweeper board

Parameters:
p - coordinates of the target cell; between (0,0) inclusive and (getWidth()-1, getHeight()-1) inclusive
Returns:
boolean indicating whether the target cell is in bounds of this Minesweeper board
See Also:
inBounds(int, int)

getCount

public int getCount(int x,
                    int y)
Returns the number of mines surrounding the target cell. The return value is undefined if either inBounds(int, int) of isOpened(int, int) return false for the target cell.

Parameters:
x - The x coordinate of the target cell
y - The y coordinate of the target cell
Returns:
The count of the surrounding mines; undefined if either inBounds(int, int) of isOpened(int, int) return false for the target cell
See Also:
getCount(Point), isOpened(int, int), inBounds(int, int)

getCount

public int getCount(java.awt.Point p)
Returns the number of mines surrounding the target cell. The return value is undefined if either inBounds(Point) of isOpened(Point) return false for the target cell.

Parameters:
p - The x-y-coordinates of the target cell
Returns:
The count of the surrounding mines; undefined if either inBounds(Point) of isOpened(Point) return false for the target cell
See Also:
getCount(int, int), isOpened(Point), inBounds(Point)

isOpened

public boolean isOpened(int x,
                        int y)
Returns a boolean indicating whether the target cell has been opened yet. The return value is undefined if inBounds(int, int) returns false for the target cell.

Parameters:
x - The x-coordinate of the target cell
y - The y-coordinate of the target cell
Returns:
boolean indicating whether the target cell has been opened; undefined if inBounds(int, int) returns false for the target cell
See Also:
isOpened(Point), inBounds(int, int)

isOpened

public boolean isOpened(java.awt.Point p)
Returns a boolean indicating whether the target cell has been opened yet. The return value is undefined if inBounds(Point) returns false for the target cell.

Parameters:
p - The x-y-coordinates of the target cell
Returns:
boolean indicating whether the target cell has been opened; undefined if inBounds(Point) returns false for the target cell
See Also:
isOpened(int, int), inBounds(Point)

getNeighbors

public java.util.Set getNeighbors(int x,
                                  int y)
Returns an immutable set containing Point objects representing the neighbors of the target cell. Usually the size of the Set will be 8 elements, but cells on the sides and corners of the map will return smaller sets. Since this set is immutable, any method that would normally modify the Set will throw an exception. The return value is undefined if inBounds(int, int) returns false for the target cell.

Parameters:
x - The x-coordinate of the target cell
y - The y-coordinate of the target cell
Returns:
immutable set containing Point objects representing the neighbors of the target cell; undefined if inBounds(int, int) returns false for the target cell
See Also:
getNeighbors(Point), inBounds(int, int)

getNeighbors

public java.util.Set getNeighbors(java.awt.Point p)
Returns an immutable set containing Point objects representing the neighbors of the target cell. Usually the size of the Set will be 8 elements, but cells on the sides and corners of the map will return smaller sets. Since this set is immutable, any method that would normally modify the Set will throw an exception. The return value is undefined if inBounds(Point) returns false for the target cell.

Parameters:
p - The x-y-coordinates of the target cell
Returns:
immutable set containing Point objects representing the neighbors of the target cell; undefined if inBounds(Point) returns false for the target cell
See Also:
getNeighbors(int, int), inBounds(Point)

getFringe

public java.util.Set getFringe()
Returns an immutable set containing Point objects representing the fringe of the Minesweeper board. The fringe consists of all cells that are not opened but are neighbors of an opened cell. Since this set is immutable, any method that would normally modify the Set will throw an exception.

Returns:
immutable set containing Point objects representing the fringe of the board

getEdge

public java.util.Set getEdge()
Returns an immutable set containing Point objects representing the edge of the Minesweeper board. The edge consists of all cells that are already opened but have neighbors that are not opened. Since this set is immutable, any method that would normally modify the Set will throw an exception.

Returns:
immutable set containing Point objects representing the edge of the board

getLastMove

public java.awt.Point getLastMove()
Returns the move that was last made on the board; returns null if no moves have been made

Returns:
the move that was last made on the board; null if no moves have been made

getOpenedCount

public int getOpenedCount()
Returns the number of opened cells on the board; the return value will be in the range of 0 inclusive and getWidth() * getHeight() inclusive.

Returns:
the number of opened cells on the board

print

public void print()
Prints a text representation of the board to System.out