Skip to content

Commit

Permalink
Added throw in challenge
Browse files Browse the repository at this point in the history
  • Loading branch information
rpufe committed Apr 15, 2024
1 parent 7ed5e8e commit bd3edff
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/main/java/magma/tools/benchmark/ChallengeType.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public enum ChallengeType {

THROW_IN("Throw In", ThrowInBenchmark::new, ThrowInBenchmarkTableView::getInstance);

public static final ChallengeType DEFAULT = ROLLING_BALL;
public static final ChallengeType DEFAULT = THROW_IN;

public final String name;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@ public class ThrowInBenchmark extends BenchmarkMain
/** x-axis delta of player to ball (in m) */
static final double DISTANCE_BEHIND_BALL = 0.6;

/** half opening angle of ball positions (in degrees) */
static final double BEAM_ANGLE = 30;

/** noise in player beam position (in m) */
static final double BEAM_NOISE = 0.1;

Expand Down Expand Up @@ -92,13 +89,12 @@ protected TeamResult createTeamResult(TeamConfiguration currentTeamConfig)

@Override
protected RunInformation createRunInformation(Random rand, int runID)
{
double radius = (runID + 3);
double angle = Math.toRadians(noise(rand, BEAM_ANGLE));
double ballX = -radius * Math.cos(angle);
double ballY = radius * Math.sin(angle);
double beamX = ballX - DISTANCE_BEHIND_BALL + noise(rand, BEAM_NOISE);
double beamY = ballY + noise(rand, BEAM_NOISE);
{
double beamX = -15;
double beamY = 0;
double ballX = beamX + DISTANCE_BEHIND_BALL + noise(rand, BEAM_NOISE);
double ballY = beamY + noise(rand, BEAM_NOISE);

return new RunInformation(runID, beamX, beamY, ballX, ballY);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ public class ThrowInBenchmarkReferee extends BenchmarkRefereeBase

/** speed below which the ball is considered in rest (in m/cycle) */
private static final double BALL_STOPPED_SPEED = 0.001;

/** minimal height from where the ball needs to be thrown to be considered a throw */
private static final double MIN_THROW_HEIGHT = 0.5;

/** threshold for ball velocity where a throw is considered a kick */
private static final double KICK_VELOCITY_THRESHOLD = 0.4;

private final String roboVizServer;

Expand All @@ -41,6 +47,12 @@ public class ThrowInBenchmarkReferee extends BenchmarkRefereeBase

/** position of ball in last cycle */
private Vector2D oldBallPos;

/** position of ball in last cycle */
private Vector3D oldBallPos3D;

/** flag for checking if the ball was above MIN_TROW_HEIGHT */
private boolean wasThrown;

public ThrowInBenchmarkReferee(IMonitorWorldModel mWorldModel, IServerCommander serverCommander, String serverPid,
SinglePlayerLauncher launcher, float dropHeight, RunInformation runInfo, String roboVizServer)
Expand All @@ -50,6 +62,7 @@ public ThrowInBenchmarkReferee(IMonitorWorldModel mWorldModel, IServerCommander
this.roboVizServer = roboVizServer;
distanceError = 0;
oldBallPos = new Vector2D(runInfo.getBallX(), runInfo.getBallY());
oldBallPos3D = new Vector3D(runInfo.getBallX(), runInfo.getBallY(), 0);
}

/**
Expand All @@ -67,6 +80,8 @@ protected boolean onDuringLaunching()
protected boolean onStartBenchmark()
{
state = RefereeState.CONNECTED;

wasThrown = false;

serverCommander.setPlaymode(PlayMode.PLAY_ON);
serverCommander.beamBall((float) runInfo.getBallX(), (float) runInfo.getBallY());
Expand Down Expand Up @@ -118,7 +133,8 @@ protected boolean onDuringBenchmark()
// stop if player runs too far
if (playerNow.distance(ballInitial) > MAX_BALL_DISTANCE) {
return true;
}
}

// stop if ball has left radius and has stopped
if (ballNow.distance(ballInitial) > MAX_BALL_DISTANCE) {
if (ballNow.distance(oldBallPos) < BALL_STOPPED_SPEED) {
Expand All @@ -129,6 +145,14 @@ protected boolean onDuringBenchmark()
if (time - startTime > TIME_BALL_HAS_TO_LEAVE_CIRCLE) {
return true;
}

double velocity = posBall.distance(oldBallPos3D);

if (posBall.getZ() > MIN_THROW_HEIGHT && velocity < KICK_VELOCITY_THRESHOLD) {
wasThrown = true;
} else {
wasThrown = false;
}
}
// stop if playmode changes (e.g. because someone scored an own goal)
if (worldModel.getPlayMode() != PlayMode.PLAY_ON) {
Expand All @@ -137,6 +161,7 @@ protected boolean onDuringBenchmark()
}

oldBallPos = ballNow;
oldBallPos3D = posBall;
return false;
}

Expand All @@ -155,6 +180,12 @@ protected void onStopBenchmark()
distanceError += PENALTY_LEAVING_CIRCLE;
hasPenalty = true;
}

// we give a penalty if player did not threw the ball
if (!wasThrown) {
distanceError = 0;
hasPenalty = true;
}
}

/**
Expand Down

0 comments on commit bd3edff

Please sign in to comment.