All Packages Class Hierarchy This Package Previous Next Index
Interface busrider.Strategy
- public interface Strategy
To participate in the game, one writes a class which implements
this interface. (Alternatively, one can extend the StrategyAdapter
class, which provides simple but legal implementations of each
method.) That class must have a default constructor.
Each Player in the game has an associated Strategy.
The conductor calls this interface when:
- a game begins (
startGame
),
- the game ends (
endGame
),
- any player becomes fast (
playerIsFast
),
- any route is bought or sold (
transferRoute
),
- another player rides this player's routes, and thereby pays a
fare (
receiveFare
).
- the player's turn begins (
startTurn
),
- the player's turn ends (
endTurn
),
- the player may select a destination
(
chooseDestination
),
- the player arrives at his destination terminus
(
youArrived
),
- the Strategy may select the player's Segment, a part of the
routes along which the player travels
(
chooseSegment
),
- the Strategy may choose a Route for the player to sell
(
youMustSell
),
- the player goes bankrupt, and therefore leaves the game
(
youAreBroke
),
Some of the methods return values. It is always legal to return
null
, after which the conductor will make a selection on
behalf of the player. This may be a poor choice, but allows one to
participate with minimal effort. (Indeed, this is what StrategyAdapter
does.) Throwing an exception out of an interface method has the same
effect.
Since route selection may be somewhat difficult for the
programmer, the conductor tries to make good Segment choices.
Other decisions of the conductor are likely to be abysmal, and are
documented below.
- See Also:
- StrategyAdapter, Player
Method Index
-
beginTurn()
- called at the start of the player's turn.
-
chooseDestination(Junction, Junction)
- called to let the Strategy choose one of two Destinations.
-
chooseSegment(int)
- called whenever it is the player's turn to move, and the Strategy
may choose a Segment to follow.
-
endGame(int)
- indicates that the game has ended.
-
endTurn()
- called at the end of the player's turn.
-
playerIsFast(int)
- called whenever a player buys a Right-of-way.
-
receiveFare(int, int)
- called whenever someone pays this player for riding on his routes.
-
startGame(Game, PlayerView)
- indicates that a game is starting.
-
transferRoute(int)
- called whenever a route changes ownership, after the change.
-
youAreBroke()
- called near the end of a player's turn, when his cash is
negative, and the player has nothing to sell.
-
youArrived()
- called to inform the player of his arrival at his destination.
-
youMustSell()
- called near the end of a player's turn, when his cash is
negative.
Methods
startGame
public abstract void startGame(Game ga,
PlayerView me)
- indicates that a game is starting.
The Strategy can keep a reference to the Game parameter,
or can fetch it by
Game.getInstance()
.
One can can inspect the Game, to see the Board, the number of
players, their locations, etc.
The PlayerView parameter is a view to the Strategy's player.
This differs from the PlayerViews obtainable from the Game,
in that one can always see one's own cash.
We recommend that the Strategy keep that reference: it is the
only way to see one's cash!
endGame
public abstract void endGame(int winner)
- indicates that the game has ended.
winner
is the player-index of the winner, or -1
if no player has won.
playerIsFast
public abstract void playerIsFast(int playerIndex)
- called whenever a player buys a Right-of-way.
playerIndex
specifies which player bought.
transferRoute
public abstract void transferRoute(int routeIndex)
- called whenever a route changes ownership, after the change.
routeIndex
specifies which route.
The Game can be queried to see the new owner.
receiveFare
public abstract void receiveFare(int fromwhom,
int payment)
- called whenever someone pays this player for riding on his routes.
The player's cash is already updated.
fromwhom
is the rider's player-index.
beginTurn
public abstract void beginTurn()
- called at the start of the player's turn.
endTurn
public abstract void endTurn()
- called at the end of the player's turn.
chooseDestination
public abstract Junction chooseDestination(Junction term1,
Junction term2)
- called to let the Strategy choose one of two Destinations.
The Strategy will return one of the two parameters.
(Otherwise the first is selected.)
youArrived
public abstract Purchase youArrived()
- called to inform the player of his arrival at his destination.
The bank has already credited his cash.
The Strategy will return a Purchase reference, or null
(meaning purchase nothing).
If the purchase is legal, it is made; otherwise nothing is
purchased.
chooseSegment
public abstract Segment chooseSegment(int roll)
- called whenever it is the player's turn to move, and the Strategy
may choose a Segment to follow.
This routine is called even if there is only one choice.
roll
indicates the remainder of the player's dice
roll for this turn.
The Strategy may return null or an invalid Segment, in which
case the conductor will make a legal choice (and probably a
reasonable one).
youMustSell
public abstract Route youMustSell()
- called near the end of a player's turn, when his cash is
negative. This routine is called even if the player has only one
route to sell.
The Strategy will return the index of a route, indicating which
route to sell. If it returns null, or tries to sell a route which
the player does not own, the conductor will choose a route.
youAreBroke
public abstract void youAreBroke()
- called near the end of a player's turn, when his cash is
negative, and the player has nothing to sell. The player has
therefore lost. The player will not have any more turns, and the
Strategy will not be informed of other player's activities.
It will receive its last
endTurn
call, and an
endGame
call.
All Packages Class Hierarchy This Package Previous Next Index