Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

Player Class Reference

#include <Player.h>

Inheritance diagram for Player:

Inheritance graph
[legend]
Collaboration diagram for Player:

Collaboration graph
[legend]
List of all members.

Public Methods

 Player (ActHandler *a, WorldModel *wm, ServerSettings *ss, PlayerSettings *cs, Formations *fs, char *strTeamName, double dVersion, int iReconnect=-1)
VecPosition getStrategicPosition (int iPlayer=-1)
void mainLoop ()
void deMeer5 ()
void deMeer5_goalie ()
void handleStdin ()
void showStringCommands (ostream &out)
bool executeStringCommand (char *str)
void test_only_update ()
bool shallISaySomething ()
bool amIAgentToSaySomething ()
SoccerCommand sayWorldStatus ()

Private Methods

void goalieMainLoop ()
void defenderMainLoop ()
void midfielderMainLoop ()
void attackerMainLoop ()

Private Attributes

Formationsformations
bool bContLoop
int m_lastSay

Detailed Description

This class is a superclass from BasicPlayer and contains a more sophisticated decision procedure to determine the next action.

Definition at line 54 of file Player.h.


Constructor & Destructor Documentation

Player::Player ActHandler   act,
WorldModel   wm,
ServerSettings   ss,
PlayerSettings   ps,
Formations   fs,
char *    strTeamName,
double    dVersion,
int    iReconnect = -1
 

This is the constructor the Player class and calls the constructor of the superclass BasicPlayer.

Parameters:
act  ActHandler to which the actions can be sent
wm  WorldModel which information is used to determine action
ss  ServerSettings that contain parameters used by the server
ps  PlayerSettings that contain parameters important for the client
strTeamName  team name of this player
dVersion  version this basicplayer corresponds to
iReconnect  integer that defines player number (-1 when new player)

Definition at line 58 of file Player.C.

References BasicPlayer::ACT, bContLoop, formations, Formations::getPlayerInFormation(), Formations::getPlayerType(), m_lastSay, MAX_MSG, BasicPlayer::PS, PT_GOALKEEPER, ActHandler::sendMessage(), WorldModel::setTeamName(), BasicPlayer::SS, and BasicPlayer::WM.


Member Function Documentation

bool Player::amIAgentToSaySomething  
 

This method returns a boolean indicating whether I should communicate my world model to the other agents. This depends on the last sent message and a simple utility function that determines whether I am best positioned on the field.

Returns:
boolean indicating whether I should communicate my world model.

Definition at line 665 of file Player.C.

References WorldModel::getBallPos(), WorldModel::getPlayerNumber(), VecPosition::getX(), VecPosition::getY(), PITCH_LENGTH, and BasicPlayer::WM.

Referenced by shallISaySomething().

void Player::attackerMainLoop   [private]
 

This is the main decision loop for an agent.

Definition at line 167 of file Player.C.

References deMeer5().

Referenced by mainLoop().

void Player::defenderMainLoop   [private]
 

This is the main decision loop for a defender.

Definition at line 155 of file Player.C.

References deMeer5().

Referenced by mainLoop().

void Player::deMeer5  
 

This method is the first complete simple team and defines the actions taken by all the players on the field (excluding the goalie). It is based on the high-level actions taken by the simple team FC Portugal that it released in 2000. The players do the following:

  • if ball is kickable kick ball to goal (random corner of goal)
  • else if i am fastest player to ball and no opponent can intercept ball intercept the ball
  • else move to strategic position based on your home position and pos ball

Definition at line 182 of file Player.C.

References BasicPlayer::ACT, BasicPlayer::alignNeckWithBody(), CMD_DASH, CMD_ILLEGAL, CMD_TURNNECK, SoccerCommand::commandType, SoccerCommand::dPower, formations, FT_INITIAL, FT_STANDARD, WorldModel::getAgentGlobalPosition(), WorldModel::getAgentObjectType(), WorldModel::getAgentStamina(), PlayerSettings::getBallConfThr(), WorldModel::getBallPos(), ServerSettings::getBallSpeedMax(), WorldModel::getConfidence(), WorldModel::getCurrentCycle(), VecPosition::getDistanceTo(), WorldModel::getFastestInSetTo(), Formations::getFormation(), ServerSettings::getGoalWidth(), PlayerSettings::getPlayerWhenToTurnAngle(), ServerSettings::getRecoverDecThr(), Stamina::getRecovery(), WorldModel::getRelativeAngle(), Stamina::getStamina(), ServerSettings::getStaminaMax(), getStrategicPosition(), VecPosition::getX(), BasicPlayer::intercept(), WorldModel::isBallKickable(), WorldModel::isBeforeKickOff(), WorldModel::isDeadBallThem(), BasicPlayer::kickTo(), BasicPlayer::moveToPos(), OBJECT_BALL, OBJECT_SET_TEAMMATES, PITCH_LENGTH, BasicPlayer::PS, ActHandler::putCommandInQueue(), BasicPlayer::searchBall(), Formations::setFormation(), BasicPlayer::SS, BasicPlayer::teleportToPos(), BasicPlayer::turnBodyToObject(), BasicPlayer::turnBodyToPoint(), BasicPlayer::turnNeckToObject(), and BasicPlayer::WM.

Referenced by attackerMainLoop(), defenderMainLoop(), and midfielderMainLoop().

void Player::deMeer5_goalie  
 

This method is a simple goalie based on the goalie of the simple Team of FC Portugal. It defines a rectangle in its penalty area and moves to the position on this rectangle where the ball intersects if you make a line between the ball position and the center of the goal. If the ball can be intercepted in the own penalty area the ball is intercepted and catched.

Definition at line 278 of file Player.C.

References BasicPlayer::ACT, BasicPlayer::alignNeckWithBody(), AngDeg, BasicPlayer::catchBall(), CMD_MOVE, formations, FT_INITIAL, WorldModel::getAgentGlobalBodyAngle(), WorldModel::getAgentGlobalPosition(), WorldModel::getAgentObjectType(), PlayerSettings::getBallConfThr(), WorldModel::getBallPos(), WorldModel::getConfidence(), VecPosition::getDistanceTo(), WorldModel::getFastestInSetTo(), Formations::getFormation(), SoccerTypes::getGlobalPositionFlag(), BasicPlayer::getInterceptionPointBall(), Line::getIntersection(), WorldModel::getNrInSetInCircle(), PlayerSettings::getPlayerWhenToTurnAngle(), WorldModel::getPlayMode(), WorldModel::getSide(), getStrategicPosition(), WorldModel::getTimeSinceLastCatch(), VecPosition::getX(), VecPosition::getY(), BasicPlayer::intercept(), WorldModel::isBallCatchable(), WorldModel::isBallKickable(), WorldModel::isBeforeKickOff(), WorldModel::isCornerKickThem(), WorldModel::isFreeKickThem(), WorldModel::isFreeKickUs(), WorldModel::isGoalKickUs(), WorldModel::isInOwnPenaltyArea(), VecPosition::isLeftOf(), VecPosition::isRightOf(), BasicPlayer::kickTo(), SoccerCommand::makeCommand(), Line::makeLineFromTwoPoints(), BasicPlayer::moveToPos(), OBJECT_BALL, OBJECT_GOAL_L, OBJECT_GOAL_R, OBJECT_SET_OPPONENTS, OBJECT_SET_PLAYERS, PENALTY_AREA_LENGTH, PENALTY_AREA_WIDTH, PITCH_LENGTH, PM_PLAY_ON, BasicPlayer::PS, ActHandler::putCommandInQueue(), BasicPlayer::searchBall(), Formations::setFormation(), VecPosition::setX(), SIDE_LEFT, SIDE_RIGHT, BasicPlayer::teleportToPos(), BasicPlayer::turnBodyToObject(), BasicPlayer::turnBodyToPoint(), BasicPlayer::turnNeckToObject(), and BasicPlayer::WM.

Referenced by goalieMainLoop().

bool Player::executeStringCommand char *    str
 

This method executes the command that is entered by the user. For the possible command look at the method showStringCommands.

Parameters:
str  string that is entered by the user
Returns:
true when command could be executed, false otherwise

Definition at line 512 of file Player.C.

References BasicPlayer::ACT, bContLoop, CMD_CATCH, CMD_CHANGEVIEW, CMD_DASH, CMD_ILLEGAL, CMD_KICK, CMD_MOVE, CMD_SAY, CMD_TURN, CMD_TURNNECK, SoccerCommand::commandType, SoccerCommand::dAngle, SoccerCommand::dPower, SoccerCommand::dX, SoccerCommand::dY, WorldModel::getAgentGlobalNeckAngle(), WorldModel::getAgentGlobalPosition(), WorldModel::getAgentObjectType(), WorldModel::getNrInSetInCone(), PlayerSettings::getPlayerWhenToTurnAngle(), SoccerTypes::getViewAngleFromStr(), SoccerTypes::getViewQualityFromStr(), Parse::gotoFirstNonSpace(), Parse::gotoFirstOccurenceOf(), SoccerCommand::iTimes, BasicPlayer::kickTo(), SoccerCommand::makeCommand(), OBJECT_SET_OPPONENTS, Parse::parseFirstDouble(), Parse::parseFirstInt(), WorldModel::predictNrCyclesToPoint(), BasicPlayer::PS, ActHandler::putCommandInQueue(), ActHandler::sendMessage(), WorldModel::show(), GenericValues::show(), WorldModel::showQueuedCommands(), showStringCommands(), BasicPlayer::SS, SoccerCommand::str, SoccerCommand::va, SoccerCommand::vq, and BasicPlayer::WM.

Referenced by handleStdin().

VecPosition Player::getStrategicPosition int    iPlayer = -1
 

This method determine the strategic position for the specified player. This is done using the Formations class. In this class all information about the current formation, player number in formation and other specific values are stored. The strategic position is based on the position of the ball. If the confidence in the position of the ball is lower than the threshold defined in PlayerSettings, it is assumed that the ball is at position (0,0).

Parameters:
iPlayer  role in formation for which strategic position should be returnd. With default value is -1 it is assumed that the strategic position of the agent itself should be returned.
Returns:
VecPosition strategic position for player 'iPlayer'

Definition at line 434 of file Player.C.

References formations, PlayerSettings::getBallConfThr(), WorldModel::getBallPos(), WorldModel::getConfidence(), WorldModel::getOffsideX(), Formations::getPlayerInFormation(), Formations::getStrategicPosition(), VecPosition::getX(), WorldModel::isGoalKickThem(), WorldModel::isOffsideUs(), min(), OBJECT_BALL, PENALTY_X, BasicPlayer::PS, and BasicPlayer::WM.

Referenced by deMeer5(), and deMeer5_goalie().

void Player::goalieMainLoop   [private]
 

This is the main decision loop for the goalkeeper.

Definition at line 149 of file Player.C.

References deMeer5_goalie().

Referenced by mainLoop().

void Player::handleStdin  
 

This method listens for input from the keyboard and when it receives this input it converts this input to the associated action. See showStringCommands for the possible options. This method is used together with the SenseHandler class that sends an alarm to indicate that a new command can be sent. This conflicts with the method in this method that listens for the user input (fgets) on Linux systems (on Solaris this isn't a problem). The only known method is to use the flag SA_RESTART with this alarm function, but that does not seem to work under Linux. If each time the alarm is sent, this gets function unblocks, it will cause major performance problems. This function should not be called when a whole match is played!

Definition at line 468 of file Player.C.

References executeStringCommand(), and MAX_MSG.

Referenced by stdin_callback().

void Player::mainLoop  
 

This is the main loop of the agent. This method calls the update methods of the world model after it is indicated that new information has arrived. After this, the correct main loop of the player type is called, which puts the best soccer command in the queue of the ActHandler.

Definition at line 92 of file Player.C.

References BasicPlayer::ACT, attackerMainLoop(), bContLoop, defenderMainLoop(), formations, WorldModel::getCurrentCycle(), WorldModel::getCurrentTime(), WorldModel::getPlayerNumber(), Formations::getPlayerType(), WorldModel::getTimeLastSeeMessage(), goalieMainLoop(), WorldModel::iNrHoles, WorldModel::iNrOpponentsSeen, WorldModel::iNrTeammatesSeen, m_lastSay, midfielderMainLoop(), PT_ATTACKER, PT_ATTACKER_WING, PT_DEFENDER_SWEEPER, PT_DEFENDER_WING, PT_GOALKEEPER, PT_ILLEGAL, PT_MIDFIELDER_CENTER, PT_MIDFIELDER_WING, sayWorldStatus(), ActHandler::sendCommandDirect(), ActHandler::sendCommands(), shallISaySomething(), WorldModel::updateAll(), WorldModel::waitForNewInformation(), and BasicPlayer::WM.

Referenced by main().

void Player::midfielderMainLoop   [private]
 

This is the main decision loop for a midfielder.

Definition at line 161 of file Player.C.

References deMeer5().

Referenced by mainLoop().

SoccerCommand Player::sayWorldStatus  
 

This method says the world status. This message is encoded to make sure the other teammates know which is the cycle of the message, the author of the message and that the message is originated from a teammate and not from an opponent. The world status is the abs pos and velocity of the author of the message and the ball and the global positions of all the known teammates and the opponents. The format is as follows (*=encoding): (say ***** my_x my_y my_vel_x my_vel_y (ball_x ball_y ball_vel_x ball_vel_y ball_conf) (team_nr pos_x pos_y conf ...) (opp_nr pos_x pos_y conf ...)) Some players in the worldmodel are known by player number, some not. Players of which the player number is not sure are located at the end of the message and have the nr -1.

Returns:
SoccerCommand which contains say message with world status

Definition at line 707 of file Player.C.

References CMD_SAY, WorldModel::getAgentGlobalPosition(), WorldModel::getAgentGlobalVelocity(), PlayerSettings::getBallConfThr(), WorldModel::getBallPos(), WorldModel::getConfidence(), WorldModel::getCurrentCycle(), WorldModel::getGlobalPosition(), WorldModel::getGlobalVelocity(), WorldModel::getOppGoalieType(), WorldModel::getPlayerNumber(), WorldModel::getSide(), VecPosition::getX(), VecPosition::getY(), WorldModel::isConfidenceGood(), WorldModel::isKnownPlayer(), MAX_OPPONENTS, MAX_SAY_MSG, MAX_TEAMMATES, OBJECT_BALL, OBJECT_OPPONENT_1, OBJECT_TEAMMATE_1, ObjectT, BasicPlayer::PS, SIDE_LEFT, and BasicPlayer::WM.

Referenced by mainLoop().

bool Player::shallISaySomething  
 

This method determines whether a player should say something. This is based on several factors: 1. The difference with the last say message should be equal or larger than the server paramater hear_decay 2. Always say something when time is stopped 3. The outside player in the opposite rectangle in which the ball is located equals this agent.

Returns:
bool indiciating whether the agent should say a message

Definition at line 650 of file Player.C.

References amIAgentToSaySomething(), WorldModel::getCurrentCycle(), ServerSettings::getHearDecay(), m_lastSay, BasicPlayer::SS, and BasicPlayer::WM.

Referenced by mainLoop().

void Player::showStringCommands ostream &    out
 

This method prints the possible commands that can be entered by the user. The whole name can be entered to perform the corresponding command, but normally only the first character is sufficient. This is indicated by putting brackets around the part of the command that is not needed.

Parameters:
out  output stream to which the possible commands are printed

Definition at line 484 of file Player.C.

Referenced by executeStringCommand().

void Player::test_only_update  
 

This method does nothing except updating the worldmodel after each arrival of a see or sense_body message. Using this test program it is possible to control the commands of the agent using the standard input and see the resulting behavior of the agent.

Definition at line 821 of file Player.C.

References bContLoop, WorldModel::updateAll(), WorldModel::waitForNewInformation(), and BasicPlayer::WM.

Referenced by main().


Member Data Documentation

bool Player::bContLoop [private]
 

is server is alive

Definition at line 57 of file Player.h.

Referenced by executeStringCommand(), mainLoop(), Player(), and test_only_update().

Formations* Player::formations [private]
 

all formation information

Definition at line 56 of file Player.h.

Referenced by deMeer5(), deMeer5_goalie(), getStrategicPosition(), mainLoop(), and Player().

int Player::m_lastSay [private]
 

last cycle communicated

Definition at line 59 of file Player.h.

Referenced by mainLoop(), Player(), and shallISaySomething().


The documentation for this class was generated from the following files:
Generated on Thu Mar 7 00:37:55 2002 for UvA Trilearn 2001 by doxygen1.2.12 written by Dimitri van Heesch, © 1997-2001