Skip to content
Open
Show file tree
Hide file tree
Changes from 6 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
14 changes: 13 additions & 1 deletion src/software/ai/hl/stp/play/penalty_kick/BUILD
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
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
Expand Down Expand Up @@ -38,7 +39,7 @@ cc_test(
)

cc_test(
name = "penalty_kick_play_test",
Comment thread
itsarune marked this conversation as resolved.
name = "penalty_kick_play_cpp_test",
srcs = ["penalty_kick_play_test.cpp"],
deps = [
":penalty_kick_play",
Expand All @@ -52,3 +53,14 @@ cc_test(
"//software/world",
],
)

py_test(
name = "penalty_kick_play_test",
srcs = ["penalty_kick_play_test.py"],
tags = ["exclusive"],
deps = [
"//software:conftest",
Comment thread
itsarune marked this conversation as resolved.
"//software/simulated_tests:validation",
requirement("pytest"),
],
)
110 changes: 110 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,110 @@
import sys

import pytest

import software.python_bindings as tbots_cpp

from software.simulated_tests.ball_enters_region import BallEventuallyEntersRegion
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


def test_penalty_kick_play(simulated_test_runner):
ball_initial_pos = tbots_cpp.Point(0, 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(-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(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

# Not sure if this should be penalty kick enemy play or halt play
Comment thread
itsarune marked this conversation as resolved.
Outdated
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 = [[FriendlyAlwaysHasBallPossession()]]
Comment thread
itsarune marked this conversation as resolved.
Outdated

# 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