|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectdd.util.FreewaySupport
Support utilities for the Freeway game. This is a high-level interface for interacting with the game board for the game Freeway. It encapsulates most of the game logic for the Freeway game, including scoring, finding road attributes, and other relevant functions.
Freeway is a consensus building game for two to six players. Each player adopts a role and tries to build a road from the southern end to the northern end of the map minimizing that player's score. Depending on the things that must be demolished to make room for the road, the player's score will be impacted in different ways.
This class is made up entire of static methods. No state is cached to make these methods as general-purpose as possible.
Field Summary | |
static java.util.HashMap |
playerLookup
A mapping from player names to core table rows. |
static int[][] |
scoreTable
The matrix used to compute player scores. |
Constructor Summary | |
FreewaySupport()
|
Method Summary | |
static java.util.List |
allRoads(MapCell cell)
Returns a list of players who have a road in this cell. |
static java.lang.String |
hasRoad(MapCell cell)
Returns the first player encountered who has a road in this cell. |
static boolean |
hasRoad(MapCell cell,
java.lang.String player)
Returns whether a player has a road in this cell. |
static Map |
readMap(java.lang.String fileName)
Creates a new map from a text file representation. |
static float |
scoreForPlayer(java.lang.String player,
float residential,
float business,
float hills,
float historic,
float dig)
Computes the score for a player given the makeup of a cell. |
static int |
scoreForPlayer(java.lang.String player,
Map map)
Compute the total score for a player in the current game state. |
static float |
scoreForPlayer(java.lang.String player,
MapCell cell,
Layer features)
Compute the score for a player in the given cell. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final int[][] scoreTable
The score for a player is computed by looking at a cell and multiplying the number of features of a type by the score for that feature type for the player. This table presentation should make it easy to add new land types, new roles, or modify existing roles.
public static java.util.HashMap playerLookup
Constructor Detail |
public FreewaySupport()
Method Detail |
public static float scoreForPlayer(java.lang.String player, float residential, float business, float hills, float historic, float dig)
player
- name of the player's roleresidential
- count of residences in the cellbusiness
- count of businesses in the cellhills
- count of hills in the cellhistoric
- count of historic sites in the celldig
- count of dig sites in the cell
public static float scoreForPlayer(java.lang.String player, MapCell cell, Layer features)
player
- name of the player's rolecell
- Map cell to testfeatures
- layer upon which features for land uses are located
public static int scoreForPlayer(java.lang.String player, Map map)
player
- name of the player's rolemap
- current Freeway map
public static java.lang.String hasRoad(MapCell cell)
null
if a cell is empty, and a non-null string of the first role that has a
road in the cell. This returns a boolean because knowing who has a
road in a cell is often as required as determining if it is empty.
cell
- cell to test for a road
null
if the cell contains no roads.public static boolean hasRoad(MapCell cell, java.lang.String player)
cell
- cell in which to search for the roadplayer
- name of the role to search
true
if the player has a road in this cell,
false
otherwise.public static java.util.List allRoads(MapCell cell)
cell
- cell to search for roads
public static Map readMap(java.lang.String fileName) throws java.io.IOException
fileName
- name of the file to read
java.io.IOException
- if an error occurs when reading the file
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |