|
| 1 | +import software.python_bindings as tbots_cpp |
| 2 | +from proto.play_pb2 import Play, PlayName |
| 3 | +from software.simulated_tests.friendly_team_scored import * |
| 4 | +from software.simulated_tests.ball_enters_region import * |
| 5 | +from software.simulated_tests.friendly_has_ball_possession import * |
| 6 | +from proto.message_translation.tbots_protobuf import create_world_state |
| 7 | +from proto.ssl_gc_common_pb2 import Team |
| 8 | +from software.simulated_tests.simulated_test_fixture import ( |
| 9 | + pytest_main, |
| 10 | +) |
| 11 | + |
| 12 | + |
| 13 | +def test_shoot_or_pass_play(simulated_test_runner): |
| 14 | + def setup(start_point): |
| 15 | + # starting point must be Point |
| 16 | + ball_initial_pos = start_point |
| 17 | + # placement point must be Vector2 to work with game controller |
| 18 | + tbots_cpp.Point(-3, -2) |
| 19 | + tbots_cpp.Field.createSSLDivisionBField() |
| 20 | + |
| 21 | + # Setup Bots |
| 22 | + blue_bots = [ |
| 23 | + tbots_cpp.Point(-4.5, 3.0), |
| 24 | + tbots_cpp.Point(-2, 1.5), |
| 25 | + tbots_cpp.Point(-2, 0.5), |
| 26 | + tbots_cpp.Point(-2, -1.7), |
| 27 | + tbots_cpp.Point(-2, -1.5), |
| 28 | + tbots_cpp.Point(-2, -0.5), |
| 29 | + ] |
| 30 | + |
| 31 | + yellow_bots = [ |
| 32 | + tbots_cpp.Point(1, 0), |
| 33 | + tbots_cpp.Point(1, 2.5), |
| 34 | + tbots_cpp.Point(1, -2.5), |
| 35 | + tbots_cpp.Field.createSSLDivisionBField().enemyGoalCenter(), |
| 36 | + tbots_cpp.Field.createSSLDivisionBField() |
| 37 | + .enemyDefenseArea() |
| 38 | + .negXNegYCorner(), |
| 39 | + tbots_cpp.Field.createSSLDivisionBField() |
| 40 | + .enemyDefenseArea() |
| 41 | + .negXPosYCorner(), |
| 42 | + ] |
| 43 | + |
| 44 | + # Game Controller Setup |
| 45 | + simulated_test_runner.gamecontroller.send_gc_command( |
| 46 | + gc_command=Command.Type.STOP, team=Team.UNKNOWN |
| 47 | + ) |
| 48 | + simulated_test_runner.gamecontroller.send_gc_command( |
| 49 | + gc_command=Command.Type.FORCE_START, team=Team.BLUE |
| 50 | + ) |
| 51 | + |
| 52 | + # Force play override here |
| 53 | + blue_play = Play() |
| 54 | + blue_play.name = PlayName.OffensePlay |
| 55 | + |
| 56 | + yellow_play = Play() |
| 57 | + yellow_play.name = PlayName.HaltPlay |
| 58 | + |
| 59 | + simulated_test_runner.blue_full_system_proto_unix_io.send_proto( |
| 60 | + Play, blue_play) |
| 61 | + simulated_test_runner.yellow_full_system_proto_unix_io.send_proto( |
| 62 | + Play, yellow_play |
| 63 | + ) |
| 64 | + |
| 65 | + # Create world state |
| 66 | + simulated_test_runner.simulator_proto_unix_io.send_proto( |
| 67 | + WorldState, |
| 68 | + create_world_state( |
| 69 | + yellow_robot_locations=yellow_bots, |
| 70 | + blue_robot_locations=blue_bots, |
| 71 | + ball_location=ball_initial_pos, |
| 72 | + ball_velocity=tbots_cpp.Vector(0, 0), |
| 73 | + ), |
| 74 | + ) |
| 75 | + |
| 76 | + field = tbots_cpp.Field.createSSLDivisionBField() |
| 77 | + |
| 78 | + # Always Validation |
| 79 | + inv_always_validation_sequence_set = [ |
| 80 | + [BallAlwaysStaysInRegion(regions=[field.fieldBoundary()])] |
| 81 | + ] |
| 82 | + |
| 83 | + ag_always_validation_sequence_set = [[FriendlyAlwaysHasBallPossession()]] |
| 84 | + |
| 85 | + # Eventually Validation |
| 86 | + inv_eventually_validation_sequence_set = [[]] |
| 87 | + ag_eventually_validation_sequence_set = [[FriendlyTeamEventuallyScored()]] |
| 88 | + |
| 89 | + simulated_test_runner.run_test( |
| 90 | + params=[tbots_cpp.Point(-4.4, 2.9)], |
| 91 | + setup=setup, |
| 92 | + inv_eventually_validation_sequence_set=inv_eventually_validation_sequence_set, |
| 93 | + inv_always_validation_sequence_set=inv_always_validation_sequence_set, |
| 94 | + ag_eventually_validation_sequence_set=ag_eventually_validation_sequence_set, |
| 95 | + ag_always_validation_sequence_set=ag_always_validation_sequence_set, |
| 96 | + test_timeout_s=15, |
| 97 | + run_till_end=True, |
| 98 | + ) |
| 99 | + |
| 100 | + |
| 101 | +if __name__ == "__main__": |
| 102 | + pytest_main(__file__) |
0 commit comments