dd.util
Class FishbanksSupport

java.lang.Object
  extended bydd.util.FishbanksSupport
All Implemented Interfaces:
FishbanksConstants

public class FishbanksSupport
extends java.lang.Object
implements FishbanksConstants

Support utlities for the Fishbanks game. This is a high-level interface for interacting with the game board for the game Fishbanks. It encapsulates most of the game luck, such as scoring, boat manipulation, bank balance, and simulating the fish population.

Fishbanks is a systems-thinking game created by Dennis Meadows. It is desgined to get players to think about dynamic systems and to understand the classic "tragedy of the commons" problem. Teams play fishing companies that want to maximize their profits. Teams can buy boats, deploy them in the ocean, and catch fish. Depending on the actions of the team, the number of fish in the ocean will react accordingly, causing the fish population to grow and shrink.

Author:
Eric Scharff

Field Summary
static double CATCH_OFFSET
           
static double CATCH_VARIANCE
           
 
Fields inherited from interface dd.util.FishbanksConstants
BOAT, COASTAL_WATERS, DEEP_OCEAN, HARBOR, LAND, TYPE
 
Constructor Summary
FishbanksSupport()
           
 
Method Summary
static void addBoat(MapCell cell, int teamNum)
          Adds a boat owned by this team to the map in the cell specified.
static void doOneTurn(Map map)
          Do a single turn in the fishbanks game.
static int getBoat(MapCell cell)
          Returns the owner of the boat in the current cell.
static int getBoatCount(Map map)
          Returns the number of boats in the simulation.
static int getBoatCount(Map map, java.lang.String region)
          Counts the number of boats in a part of the ocean.
static int getBoatCount(Map map, java.lang.String region, int teamNum)
          Counts the number of boats owned by a team in a given part of the ocean.
static java.util.Iterator getBoatIterator(Map map, java.lang.String region)
           
static java.lang.String getCellType(MapCell cell)
          Returns the "type" of the cell.
static int getExtraBoats(Map map, int teamNum)
          Returns the number of unallocated boats for a team.
static int getFishCaught(Map map, int teamNum, java.lang.String region)
           
static int getNumTeams(Map map)
           
static int getTeamBoats(Map map, int teamNum)
          Returns the number of boats owned by a team.
static float getTeamMoney(Map map, int teamNum)
          Returns the team's current bank balance
static java.lang.String getTeamName(Map map, int teamNum)
          Return the descriptive name for a team.
static boolean hasBoat(MapCell cell)
          Returns true is the map cell contains a boat.
static boolean hasBoat(MapCell cell, int teamNum)
          Returns true if the team owns a boat in this cell.
static void removeBoat(MapCell cell)
          Removes a boat from the map.
static void setNumTeams(Map map, int numTeams)
           
static void setTeamBoats(Map map, int teamNum, int numBoats)
          Sets the number of boats owned by a team.
static void setTeamMoney(Map map, int teamNum, float money)
          Sets the team's bank balance
static void setTeamName(Map map, int teamNum, java.lang.String teamName)
          Sets the descriptive name for a team.
static void startupMap(Map map, int numTeams, float startingBalance, int coastalWaterFish, int deepOceanFish)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CATCH_VARIANCE

public static final double CATCH_VARIANCE
See Also:
Constant Field Values

CATCH_OFFSET

public static final double CATCH_OFFSET
See Also:
Constant Field Values
Constructor Detail

FishbanksSupport

public FishbanksSupport()
Method Detail

startupMap

public static void startupMap(Map map,
                              int numTeams,
                              float startingBalance,
                              int coastalWaterFish,
                              int deepOceanFish)

hasBoat

public static boolean hasBoat(MapCell cell)
Returns true is the map cell contains a boat. If the cell contains a boat owned by any team, this method returns true.

Parameters:
cell - Map cell to search for a boat
Returns:
true if the cell contains any boat, false otherwise

hasBoat

public static boolean hasBoat(MapCell cell,
                              int teamNum)
Returns true if the team owns a boat in this cell. If the cell contains a boat and that boat is owned by the team specified, this method returns true.

Parameters:
cell - Map cell to search for a boat
teamNum - team who owns the boat
Returns:
true if the team owns the boat in this cell, false otherwise.

getBoat

public static int getBoat(MapCell cell)
Returns the owner of the boat in the current cell. This method returns the number of the team that owns the boat in this cell. Note that only one boat may be in a single cell at any time.

Parameters:
cell - Map cell to search for a boat
Returns:
the number of the team who owns the boat, -1 if the cell does not contain any boats.

addBoat

public static void addBoat(MapCell cell,
                           int teamNum)
Adds a boat owned by this team to the map in the cell specified. If the team has boats that are not yet allocated, this places a new boat on the map in the cell specified. If the team does not have any boats (or if this cell already has a boat) this method returns without taking any action.

Parameters:
cell - cell to add a boat
teamNum - the number of the team who will own the boat

removeBoat

public static void removeBoat(MapCell cell)
Removes a boat from the map. If there is a boat on the map, it is removed.

Parameters:
cell - Map cell from which the boat should be removed

getCellType

public static java.lang.String getCellType(MapCell cell)
Returns the "type" of the cell. A cell type is either LAND, COASTAL_WATERS, or DEEP_OCEAN.

Parameters:
cell - cell whose type should be determined
Returns:
the land type of this cell
See Also:
FishbanksConstants

getExtraBoats

public static int getExtraBoats(Map map,
                                int teamNum)
Returns the number of unallocated boats for a team. An extra boat is one that is not in the ocean or in the harbor. Examples would be boats temporarily removed, or boats just purchased at auction.

Parameters:
map - Map to search for team boats
teamNum - number of the team to query
Returns:
the number of unallocated boats for that team

getBoatCount

public static int getBoatCount(Map map)
Returns the number of boats in the simulation. This number includes all boats owned by all teams, regardless of whether they have been placed in the map.

Parameters:
map - Map to search
Returns:
the total number of boats owned by all teams

getBoatCount

public static int getBoatCount(Map map,
                               java.lang.String region)
Counts the number of boats in a part of the ocean. region is one of the constants HARBOR, COASTAL_WATERS, or DEEP_OCEAN. This method returns the current number of boats that are in these areas of the map.

Parameters:
map - Map to search for boats
region - cell type to search for boats
Returns:
the number of boats that are in cells of the specified type

getBoatIterator

public static java.util.Iterator getBoatIterator(Map map,
                                                 java.lang.String region)

getBoatCount

public static int getBoatCount(Map map,
                               java.lang.String region,
                               int teamNum)
Counts the number of boats owned by a team in a given part of the ocean. The region is one of the constants HARBOR, COASTAL_WATERS, or DEEP_OCEAN. This method returns the current number of boats owned by the team specified in those areas of the map.

Parameters:
map - Map to search for boats
region - cell type to search for boats
teamNum - number of the team that owns the boats
Returns:
the number of boats in that region of the ocean owned by the team specified

setNumTeams

public static void setNumTeams(Map map,
                               int numTeams)

getNumTeams

public static int getNumTeams(Map map)

getTeamBoats

public static int getTeamBoats(Map map,
                               int teamNum)
Returns the number of boats owned by a team.

Parameters:
map - Map in which this team is operating
teamNum - number of the team to query
Returns:
the number of boats owned by this team

setTeamBoats

public static void setTeamBoats(Map map,
                                int teamNum,
                                int numBoats)
Sets the number of boats owned by a team. This method does not do any additional accounting but merely changes the boats assigned to a team. One should be warned that if this number is reduced below the number of boats the team currently has in the ocean, there will be inconsistency in reporting. Boats should be removed before reducing this number.

Parameters:
map - game map
teamNum - number of the team
numBoats - new number of boats for this team
See Also:
removeBoat(dd.sim.MapCell)

getTeamMoney

public static float getTeamMoney(Map map,
                                 int teamNum)
Returns the team's current bank balance

Parameters:
map - game map
teamNum - number of the team
Returns:
the current bank balance of a team (may be negative)

setTeamMoney

public static void setTeamMoney(Map map,
                                int teamNum,
                                float money)
Sets the team's bank balance

Parameters:
map - game map
teamNum - number of the team
money - new bank balance for the team

getTeamName

public static java.lang.String getTeamName(Map map,
                                           int teamNum)
Return the descriptive name for a team. Internally, teams should be referred to by number, but this name provides a more descriptive name for users.

Parameters:
map - game map
teamNum - number of the team
Returns:
the descriptive name of the team

setTeamName

public static void setTeamName(Map map,
                               int teamNum,
                               java.lang.String teamName)
Sets the descriptive name for a team. Internally, teams are referred to by number. This name does not have any semantic value

Parameters:
map - game map
teamNum - number of the team
teamName - new descriptive name for the team

doOneTurn

public static void doOneTurn(Map map)
Do a single turn in the fishbanks game. This means that fishing boats catch fish, orders for boats are processed, bank balances are updated, and other bookkeeping is handled. This ends a current turn and provides data for the next turn.

Parameters:
map - game map

getFishCaught

public static int getFishCaught(Map map,
                                int teamNum,
                                java.lang.String region)