Skip to content

Commit df621d7

Browse files
committed
[bugfix,test] Added a lot more tests again and fixed some placement bugs
1 parent c4c992b commit df621d7

File tree

20 files changed

+1534
-4
lines changed

20 files changed

+1534
-4
lines changed

internal/app/controller/engine.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,7 @@ func (e *Engine) CommandForEvent(event *GameEvent) (command RefCommand, forTeam
178178

179179
if e.State.bothTeamsCanPlaceBall() &&
180180
e.State.ballPlacementFailedBefore() &&
181-
!e.allTeamsFailedPlacement() &&
182-
primaryGameEvent.Type.resultsFromBallLeavingField() {
181+
!e.allTeamsFailedPlacement() {
183182
// A failed placement will result in an indirect free kick for the opposing team.
184183
command = CommandIndirect
185184
forTeam = event.ByTeam()
@@ -226,6 +225,7 @@ func (e *Engine) CommandForEvent(event *GameEvent) (command RefCommand, forTeam
226225

227226
if e.State.Division == config.DivA && // For division A
228227
!e.State.TeamState[forTeam].CanPlaceBall && // If team in favor can not place the ball
228+
e.State.TeamState[forTeam.Opposite()].CanPlaceBall && // If opponent team can place the ball
229229
primaryGameEvent.Type.resultsFromBallLeavingField() { // event is caused by the ball leaving the field
230230
// All free kicks that were a result of the ball leaving the field, are awarded to the opposing team.
231231
forTeam = forTeam.Opposite()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
# Situation:
2+
# Unique collision by yellow
3+
#
4+
# Division: B
5+
#
6+
# Who can place?
7+
# both teams
8+
#
9+
# Ball left field?
10+
# no
11+
#
12+
# Who succeeds?
13+
# Opponent team (one failure)
14+
# -> yellow
15+
#
16+
# Special case?
17+
# Yes (second try, both teams can place, ball left field before)
18+
# Opponent (yellow) is awarded an indirect free kick, because the first team has failed.
19+
#
20+
initialState:
21+
stage: First Half
22+
command: forceStart
23+
division: DivB
24+
stageTimeLeft: 5m
25+
teamState:
26+
Yellow:
27+
ballPlacementFailures: 2
28+
Blue:
29+
ballPlacementFailures: 3
30+
transitions:
31+
- event:
32+
gameEvent:
33+
type: botCrashUnique
34+
details:
35+
botcrashunique:
36+
byteam: 1 # Yellow
37+
location:
38+
x: 2.0
39+
y: 1.0
40+
expectedStateDiff:
41+
command: ballPlacement
42+
commandFor: Blue
43+
nextCommand: direct
44+
nextCommandFor: Blue
45+
currentActionDeadline: "2010-01-01T00:00:30Z"
46+
currentActionTimeRemaining: 30s
47+
placementPos:
48+
x: 2.0
49+
y: 1.0
50+
teamState:
51+
Yellow:
52+
foulCounter: 1
53+
gameEvents:
54+
- type: botCrashUnique
55+
details:
56+
botcrashunique:
57+
byteam: 1 # Yellow
58+
location:
59+
x: 2.0
60+
y: 1.0
61+
- tick: 1s # make sure that the stage time is not proceeded
62+
expectedStateDiff:
63+
currentActionTimeRemaining: 29s
64+
placementPos:
65+
x: 2.0
66+
y: 1.0
67+
- event:
68+
gameEvent:
69+
type: placementFailed
70+
details:
71+
placementfailed:
72+
byteam: 2 # Blue
73+
remainingdistance: 1.0
74+
expectedStateDiff:
75+
command: ballPlacement
76+
commandFor: Yellow
77+
nextCommand: indirect
78+
nextCommandFor: Yellow
79+
currentActionDeadline: "2010-01-01T00:00:31Z"
80+
currentActionTimeRemaining: 30s
81+
placementPos:
82+
x: 2.0
83+
y: 1.0
84+
gameEvents:
85+
- type: botCrashUnique
86+
details:
87+
botcrashunique:
88+
byteam: 1 # Yellow
89+
location:
90+
x: 2.0
91+
y: 1.0
92+
- type: placementFailed
93+
details:
94+
placementfailed:
95+
byteam: 2 # Blue
96+
remainingdistance: 1.0
97+
teamState:
98+
Blue:
99+
ballPlacementFailures: 4
100+
- tick: 1s # make sure that the stage time is not proceeded
101+
expectedStateDiff:
102+
currentActionTimeRemaining: 29s
103+
placementPos:
104+
x: 2.0
105+
y: 1.0
106+
- event:
107+
gameEvent:
108+
type: placementSucceeded
109+
details:
110+
placementsucceeded:
111+
byteam: 1 # Yellow
112+
timetaken: 1.0
113+
precision: 0.01
114+
expectedStateDiff:
115+
command: indirect
116+
commandFor: Yellow
117+
nextCommand: ""
118+
nextCommandFor: ""
119+
currentActionDeadline: "2010-01-01T00:00:12Z"
120+
currentActionTimeRemaining: 10s
121+
gameEvents: []
122+
teamState:
123+
Yellow:
124+
ballPlacementFailures: 0
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
# Situation:
2+
# Unique collision by yellow
3+
#
4+
# Division: B
5+
#
6+
# Who can place?
7+
# both teams
8+
#
9+
# Ball left field?
10+
# no
11+
#
12+
# Who succeeds?
13+
# Opponent team (one failure)
14+
# -> yellow
15+
#
16+
# Special case?
17+
# Yes (second try, both teams can place, ball left field before)
18+
# Opponent (yellow) is awarded an indirect free kick, because the first team has failed.
19+
#
20+
initialState:
21+
stage: First Half
22+
command: forceStart
23+
division: DivB
24+
stageTimeLeft: 5m
25+
teamState:
26+
Yellow:
27+
ballPlacementFailures: 2
28+
Blue:
29+
ballPlacementFailures: 3
30+
transitions:
31+
- event:
32+
gameEvent:
33+
type: botCrashUnique
34+
details:
35+
botcrashunique:
36+
byteam: 1 # Yellow
37+
location:
38+
x: 2.0
39+
y: 1.0
40+
expectedStateDiff:
41+
command: ballPlacement
42+
commandFor: Blue
43+
nextCommand: direct
44+
nextCommandFor: Blue
45+
currentActionDeadline: "2010-01-01T00:00:30Z"
46+
currentActionTimeRemaining: 30s
47+
placementPos:
48+
x: 2.0
49+
y: 1.0
50+
teamState:
51+
Yellow:
52+
foulCounter: 1
53+
gameEvents:
54+
- type: botCrashUnique
55+
details:
56+
botcrashunique:
57+
byteam: 1 # Yellow
58+
location:
59+
x: 2.0
60+
y: 1.0
61+
- tick: 1s # make sure that the stage time is not proceeded
62+
expectedStateDiff:
63+
currentActionTimeRemaining: 29s
64+
placementPos:
65+
x: 2.0
66+
y: 1.0
67+
- event:
68+
gameEvent:
69+
type: placementFailed
70+
details:
71+
placementfailed:
72+
byteam: 2 # Blue
73+
remainingdistance: 1.0
74+
expectedStateDiff:
75+
command: ballPlacement
76+
commandFor: Yellow
77+
nextCommand: indirect
78+
nextCommandFor: Yellow
79+
currentActionDeadline: "2010-01-01T00:00:31Z"
80+
currentActionTimeRemaining: 30s
81+
placementPos:
82+
x: 2.0
83+
y: 1.0
84+
gameEvents:
85+
- type: botCrashUnique
86+
details:
87+
botcrashunique:
88+
byteam: 1 # Yellow
89+
location:
90+
x: 2.0
91+
y: 1.0
92+
- type: placementFailed
93+
details:
94+
placementfailed:
95+
byteam: 2 # Blue
96+
remainingdistance: 1.0
97+
teamState:
98+
Blue:
99+
ballPlacementFailures: 4
100+
- tick: 1s # make sure that the stage time is not proceeded
101+
expectedStateDiff:
102+
currentActionTimeRemaining: 29s
103+
placementPos:
104+
x: 2.0
105+
y: 1.0
106+
- event:
107+
gameEvent:
108+
type: placementSucceeded
109+
details:
110+
placementsucceeded:
111+
byteam: 1 # Yellow
112+
timetaken: 1.0
113+
precision: 0.01
114+
expectedStateDiff:
115+
command: indirect
116+
commandFor: Yellow
117+
nextCommand: ""
118+
nextCommandFor: ""
119+
currentActionDeadline: "2010-01-01T00:00:12Z"
120+
currentActionTimeRemaining: 10s
121+
gameEvents: []
122+
teamState:
123+
Yellow:
124+
ballPlacementFailures: 0
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Situation:
2+
# Unique collision by yellow
3+
#
4+
# Division: A
5+
#
6+
# Who can place?
7+
# opponent only (yellow)
8+
#
9+
# Ball left field?
10+
# no
11+
#
12+
# Who succeeds?
13+
# No team (one failure)
14+
#
15+
# Special case?
16+
# Yes
17+
# Opponent team (yellow) has committed a foul, where the ball did not simply left the field.
18+
# Team in favor (blue) can not place the ball, though.
19+
# Referee has to place the ball.
20+
#
21+
initialState:
22+
stage: First Half
23+
command: forceStart
24+
division: DivA
25+
stageTimeLeft: 5m
26+
teamState:
27+
Yellow:
28+
ballPlacementFailures: 2
29+
Blue:
30+
ballPlacementFailures: 5
31+
canPlaceBall: false
32+
transitions:
33+
- event:
34+
gameEvent:
35+
type: botCrashUnique
36+
details:
37+
botcrashunique:
38+
byteam: 1 # Yellow
39+
location:
40+
x: 2.0
41+
y: 1.0
42+
expectedStateDiff:
43+
command: halt
44+
commandFor: ""
45+
nextCommand: direct
46+
nextCommandFor: Blue
47+
placementPos:
48+
x: 2.0
49+
y: 1.0
50+
teamState:
51+
Yellow:
52+
foulCounter: 1
53+
gameEvents:
54+
- type: botCrashUnique
55+
details:
56+
botcrashunique:
57+
byteam: 1 # Yellow
58+
location:
59+
x: 2.0
60+
y: 1.0

internal/app/controller/testdata/engine_test_gameevent_placement_fail_once_opponentCanPlace_divB.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,6 @@ transitions:
7676
commandFor: ""
7777
nextCommand: direct
7878
nextCommandFor: Blue
79-
currentActionDeadline: "2010-01-01T00:00:30Z"
80-
currentActionTimeRemaining: 29s
8179
placementPos:
8280
x: 4.3
8381
y: 2.8

0 commit comments

Comments
 (0)