Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 9 additions & 13 deletions src/software/ai/hl/stp/play/penalty_kick/BUILD
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package(default_visibility = ["//visibility:public"])

load("@simulated_tests_deps//:requirements.bzl", "requirement")
# We force linking for all plays so that the static variables required for the
# "factory" design pattern to work are linked in
# https://www.bfilipek.com/2018/02/static-vars-static-lib.html

package(default_visibility = ["//visibility:public"])

cc_library(
name = "penalty_kick_play",
srcs = [
Expand Down Expand Up @@ -37,18 +38,13 @@ cc_test(
],
)

cc_test(
py_test(
name = "penalty_kick_play_test",
Comment thread
itsarune marked this conversation as resolved.
srcs = ["penalty_kick_play_test.cpp"],
srcs = ["penalty_kick_play_test.py"],
tags = ["exclusive"],
deps = [
":penalty_kick_play",
"//shared/test_util:tbots_gtest_main",
"//software/simulated_tests:simulated_er_force_sim_play_test_fixture",
"//software/simulated_tests/non_terminating_validation_functions",
"//software/simulated_tests/terminating_validation_functions",
"//software/simulated_tests/validation:validation_function",
"//software/test_util",
"//software/time:duration",
"//software/world",
"//software:conftest",
Comment thread
itsarune marked this conversation as resolved.
"//software/simulated_tests:validation",
requirement("pytest"),
],
)
113 changes: 0 additions & 113 deletions src/software/ai/hl/stp/play/penalty_kick/penalty_kick_play_test.cpp

This file was deleted.

215 changes: 215 additions & 0 deletions src/software/ai/hl/stp/play/penalty_kick/penalty_kick_play_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,215 @@
import sys

import pytest

import software.python_bindings as tbots_cpp


from software.simulated_tests.ball_enters_region import BallEventuallyEntersRegion
from software.simulated_tests.ball_moves_forward import BallAlwaysMovesForward
from software.simulated_tests.friendly_has_ball_possession import (
FriendlyAlwaysHasBallPossession,
)
from software.simulated_tests.friendly_team_scored import FriendlyTeamEventuallyScored

from proto.message_translation.tbots_protobuf import create_world_state
from proto.import_all_protos import *
from proto.ssl_gc_common_pb2 import Team
from proto.play_pb2 import Play, PlayName

from software.simulated_tests.robot_enters_region import (
NumberOfRobotsEventuallyEntersRegion,
)


def test_penalty_kick_play_setup(simulated_test_runner):
ball_initial_pos = tbots_cpp.Point(-1.5, 0)

def setup(*args):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing docstring, add param docs for args.

# Setup Bots
blue_bots = [
tbots_cpp.Point(3, 2.5),
tbots_cpp.Point(2, 1.5),
tbots_cpp.Point(-1, 0.5),
tbots_cpp.Point(1, -0.5),
tbots_cpp.Point(0, -1.5),
tbots_cpp.Point(-3, -2.5),
]

yellow_bots = [
tbots_cpp.Point(1, 0),
tbots_cpp.Point(1, 2.5),
tbots_cpp.Point(1, -2.5),
tbots_cpp.Field.createSSLDivisionBField().enemyGoalCenter(),
tbots_cpp.Field.createSSLDivisionBField()
.enemyDefenseArea()
.negXNegYCorner(),
tbots_cpp.Field.createSSLDivisionBField()
.enemyDefenseArea()
.negXPosYCorner(),
]

# Force play override here
blue_play = Play()
blue_play.name = PlayName.PenaltyKickPlay

yellow_play = Play()
yellow_play.name = PlayName.PenaltyKickEnemyPlay

simulated_test_runner.blue_full_system_proto_unix_io.send_proto(Play, blue_play)
simulated_test_runner.yellow_full_system_proto_unix_io.send_proto(
Play, yellow_play
)

# Game Controller Setup
simulated_test_runner.gamecontroller.send_gc_command(
gc_command=Command.Type.STOP, team=Team.UNKNOWN
)

simulated_test_runner.gamecontroller.send_gc_command(
gc_command=Command.Type.NORMAL_START, team=Team.BLUE
)

simulated_test_runner.gamecontroller.send_gc_command(
gc_command=Command.Type.PENALTY, team=Team.BLUE
)

# Create world state
simulated_test_runner.simulator_proto_unix_io.send_proto(
WorldState,
create_world_state(
yellow_robot_locations=yellow_bots,
blue_robot_locations=blue_bots,
ball_location=ball_initial_pos,
ball_velocity=tbots_cpp.Vector(0, 0),
),
)

field = tbots_cpp.Field.createSSLDivisionBField()

# Always Validation
inv_always_validation_sequence_set = [[]]

ag_always_validation_sequence_set = [[]]

# Eventually Validation
inv_eventually_validation_sequence_set = [
[
NumberOfRobotsEventuallyEntersRegion(
region=tbots_cpp.Rectangle(
tbots_cpp.Point(-4.5, -3), tbots_cpp.Point(-2.5, 3)
),
req_robot_cnt=5,
),
NumberOfRobotsEventuallyEntersRegion(
region=tbots_cpp.Circle(ball_initial_pos, 0.5), req_robot_cnt=1
),
]
]
ag_eventually_validation_sequence_set = [[]]

simulated_test_runner.run_test(
params=[0],
setup=setup,
inv_eventually_validation_sequence_set=inv_eventually_validation_sequence_set,
inv_always_validation_sequence_set=inv_always_validation_sequence_set,
ag_eventually_validation_sequence_set=ag_eventually_validation_sequence_set,
ag_always_validation_sequence_set=ag_always_validation_sequence_set,
test_timeout_s=15,
)


def test_penalty_kick_play_kick(simulated_test_runner):
ball_initial_pos = tbots_cpp.Point(-1.5, 0)

def setup(*args):
# Setup Bots
blue_bots = [
tbots_cpp.Point(-3, 2.5),
tbots_cpp.Point(-3, 1.5),
tbots_cpp.Point(-3, 0.5),
tbots_cpp.Point(-3, -0.5),
tbots_cpp.Point(-3, -1.5),
tbots_cpp.Point(-3, -2.5),
]

yellow_bots = [
tbots_cpp.Point(-2.5, 0),
tbots_cpp.Point(-2.5, 1.5),
tbots_cpp.Point(-2.5, -1.5),
tbots_cpp.Point(-2.5, 2.5),
tbots_cpp.Point(-2.5, -2.5),
tbots_cpp.Field.createSSLDivisionBField().enemyGoalCenter(),
]

# Force play override here
blue_play = Play()
blue_play.name = PlayName.PenaltyKickPlay

yellow_play = Play()
yellow_play.name = PlayName.PenaltyKickEnemyPlay

simulated_test_runner.blue_full_system_proto_unix_io.send_proto(Play, blue_play)
simulated_test_runner.yellow_full_system_proto_unix_io.send_proto(
Play, yellow_play
)

# Game Controller Setup
simulated_test_runner.gamecontroller.send_gc_command(
gc_command=Command.Type.STOP, team=Team.UNKNOWN
)

simulated_test_runner.gamecontroller.send_gc_command(
gc_command=Command.Type.NORMAL_START, team=Team.BLUE
)

simulated_test_runner.gamecontroller.send_gc_command(
gc_command=Command.Type.PENALTY, team=Team.BLUE
)
simulated_test_runner.gamecontroller.send_gc_command(
gc_command=Command.Type.NORMAL_START, team=Team.BLUE
)

# Create world state
simulated_test_runner.simulator_proto_unix_io.send_proto(
WorldState,
create_world_state(
yellow_robot_locations=yellow_bots,
blue_robot_locations=blue_bots,
ball_location=ball_initial_pos,
ball_velocity=tbots_cpp.Vector(0, 0),
),
)

field = tbots_cpp.Field.createSSLDivisionBField()

# Always Validation
inv_always_validation_sequence_set = [[]]

ag_always_validation_sequence_set = [
[FriendlyAlwaysHasBallPossession(), BallAlwaysMovesForward(ball_initial_pos)]
]

# Eventually Validation
inv_eventually_validation_sequence_set = [
[
FriendlyTeamEventuallyScored(),
BallEventuallyEntersRegion(regions=[field.enemyDefenseArea()]),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this validation is kinda redundant considering we have FriendlyTeamEventuallyScored

]
]
ag_eventually_validation_sequence_set = [[]]

simulated_test_runner.run_test(
params=[0],
setup=setup,
inv_eventually_validation_sequence_set=inv_eventually_validation_sequence_set,
inv_always_validation_sequence_set=inv_always_validation_sequence_set,
ag_eventually_validation_sequence_set=ag_eventually_validation_sequence_set,
ag_always_validation_sequence_set=ag_always_validation_sequence_set,
test_timeout_s=15,
)


if __name__ == "__main__":
# Run the test, -s disables all capturing at -vv increases verbosity
sys.exit(pytest.main([__file__, "-svv"]))
Loading
Loading