public abstract class Player extends java.lang.Object implements Identity
Modifier and Type | Class and Description |
---|---|
protected class |
Player.MergeOption
Class describing a possible merge that a player could perform.
|
class |
Player.PlayerStats
Class holding various game related player statistics.
|
Modifier and Type | Field and Description |
---|---|
private boolean |
ai
If this player is an AI or not.
|
private double |
area
The total area claimed by this player.
|
private int |
id
The ID of this player.
|
private boolean |
local
Whether this player is local or acting as remote proxy.
|
private java.lang.String |
name
The name for this player.
|
private ScoreAnimation |
scoreAnimation
The score animation for this player.
|
protected GameState |
state
The game this player is associated with.
|
protected Player.PlayerStats |
stats
The game stats for this player.
|
private Theme.PlayerTheme |
theme
The theme for this player.
|
Modifier | Constructor and Description |
---|---|
protected |
Player(boolean local,
boolean ai,
java.lang.String name)
Constructs a new player instance.
|
Modifier and Type | Method and Description |
---|---|
void |
addArea(double area)
Adds some claimed area to this player.
|
boolean |
equals(java.lang.Object other) |
abstract boolean |
executeMove()
Executes a move for this player.
|
protected Player.MergeOption |
findBestMergeFrom(ConvexObject obj)
Finds the best possible merge (largest relative area gain)
from the given object for this player.
|
protected ConvexObject |
findLargestUnownedObject()
Finds the largest unowned object left in the
current game state.
|
protected ConvexObject |
findLargestUnownedObject(java.util.Comparator<java.lang.Double> comparator)
Finds the largest unowned object left in the
current game state according to the given comparator.
|
double |
getArea()
Gets the total area claimed by this player.
|
int |
getID()
Gets the ID of this entity.
|
java.lang.String |
getName()
Gets the name of this player.
|
PlayerProxy |
getProxy()
Gets a proxy for this player.
|
ScoreAnimation |
getScoreAnimation()
Getst the animation rendering the score for this player.
|
Player.PlayerStats |
getStats()
Gets the game stats for this player.
|
Theme.PlayerTheme |
getTheme()
Gets the color theme for this player.
|
int |
hashCode() |
protected boolean |
hasMergeFrom(ConvexObject obj)
Checks if there exists a possible valid merge from the
given object to any other object.
|
void |
init(GameState game,
Theme.PlayerTheme theme)
Initialises this player with the given game state and theme.
|
boolean |
isAI()
Checks if this player is an AI.
|
boolean |
isLocal()
Checks if this player is executing locally or
acting as a remote proxy.
|
boolean |
owns(ConvexObject obj)
Checks if this player owns the given object.
|
void |
removeArea(double area)
Removes some claimed area from this player.
|
void |
setID(int id)
Sets the ID of this entity.
|
protected void |
setName(java.lang.String name)
Sets the name of this player.
|
java.util.stream.Stream<ConvexObject> |
stream()
Streams all the objects owned by this player.
|
java.lang.String |
toString() |
private int id
protected GameState state
protected Player.PlayerStats stats
private ScoreAnimation scoreAnimation
private java.lang.String name
private boolean ai
private Theme.PlayerTheme theme
private double area
private boolean local
protected Player(boolean local, boolean ai, java.lang.String name)
local
- Whether this player is local or acting as remote proxy.ai
- Whether this player is an AI.name
- The name of this player.public void init(GameState game, Theme.PlayerTheme theme)
game
- The game this player is now a part of.theme
- The color theme for this player.public abstract boolean executeMove() throws java.lang.InterruptedException
java.lang.InterruptedException
- When the player was
interrupted while making its move. Signalling
that the game was aborted.public boolean isLocal()
public Theme.PlayerTheme getTheme()
public boolean isAI()
public void addArea(double area)
area
- The area that was claimed.public void removeArea(double area)
area
- The area to remove.public double getArea()
public java.lang.String getName()
public boolean owns(ConvexObject obj)
obj
- The object to check.public ScoreAnimation getScoreAnimation()
public java.util.stream.Stream<ConvexObject> stream()
protected ConvexObject findLargestUnownedObject()
null
if there are no unowned
object left in the game.protected ConvexObject findLargestUnownedObject(java.util.Comparator<java.lang.Double> comparator)
comparator
- The comparator to use to compare object sizes.
null
if there are no unowned
object left in the game.protected void setName(java.lang.String name)
name
- The new player name.protected boolean hasMergeFrom(ConvexObject obj)
obj
- The object to check merges for.protected Player.MergeOption findBestMergeFrom(ConvexObject obj)
obj
- The object to check from.null
if there are no possible merges left in the game.public PlayerProxy getProxy()
public Player.PlayerStats getStats()
public int hashCode()
hashCode
in class java.lang.Object
public boolean equals(java.lang.Object other)
equals
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object
public int getID()
Identity