Class Brain

java.lang.Object
  |
  +--Brain

public class Brain
extends java.lang.Object

The Brain class is used to compute and steer the actual player. By receiving all necessary information from the Worldmodel, tactics and player-control are being considered.

Author:
Ramin Radpour, Anita Reifsteck, Wini Appl, Patrick Ficher, Alexander Lillich, Thorsten Fiekert

Field Summary
private  int actualTime
           
private  boolean ballCatched
           
private  double[] futurePos
           
private  double[][] gamePos
           
private  double[][] initPos
           
private  int myNr
           
private  Player player
           
private  PlayerAction playerAction
           
private  boolean playerChanged
           
private  boolean playRight
           
private  double[][] positions
           
private  java.lang.String refereeMsg
           
private  Worldmodel world
           
 
Constructor Summary
Brain(PlayerAction playerAction, Player player, Worldmodel world)
          Creates a new Brain instance.
 
Method Summary
private  boolean atGamePos()
          The atGamePos method is used to cause the player to go back to the middle of his radius whenever the ball is not within reach
private  boolean atPoint(double x, double y)
          The atPoint method is used to recognize wheter a position has been reached or not atPoint = false ---> position is not reached (default) atPoint = true ---> position is reached
private  boolean ballCanBeSeen()
          The ballCanBeSeen method test if ball can be seen
private  boolean ballInRadius()
          The ballInRadius method test if ball is within the player´s action-radius
private  boolean ballKickAble()
          The ballKickAble method test if ball is perfect to kick
private  java.lang.String buildMessage()
          The buildMessage method builds message containing positions to cry out to all the world message contains information in this order: password myNr time0 x0 y0 time1 x1 y1 ... time22 x22 y22 all information is stored as integer
private  double calcAngle2Obj(double x, double y)
          The calcAngle2Obj method calculates angle to turn to face direction to an object.
private  int calcDashPower(double x, double y)
          The calcDashPower method calculates power to dash using the distance to the coordinates to dash to Author: Ramin Radpour
private  double calcDist(double x1, double y1, double x2, double y2)
          The calcDistr method calculates the distance between two objects Author: Ramin Radpour
private  int calcKickPower(double x, double y)
          The calcKickPower method calculates power to kick the ball refering to distance of object to pass to.
private  double calcObjectDir(double oldX, double oldY, double actX, double actY)
          The calcObjectDir method calculates actual moving direction of an object by giving the angle to absangle back. oldX, oldY are old and actX, actY actual positions of the object; timedif is the diference between the timecycle of oldX/Y and actX/Y.
private  void catchBall()
          The catchBall method is the main routine of goalie
Author: Anita Reifsteck (Implementation), Ramin Radpour (Implementation), Wini Appl (Transmission to GUI)
private  boolean enemyInFront()
          The enemyInFront method test if one enemy in front of me
private  void freeKick()
          The freeKick method is Goalie free kick after catching the ball Author: Anita Reifsteck
 int friendHot()
          The friendHot method calculates possible teammembers to pass to
 void gamePos()
          The gamePos method defines the action-area.
private  void getBall()
          The getBall method makes the particular Player run to the ball.
private  boolean goalKickGood()
          The ballKickAble method test if own position is perfekt to kick to goal
private  void gotoPoint(double x, double y)
          The gotoPoint method moves player to given coordinates Author: Ramin Radpour
private  void gotoPos()
          The gotoPos method moves Player to his Game Position Author: Thorsten Fiekert
private  void hearEvent()
          The hearEvent method uses heared messages from teammembers to complete own positions Author: Ramin Radpour
 void initPos()
          The initPos method initial positions of all players at start of game or after goal Author: Thorsten Fiekert
private  void initStartPos()
          The initStartPos method setting up start positions before kickoff or after goal Author: Ramin Radpour
private  boolean inMyOwnRadius()
          The inMyOwnRadius method test if player is in his action-radius This method is used to make sure that the player won´t leave his action-radius
 void play()
          The play method is the main method Author: Ramin Radpour, Author: Patrick Ficher
private  void playHard()
          The playHard method have many decisions, so it can really be called brain
Author: Ramin Radpour (Implementation), Wini Appl (Transmission to GUI)
private  int whoIsNearest2Ball()
          The whoIsNearest2Ball method finds out, which player from each team stands nearest to ball [0]: own player nearest to ball [1]: enemy nearest to ball [2]: distance ownPlayer to ball [3]: distance enemy to ball Author: Ramin Radpour
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

world

private Worldmodel world

playerAction

private PlayerAction playerAction

player

private Player player

initPos

private double[][] initPos

gamePos

private double[][] gamePos

myNr

private int myNr

actualTime

private int actualTime

positions

private double[][] positions

refereeMsg

private java.lang.String refereeMsg

futurePos

private double[] futurePos

ballCatched

private boolean ballCatched

playRight

private boolean playRight

playerChanged

private boolean playerChanged
Constructor Detail

Brain

public Brain(PlayerAction playerAction,
             Player player,
             Worldmodel world)
Creates a new Brain instance.
Parameters:
playerAction - a PlayerAction value
player - a Player value
world - a worldmodel value
See Also:
PlayerAction, Player, Worldmodel
Method Detail

initPos

public void initPos()
The initPos method initial positions of all players at start of game or after goal

Author: Thorsten Fiekert


initStartPos

private void initStartPos()
The initStartPos method setting up start positions before kickoff or after goal

Author: Ramin Radpour


gamePos

public void gamePos()
The gamePos method defines the action-area. Actual positions during the game.

Author: Thorsten Fiekert


buildMessage

private java.lang.String buildMessage()
The buildMessage method builds message containing positions to cry out to all the world message contains information in this order: password myNr time0 x0 y0 time1 x1 y1 ... time22 x22 y22 all information is stored as integer
Returns:
the String message

Author: Ramin Radpour


catchBall

private void catchBall()
The catchBall method is the main routine of goalie

Author: Anita Reifsteck (Implementation), Ramin Radpour (Implementation), Wini Appl (Transmission to GUI)


freeKick

private void freeKick()
The freeKick method is Goalie free kick after catching the ball

Author: Anita Reifsteck


friendHot

public int friendHot()
The friendHot method calculates possible teammembers to pass to
Returns:
a integer player number of teammember

Author: Ramin Radpour


inMyOwnRadius

private boolean inMyOwnRadius()
The inMyOwnRadius method test if player is in his action-radius This method is used to make sure that the player won´t leave his action-radius
Returns:
a boolean
  • inMyOwnRadius = false --> player is not in his radius [default]
  • inMyOwnradius = true --> player is in his radius

Author: Thorsten Fiekert


atGamePos

private boolean atGamePos()
The atGamePos method is used to cause the player to go back to the middle of his radius whenever the ball is not within reach
Returns:
a boolean

Author: Thorsten Fiekert


ballInRadius

private boolean ballInRadius()
The ballInRadius method test if ball is within the player´s action-radius
Returns:
a boolean
  • ballInRadius = false --> ball is not within radius [default]
  • ballInRadius = true --> ball is within radius

Author: Thorsten Fiekert


ballCanBeSeen

private boolean ballCanBeSeen()
The ballCanBeSeen method test if ball can be seen
Returns:
a boolean
  • ballCanBeSeen = false ---> ball can't be seen (default)
  • ballCanBeSeen = true ---> ball can be seen

Author: Ramin Radpour


atPoint

private boolean atPoint(double x,
                        double y)
The atPoint method is used to recognize wheter a position has been reached or not
Returns:
a boolean

Author: Ramin Radpour


ballKickAble

private boolean ballKickAble()
The ballKickAble method test if ball is perfect to kick
Returns:
a boolean
  • ballKickAble = false ---> ball isn't near enough to be kicked (default)
  • ballKickAble = true ---> ball is perfect to kick

Author: Ramin Radpour


enemyInFront

private boolean enemyInFront()
The enemyInFront method test if one enemy in front of me
Returns:
a boolean
  • enemyInFront = false ---> there is no enemy in front of me nearby (default)
  • enemyInFront = true ---> there is at least one enemy in front of me nearby

Author: Ramin Radpour


goalKickGood

private boolean goalKickGood()
The ballKickAble method test if own position is perfekt to kick to goal
Returns:
a boolean
  • goalKickGood = false ---> own position is not good enough to kick to goal (default)
  • goalKickGood = true ---> own position is perfekt to kick to goal

Author: Ramin Radpour


getBall

private void getBall()
The getBall method makes the particular Player run to the ball. This one is a shortened command for the gotoPoint(double x, double y) method for easier implementation.
See Also:

Author: Wini Appl


gotoPos

private void gotoPos()
The gotoPos method moves Player to his Game Position

Author: Thorsten Fiekert


gotoPoint

private void gotoPoint(double x,
                       double y)
The gotoPoint method moves player to given coordinates

Author: Ramin Radpour


calcAngle2Obj

private double calcAngle2Obj(double x,
                             double y)
The calcAngle2Obj method calculates angle to turn to face direction to an object.

Author: Ramin Radpour


calcObjectDir

private double calcObjectDir(double oldX,
                             double oldY,
                             double actX,
                             double actY)
The calcObjectDir method calculates actual moving direction of an object by giving the angle to absangle back. oldX, oldY are old and actX, actY actual positions of the object; timedif is the diference between the timecycle of oldX/Y and actX/Y.

Author: Ramin Radpour


calcDist

private double calcDist(double x1,
                        double y1,
                        double x2,
                        double y2)
The calcDistr method calculates the distance between two objects

Author: Ramin Radpour


calcDashPower

private int calcDashPower(double x,
                          double y)
The calcDashPower method calculates power to dash using the distance to the coordinates to dash to

Author: Ramin Radpour


calcKickPower

private int calcKickPower(double x,
                          double y)
The calcKickPower method calculates power to kick the ball refering to distance of object to pass to.
Parameters:
x - a double positions to pass to
y - a double positions to pass to

Author: Ramin Radpour


whoIsNearest2Ball

private int whoIsNearest2Ball()
The whoIsNearest2Ball method finds out, which player from each team stands nearest to ball

Author: Ramin Radpour


playHard

private void playHard()
The playHard method have many decisions, so it can really be called brain

Author: Ramin Radpour (Implementation), Wini Appl (Transmission to GUI)


hearEvent

private void hearEvent()
The hearEvent method uses heared messages from teammembers to complete own positions

Author: Ramin Radpour


play

public void play()
The play method is the main method

Author: Ramin Radpour, Author: Patrick Ficher