From 8374293e17b335bf11bc65a4798c19a455a8dcfe Mon Sep 17 00:00:00 2001 From: Hannes Braun Date: Mon, 4 Apr 2022 16:19:18 +0200 Subject: [PATCH] Prevent kicks disrupting the game flow --- .../decision/behavior/basic/MonitorKick.java | 28 +++++++++++++++++++ .../impl/SoccerDecisionMaker.java | 3 ++ 2 files changed, 31 insertions(+) diff --git a/src/main/java/magma/agent/decision/behavior/basic/MonitorKick.java b/src/main/java/magma/agent/decision/behavior/basic/MonitorKick.java index 6f7fe8c..b7be24c 100644 --- a/src/main/java/magma/agent/decision/behavior/basic/MonitorKick.java +++ b/src/main/java/magma/agent/decision/behavior/basic/MonitorKick.java @@ -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) { diff --git a/src/main/java/magma/agent/decision/decisionmaker/impl/SoccerDecisionMaker.java b/src/main/java/magma/agent/decision/decisionmaker/impl/SoccerDecisionMaker.java index 40348da..0c05868 100644 --- a/src/main/java/magma/agent/decision/decisionmaker/impl/SoccerDecisionMaker.java +++ b/src/main/java/magma/agent/decision/decisionmaker/impl/SoccerDecisionMaker.java @@ -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);