C# Class SimpleSoccer.Net.SoccerTeam

Defines a Team of SoccerBasePlayers for the Soccer game simulation
Mostrar archivo Open project: soshimozi/SimpleSoccer.Net Class Usage Examples

Public Methods

Method Description
AllPlayersAtHome ( ) : bool

Determines if any of the team are not located within their home region

CalculateClosestOpponentToGoal ( ) : void

Calculates the closest opponent to this teams goal

CalculateClosestPlayerToBall ( ) : void

sets _playerClosestToBall to the player closest to the ball

CanShoot ( Vector2D BallPos, double power ) : bool
CanShoot ( Vector2D BallPos, double power, Vector2D &ShotTarget ) : bool

Given a ball position, a kicking power and a reference to a vector2D this function will sample random positions along the opponent's goal- mouth and check to see if a goal can be scored if the ball was to be kicked in that direction with the given power. If a possible shot is found, the function will immediately return true, with the target position stored in the vector ShotTarget.

DetermineBestSupportingAttacker ( ) : PlayerBase

calculate the closest player to the SupportSpot

DetermineBestSupportingPosition ( ) : void

Calculates the best supporting position

FindPass ( PlayerBase passer, PlayerBase &receiver, Vector2D &PassTarget, double power, double MinPassingDistance ) : bool

The best pass is considered to be the pass that cannot be intercepted by an opponent and that is as far forward of the receiver as possible

FindPlayerById ( int playerId ) : PlayerBase

Finds a player by its id

GetBestPassToReceiver ( PlayerBase passer, PlayerBase receiver, Vector2D &PassTarget, double power ) : bool

Three potential passes are calculated. One directly toward the receiver's current position and two that are the tangents from the ball position to the circle of radius 'range' from the receiver. These passes are then tested to see if they can be intercepted by an opponent and to make sure they terminate within the playing area. If all the passes are invalidated the function returns false. Otherwise the function returns the pass that takes the ball closest to the opponent's goal area.

GetSupportSpot ( ) : Vector2D
IsOpponentWithinRadius ( Vector2D pos, double rad ) : bool

returns true if an opposing player is within the radius of the position given as a parameter

IsPassSafeFromAllOpponents ( Vector2D from, Vector2D target, PlayerBase receiver, double PassingForce ) : bool

Tests a pass from position 'from' to position 'target' against each member of the opposing team. Returns true if the pass can be made without getting intercepted

IsPassSafeFromOpponent ( Vector2D from, Vector2D target, PlayerBase receiver, PlayerBase opp, double PassingForce ) : bool

test if a pass from 'from' to 'to' can be intercepted by an opposing player

Render ( Graphics g ) : void

Render the soccer team

RequestPass ( FieldPlayer requester ) : void

This tests to see if a pass is possible between the requester and the controlling player. If it is possible a message is sent to the controlling player to pass the ball asap.

ReturnAllFieldPlayersToHome ( ) : void

sends a message to all players to return to their home areas forthwith

SetPlayerHomeRegion ( int playerId, int region ) : void

Sets a particular players home region index

SoccerTeam ( SoccerGoal homeGoal, SoccerGoal opponentsGoal, SoccerPitch pitch, SoccerTeamColor color ) : System
Update ( ) : void

Called every tick to update the team state

UpdateTargetsOfWaitingPlayers ( ) : void

Finds targets for waiting players

Private Methods

Method Description
CreatePlayers ( ) : void

Create the players for the team

LostControl ( ) : void

Method Details

AllPlayersAtHome() public method

Determines if any of the team are not located within their home region
public AllPlayersAtHome ( ) : bool
return bool

CalculateClosestOpponentToGoal() public method

Calculates the closest opponent to this teams goal
public CalculateClosestOpponentToGoal ( ) : void
return void

CalculateClosestPlayerToBall() public method

sets _playerClosestToBall to the player closest to the ball
public CalculateClosestPlayerToBall ( ) : void
return void

CanShoot() public method

public CanShoot ( Vector2D BallPos, double power ) : bool
BallPos Vector2D
power double
return bool

CanShoot() public method

Given a ball position, a kicking power and a reference to a vector2D this function will sample random positions along the opponent's goal- mouth and check to see if a goal can be scored if the ball was to be kicked in that direction with the given power. If a possible shot is found, the function will immediately return true, with the target position stored in the vector ShotTarget.
public CanShoot ( Vector2D BallPos, double power, Vector2D &ShotTarget ) : bool
BallPos Vector2D
power double
ShotTarget Vector2D
return bool

DetermineBestSupportingAttacker() public method

calculate the closest player to the SupportSpot
public DetermineBestSupportingAttacker ( ) : PlayerBase
return PlayerBase

DetermineBestSupportingPosition() public method

Calculates the best supporting position
public DetermineBestSupportingPosition ( ) : void
return void

FindPass() public method

The best pass is considered to be the pass that cannot be intercepted by an opponent and that is as far forward of the receiver as possible
public FindPass ( PlayerBase passer, PlayerBase &receiver, Vector2D &PassTarget, double power, double MinPassingDistance ) : bool
passer PlayerBase
receiver PlayerBase
PassTarget Vector2D
power double
MinPassingDistance double
return bool

FindPlayerById() public method

Finds a player by its id
public FindPlayerById ( int playerId ) : PlayerBase
playerId int
return PlayerBase

GetBestPassToReceiver() public method

Three potential passes are calculated. One directly toward the receiver's current position and two that are the tangents from the ball position to the circle of radius 'range' from the receiver. These passes are then tested to see if they can be intercepted by an opponent and to make sure they terminate within the playing area. If all the passes are invalidated the function returns false. Otherwise the function returns the pass that takes the ball closest to the opponent's goal area.
public GetBestPassToReceiver ( PlayerBase passer, PlayerBase receiver, Vector2D &PassTarget, double power ) : bool
passer PlayerBase
receiver PlayerBase
PassTarget Vector2D
power double
return bool

GetSupportSpot() public method

public GetSupportSpot ( ) : Vector2D
return Vector2D

IsOpponentWithinRadius() public method

returns true if an opposing player is within the radius of the position given as a parameter
public IsOpponentWithinRadius ( Vector2D pos, double rad ) : bool
pos Vector2D
rad double
return bool

IsPassSafeFromAllOpponents() public method

Tests a pass from position 'from' to position 'target' against each member of the opposing team. Returns true if the pass can be made without getting intercepted
public IsPassSafeFromAllOpponents ( Vector2D from, Vector2D target, PlayerBase receiver, double PassingForce ) : bool
from Vector2D
target Vector2D
receiver PlayerBase
PassingForce double
return bool

IsPassSafeFromOpponent() public method

test if a pass from 'from' to 'to' can be intercepted by an opposing player
public IsPassSafeFromOpponent ( Vector2D from, Vector2D target, PlayerBase receiver, PlayerBase opp, double PassingForce ) : bool
from Vector2D
target Vector2D
receiver PlayerBase
opp PlayerBase
PassingForce double
return bool

Render() public method

Render the soccer team
public Render ( Graphics g ) : void
g System.Drawing.Graphics
return void

RequestPass() public method

This tests to see if a pass is possible between the requester and the controlling player. If it is possible a message is sent to the controlling player to pass the ball asap.
public RequestPass ( FieldPlayer requester ) : void
requester FieldPlayer
return void

ReturnAllFieldPlayersToHome() public method

sends a message to all players to return to their home areas forthwith
public ReturnAllFieldPlayersToHome ( ) : void
return void

SetPlayerHomeRegion() public method

Sets a particular players home region index
public SetPlayerHomeRegion ( int playerId, int region ) : void
playerId int
region int
return void

SoccerTeam() public method

public SoccerTeam ( SoccerGoal homeGoal, SoccerGoal opponentsGoal, SoccerPitch pitch, SoccerTeamColor color ) : System
homeGoal SoccerGoal
opponentsGoal SoccerGoal
pitch SoccerPitch
color SoccerTeamColor
return System

Update() public method

Called every tick to update the team state
public Update ( ) : void
return void

UpdateTargetsOfWaitingPlayers() public method

Finds targets for waiting players
public UpdateTargetsOfWaitingPlayers ( ) : void
return void