|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--inonit.domain.game.card.hearts.ai.AbstractIntelligence
An implementation of Intelligence
which includes a knowledge representation of the current Game
.
Generally, AbstractIntelligence
has final
implementations of informational methods
in Intelligence
which update its knowledge representation and then invoke xxxEvent()
methods to allow subclassers to update any additional knowledge representation that they have when events occur.
See the Intelligence
class for specifications on Intelligence
methods.
Inner classes inherited from class inonit.domain.game.card.hearts.Intelligence |
Intelligence.Environment, Intelligence.Game, Intelligence.Hand, Intelligence.Kitty, Intelligence.Pass, Intelligence.Play, Intelligence.Trick |
Fields inherited from interface inonit.domain.game.card.hearts.Intelligence |
RANDOM |
Constructor Summary | |
protected |
AbstractIntelligence()
Constructor used by subclasses. |
Method Summary | |
void |
cardPlayed(Intelligence.Play play)
Updates the Game object, and then invokes cardPlayedEvent . |
protected void |
cardPlayedEvent(int player,
Card card)
The default implementation of this method does nothing. |
void |
destroy()
Invokes destroyEvent . |
protected void |
destroyEvent()
The default implementation of this method does nothing. |
void |
exceptionThrown(java.lang.String stackTrace)
The default implementation of this method does nothing. |
void |
gameEnded()
Invokes gameEndedEvent , and then discards the Game object. |
protected void |
gameEndedEvent(Game game)
The default implementation of this method does nothing. |
void |
gameStarting(Intelligence.Game game)
Creates a Game object which is associated with the game argument,
and then invokes gameStartingEvent . |
protected void |
gameStartingEvent(Intelligence.Game configuration)
The default implementation of this method does nothing. |
protected CardArray |
getCards()
Returns the Card s currently in this AbstractIntelligence 's hand. |
protected Intelligence.Environment |
getEnvironment()
Returns an object which contains services provided by, and information about, the environment in which this AbstractIntelligence is running. |
protected Game |
getGame()
Returns an object representing the current Game . |
protected Hand |
getHand()
Returns a object representing the current Hand . |
protected CardArray |
getLegalPlays()
Returns a CardArray containing the Card s which would be legal to play if this
AbstractIntelligence is playing next. |
CardArray |
getPass()
Invoked to ask this Intelligence for Card s to pass to another player. |
abstract CardArray |
getPass(int numberToPass)
Should return a CardArray containing the number of cards indicated by the numberToPass
argument. |
abstract Card |
getPlay()
Should return the Card this AbstractIntelligence wishes to play. |
protected Rules |
getRules()
Returns an object representing the rules of the current game. |
protected int[] |
getScore()
Returns the current score of the Game . |
protected Storage |
getStorage()
Returns a Storage object associated with the Intelligence.Environment.Storage object from
this AbstractIntelligence 's Intelligence.Environment . |
protected Trick |
getTrick()
Returns an object representing the current Trick . |
protected Trick[] |
getTricks()
Returns an array of objects representing of the previous Trick s in this hand, not including the current
Trick . |
protected int |
getValue(Card card)
Returns the point (scoring) value (as determined by Rules.getValue(CardArray)
of the given Card in the current Game . |
protected int |
getValue(CardArray cards)
Returns the point (scoring) value (as determined by Rules.getValue
of the given CardArray in the current Game . |
protected void |
handDealtEvent(CardArray hand)
The default implementation of this method does nothing. |
void |
handEnded()
Updates the Game object, and then invokes handScoredEvent . |
protected void |
handScoredEvent(int[] scores)
The default implementation of this method does nothing. |
void |
handStarting(Intelligence.Hand hand)
Updates the Game object, and then invokes
handDealtEvent . |
void |
initialize(Intelligence.Environment environment)
Informs this Intelligence that it has been instantiated, and provides it with an
Environment from which it can obtain various services. |
protected void |
initializeEvent(Intelligence.Environment environment)
The default implementation of this method does nothing. |
protected boolean |
isHigher(Card one,
Card two)
Returns whether the first Card is higher than the second, by Rank only. |
protected boolean |
isHigher(Card card,
Rank rank)
Returns whether the given Card is higher than the given Rank . |
protected boolean |
isLower(Card one,
Card two)
Returns whether the first Card is lower than the second, by Rank only. |
protected boolean |
isLower(Card card,
Rank rank)
Returns whether the given Card is lower than the given Rank . |
protected boolean |
isSameSuit(Card one,
Card two)
Returns whether the given two Card s are of the same suit. |
void |
kittyTaken(Intelligence.Kitty kitty)
Updates the Game object, and then invokes tookKittyEvent . |
protected void |
log(java.lang.Object o)
Write a log message to the game log; the log message will indicate the player responsible for writing it. |
void |
passIgnored(java.lang.String reason)
The default implementation of this method does nothing. |
protected int |
players()
Returns the number of players in the current Game . |
void |
playIgnored(java.lang.String reason)
The default implementation of this method does nothing. |
void |
receivedPass(Intelligence.Pass pass)
Updates the Game object, and then invokes
receivedPassEvent . |
protected void |
receivedPassEvent(Pass pass)
The default implementation of this method does nothing. |
void |
sentPass(Intelligence.Pass pass)
Updates the Game object, and then invokes
sentPassEvent . |
protected void |
sentPassEvent(Pass pass)
The default implementation of this method does nothing. |
protected void |
tookKittyEvent(CardArray kitty)
The default implementation of this method does nothing. |
protected void |
tookKittyEvent(int player,
int size)
The default implementation of this method does nothing. |
void |
trickEnded()
Updates the Game object, and then invokes trickEndedEvent . |
protected void |
trickEndedEvent(int playerWhoTook)
The default implementation of this method does nothing. |
void |
trickStarting(Intelligence.Trick trick)
Updates the Game object, and then invokes trickStartingEvent . |
protected void |
trickStartingEvent(int playerToLead)
The default implementation of this method does nothing. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
protected AbstractIntelligence()
Method Detail |
protected void log(java.lang.Object o)
o
- The object to write to the log.public final void initialize(Intelligence.Environment environment)
Intelligence
Intelligence
that it has been instantiated, and provides it with an
Environment
from which it can obtain various services.initialize
in interface Intelligence
inonit.domain.game.card.hearts.Intelligence
environment
- An Intelligence.Environment
representing external information and services.public final void gameStarting(Intelligence.Game game)
Game
object which is associated with the game
argument,
and then invokes gameStartingEvent
.gameStarting
in interface Intelligence
inonit.domain.game.card.hearts.Intelligence
game
- An Intelligence.Game
object containing information
about the game which is starting.public final void handStarting(Intelligence.Hand hand)
Game
object, and then invokes
handDealtEvent
.handStarting
in interface Intelligence
inonit.domain.game.card.hearts.Intelligence
hand
- A Intelligence.Hand
containing information about the current hand, including the cards dealt to this
Intelligence
.public final void sentPass(Intelligence.Pass pass)
Game
object, and then invokes
sentPassEvent
.sentPass
in interface Intelligence
inonit.domain.game.card.hearts.Intelligence
pass
- A Pass
object containing information about what was passed, and to whom. Ordinarily,
what was passed will already be known by this Intelligence
, unless it timed out trying
to pass or returned an invalid pass from getPass
.public final void receivedPass(Intelligence.Pass pass)
Game
object, and then invokes
receivedPassEvent
.receivedPass
in interface Intelligence
inonit.domain.game.card.hearts.Intelligence
pass
- A Pass
object containing information about what was received, and from whom.public final void trickStarting(Intelligence.Trick trick)
Game
object, and then invokes trickStartingEvent
.trickStarting
in interface Intelligence
inonit.domain.game.card.hearts.Intelligence
trick
- A Trick
object which can provide information about the current trick.public final void cardPlayed(Intelligence.Play play)
Game
object, and then invokes cardPlayedEvent
.cardPlayed
in interface Intelligence
inonit.domain.game.card.hearts.Intelligence
play
- A Intelligence.Play
object containing information about who played the card, and what was played.public final void trickEnded()
Game
object, and then invokes trickEndedEvent
.trickEnded
in interface Intelligence
public final void kittyTaken(Intelligence.Kitty kitty)
Game
object, and then invokes tookKittyEvent
.kittyTaken
in interface Intelligence
inonit.domain.game.card.hearts.Intelligence
kitty
- A Kitty
object containing information about the kitty.public final void handEnded()
Game
object, and then invokes handScoredEvent
.handEnded
in interface Intelligence
public final void gameEnded()
gameEndedEvent
, and then discards the Game
object.gameEnded
in interface Intelligence
public final void destroy()
destroyEvent
.destroy
in interface Intelligence
public final CardArray getPass()
Intelligence
Intelligence
for Card
s to pass to another player. Should return a
CardArray
containing the Card
s from this Intelligence
's hand which it wishes to
pass.
Whether this method is invoked in hands which are hold hands -- i.e., hands in which the
Intelligence
would be passing to itself -- is unspecified.
If this method does not successfully return a valid pass, the following steps will take place:
passIgnored
will be invoked with an argument explaining why,Card
s will be selected from the Intelligence
's hand to make up the pass,
sentPass
will be invoked, with a Pass
object containing
information about the cards selected.getPass
in interface Intelligence
inonit.domain.game.card.hearts.Intelligence
CardArray
containing the Card
s which it wishes to pass.
Must not be null
. Must contain the number of Card
s specified by size
.
Must contain Card
s that were dealt to the Intelligence
in
handStarting
.public abstract CardArray getPass(int numberToPass)
CardArray
containing the number of cards indicated by the numberToPass
argument.
See Intelligence.getPass
for further information about this method, including specifications about when it will be invoked and what it must
return.
numberToPass
- The number of Card
s which should be in the CardArray
returned from this
method.CardArray
containing Card
s to pass to the Intelligence
(s) receiving
this pass.public abstract Card getPlay()
Card
this AbstractIntelligence
wishes to play. Information about the current
Game
, Hand
and Trick
can be accessed via getGame
, getHand
,
and getTrick
, respectively.
See
Intelligence.getPlay
for additional details on this method, including
specifications about when it will be invoked and what it must return.
getPlay
in interface Intelligence
Card
to play.public void passIgnored(java.lang.String reason)
passIgnored
in interface Intelligence
inonit.domain.game.card.hearts.Intelligence
reason
- A String
describing why getPass()
was ignored.public void playIgnored(java.lang.String reason)
playIgnored
in interface Intelligence
inonit.domain.game.card.hearts.Intelligence
reason
- A String
describing why getPlay()
was ignored.public void exceptionThrown(java.lang.String stackTrace)
exceptionThrown
in interface Intelligence
inonit.domain.game.card.hearts.Intelligence
stackTrace
- A String
containing the exception's stack trace.protected void initializeEvent(Intelligence.Environment environment)
environment
- An Intelligence.Environment
object containing information and services provided by
the environment in which this AbstractIntelligence
object is running.protected void gameStartingEvent(Intelligence.Game configuration)
configuration
- An Intelligence.Game
object containing information about the game which is
starting.protected void handDealtEvent(CardArray hand)
hand
- A CardArray
containing the Card
s dealt to this AbstractIntelligence
.protected void sentPassEvent(Pass pass)
pass
- A Pass
containing information about cards passed to other players.protected void receivedPassEvent(Pass pass)
pass
- A Pass
containing information about cards received from other
players.protected void trickStartingEvent(int playerToLead)
playerToLead
- The player index of the Intelligence
who will lead this trick.protected void cardPlayedEvent(int player, Card card)
player
- The player index of the Intelligence
which played a Card
.card
- The Card
which the Intelligence
played.protected void trickEndedEvent(int playerWhoTook)
playerWhoTook
- The player index of the Intelligence
which took the trick.protected void tookKittyEvent(int player, int size)
player
- The player index of the Intelligence
which took the kitty.size
- The number of cards in the kitty that player
took.protected void tookKittyEvent(CardArray kitty)
kitty
- A CardArray
containing the Card
s that were contained in the non-blind
(see Rules.isKittyBlind
) kitty.protected void handScoredEvent(int[] scores)
scores
- An array containing scores for the hand which just ended, by player index. scores[0]
will contain the score for this AbstractIntelligence
, scores[1]
will contain the
score for the Intelligence
to this AbstractIntelligence
's left, and so on.
These are not the total
scores for the game; total scores can be obtained via getScore
.protected void gameEndedEvent(Game game)
game
- The Game
which just ended. Information can be extracted from the Game
object in this
method if there is information which this AbstractIntelligence
wants to persist between
Game
s.protected void destroyEvent()
protected final boolean isHigher(Card one, Card two)
Card
is higher than the second, by Rank
only.one
- A Card
to compare. Must not be null
.two
- Another Card
to compare. Must not be null
.true
if one
has a higher Rank
than two
;
false
if their Rank
s are the same or if two
's is higher.protected final boolean isLower(Card one, Card two)
Card
is lower than the second, by Rank
only.one
- A Card
to compare. Must not be null
.two
- Another Card
to compare. Must not be null
.true
if one
has a lower Rank
than two
;
false
if their Rank
s are the same or if two
's is lower.protected final boolean isHigher(Card card, Rank rank)
Card
is higher than the given Rank
.card
- A Card
to compare. Must not be null
.rank
- A Rank
to which to compare it. Must not be null
.true
if card
's Rank
is higher than rank
;
false
otherwise.protected final boolean isLower(Card card, Rank rank)
Card
is lower than the given Rank
.card
- A Card
to compare. Must not be null
.rank
- A Rank
to which to compare it. Must not be null
.true
if card
's Rank
is lower than rank
;
false
otherwise.protected final boolean isSameSuit(Card one, Card two)
Card
s are of the same suit.one
- A Card
to compare. Must not be null
.two
- Another Card
to compare. Must not be null
.true
if one
and two
are of the same suit; false
otherwise.protected final CardArray getCards()
Card
s currently in this AbstractIntelligence
's hand.CardArray
containing the Card
s currently in this AbstractIntelligence
's
hand, or null
if no Hand
is in progress.protected final CardArray getLegalPlays()
CardArray
containing the Card
s which would be legal to play if this
AbstractIntelligence
is playing next.
If this AbstractIntelligence
is not playing next, returns the Card
s that
would be legal if this AbstractIntelligence
were playing next.CardArray
containing the Card
s in this AbstractIntelligence
's hand
which would be legal to play if this AbstractIntelligence
were playing next, or null
if no Hand
is in progress.protected final Intelligence.Environment getEnvironment()
AbstractIntelligence
is running.Intelligence.Environment
object which contains information about, and services provided by, this
AbstractIntelligence
's environment.protected final Storage getStorage()
Storage
object associated with the Intelligence.Environment.Storage
object from
this AbstractIntelligence
's Intelligence.Environment
.Storage
object which can be used for persistent storage by this
AbstractIntelligence
implementation.protected final Game getGame()
Game
.Game
, or null
if no Game
is in progress.protected final Rules getRules()
Rules
object containing information about the rules of the current Game
.protected final Hand getHand()
Hand
.Hand
, or null
if no Hand
is in progress.protected final Trick[] getTricks()
Trick
s in this hand, not including the current
Trick
.Trick
s in this Hand
, or null
if no Hand
is in progress.protected final Trick getTrick()
Trick
.Trick
, or null
if no Trick
is in progress.protected final int players()
Game
.
A Game
must be in progress.Game
.protected final int getValue(Card card)
Rules.getValue(CardArray)
of the given Card
in the current Game
.
A Game
must be in progress.card
- A Card
. Must not be null
.Card
in this Game
.protected final int getValue(CardArray cards)
Rules.getValue
of the given CardArray
in the current Game
.
A Game
must be in progress.cards
- A CardArray
. Must not be null
.Card
s in the given CardArray
in this Game
.protected final int[] getScore()
Game
.int[]
containing the current game score, with this AbstractIntelligence
's
score at index 0, the score of the Intelligence
to this AbstractIntelligence
's
left at index 1, and so on. Returns null
if no Game
is in progress.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |