Skip to content

Commit

Permalink
Prevent kicks disrupting the game flow
Browse files Browse the repository at this point in the history
  • Loading branch information
hannesbraun committed Apr 4, 2022
1 parent 0ef2df2 commit 8374293
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/main/java/magma/agent/decision/behavior/basic/MonitorKick.java
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,34 @@ public boolean checkBallDistance(double distance)
return distance <= KICKABLE_MARGIN;
}

/**
* check if kicking is allowed in the current play mode
*
* @return true, if the kick is currently allowed
*/
public boolean checkPlaymode()
{
switch (getThoughtModel().getMonitorRuntime().getWorldModel().getPlayMode()) {
case BEFORE_KICK_OFF:
case GOAL_LEFT:
case GOAL_RIGHT:
return false;
case KICK_OFF_LEFT:
case KICK_OFF_RIGHT:
IThisPlayer thisPlayer = getWorldModel().getThisPlayer();
if (getPlayer(thisPlayer.getTeamname(), thisPlayer.getID()).getPosition().distance(new Vector3D(0, 0, 0)) >
2) {
// Assumption: the kick off always happens at (0, 0) -> a bit hacky, but it should work for our purposes
// If the player is far away from the middle of the field, he's not going to do the kick off.
// -> Forbid the kick. The goalie may otherwise be able to execute a kick in the first cycle of the
// kick off because he may have missed the update of the ball position or something similar.
return false;
}
default:
return true;
}
}

// TODO: this method rather belongs into magmaMonitor!
public ISoccerAgent getPlayer(String team, int number)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,9 @@ protected String move()
private String determineKick(float[] values)
{
MonitorKick kick = (MonitorKick) behaviors.get(IBehaviorConstants.MONITOR_KICK);
if (!kick.checkPlaymode()) {
return IBehaviorConstants.GET_READY;
}
if (!kick.checkBallDistance()) {
Walk walk = (Walk) behaviors.get(IBehaviorConstants.WALK);
walk.walk(10, 0, 0);
Expand Down

0 comments on commit 8374293

Please sign in to comment.