@@ -3,6 +3,8 @@ import { MiraType } from "@/mirabuf/MirabufLoader"
33import MirabufSceneObject from "@/mirabuf/MirabufSceneObject"
44import RobotDimensionTracker from "@/systems/match_mode/RobotDimensionTracker"
55import SimulationSystem from "@/systems/simulation/SimulationSystem"
6+ import World from "@/systems/World"
7+ import SceneObject from "@/systems/scene/SceneObject"
68
79interface MockDimensions {
810 width : number
@@ -11,20 +13,30 @@ interface MockDimensions {
1113}
1214
1315interface MockRobotObject {
16+ _id : number | null
17+ id : number
1418 assemblyName : string
1519 miraType : MiraType
1620 getDimensions : ( ) => MockDimensions
1721 getDimensionsWithoutRotation : ( ) => MockDimensions
22+ setup : ( ) => void
23+ update : ( ) => void
24+ dispose : ( ) => void
1825}
1926
2027interface MockNonRobotObject {
28+ _id : number | null
29+ id : number
2130 assemblyName : string
2231 miraType : MiraType
2332 getDimensions : ( ) => MockDimensions
33+ setup : ( ) => void
34+ update : ( ) => void
35+ dispose : ( ) => void
2436}
2537
2638interface MockSceneRenderer {
27- sceneObjects : Map < string , MockRobotObject | MockNonRobotObject >
39+ sceneObjects : Map < number , MockRobotObject | MockNonRobotObject >
2840}
2941
3042type TrackerUpdateParam = Parameters < typeof RobotDimensionTracker . update > [ 0 ]
@@ -48,7 +60,9 @@ vi.mock("@/systems/match_mode/MatchMode", () => ({
4860 DEFAULT_ENDGAME_TIME : 20 ,
4961 DEFAULT_IGNORE_ROTATION : true ,
5062 DEFAULT_MAX_HEIGHT : Infinity ,
51- DEFAULT_HEIGHT_PENALTY : 2 ,
63+ DEFAULT_HEIGHT_LIMIT_PENALTY : 2 ,
64+ DEFAULT_SIDE_MAX_EXTENSION : 1.5 ,
65+ DEFAULT_SIDE_EXTENSION_PENALTY : 2 ,
5266} ) )
5367
5468vi . mock ( "@/systems/simulation/SimulationSystem" , ( ) => ( {
@@ -57,6 +71,14 @@ vi.mock("@/systems/simulation/SimulationSystem", () => ({
5771 } ,
5872} ) )
5973
74+ vi . mock ( "@/systems/World" , ( ) => ( {
75+ default : {
76+ sceneRenderer : {
77+ sceneObjects : new Map ( ) ,
78+ } ,
79+ } ,
80+ } ) )
81+
6082describe ( "RobotDimensionTracker" , ( ) => {
6183 let mockSceneRenderer : MockSceneRenderer
6284 let mockRobot1 : MockRobotObject
@@ -66,8 +88,12 @@ describe("RobotDimensionTracker", () => {
6688 beforeEach ( ( ) => {
6789 vi . clearAllMocks ( )
6890
69- const tracker = RobotDimensionTracker as unknown as { _robotLastFramePenalty ?: Map < number , boolean > }
91+ const tracker = RobotDimensionTracker as unknown as {
92+ _robotLastFramePenalty ?: Map < number , boolean >
93+ _robotSize ?: Map < number , { width : number ; depth : number } >
94+ }
7095 tracker . _robotLastFramePenalty ?. clear ( )
96+ tracker . _robotSize ?. clear ( )
7197
7298 const robot1Base = Object . create ( MirabufSceneObject . prototype )
7399 const robot2Base = Object . create ( MirabufSceneObject . prototype )
@@ -97,34 +123,43 @@ describe("RobotDimensionTracker", () => {
97123 } )
98124
99125 mockNonRobot = {
126+ _id : 3 ,
127+ id : 3 ,
100128 assemblyName : "Field" ,
101129 miraType : MiraType . FIELD ,
102130 getDimensions : vi . fn ( ( ) => ( { height : 5.0 , width : 10.0 , depth : 10.0 } ) ) ,
131+ setup : vi . fn ( ) ,
132+ update : vi . fn ( ) ,
133+ dispose : vi . fn ( ) ,
103134 }
104135
105136 mockSceneRenderer = {
106137 sceneObjects : new Map ( [
107- [ "robot1" , mockRobot1 ] ,
108- [ "robot2" , mockRobot2 ] ,
109- [ "field" , mockNonRobot ] ,
138+ [ 1 , mockRobot1 ] ,
139+ [ 2 , mockRobot2 ] ,
140+ [ 3 , mockNonRobot ] ,
110141 ] ) ,
111142 }
143+
144+ World . sceneRenderer . sceneObjects . set ( 1 , mockRobot1 as unknown as SceneObject )
145+ World . sceneRenderer . sceneObjects . set ( 2 , mockRobot2 as unknown as SceneObject )
146+ World . sceneRenderer . sceneObjects . set ( 3 , mockNonRobot as unknown as SceneObject )
112147 } )
113148
114149 afterEach ( ( ) => {
115150 vi . restoreAllMocks ( )
116151 } )
117152
118153 test ( "config values determine which dimension method is used" , ( ) => {
119- RobotDimensionTracker . setConfigValues ( false , 2 , 15 )
154+ RobotDimensionTracker . setConfigValues ( false , 2 , 15 , 1.5 , 15 )
120155 RobotDimensionTracker . update ( mockSceneRenderer as unknown as TrackerUpdateParam )
121156
122157 expect ( mockRobot1 . getDimensions ) . toHaveBeenCalled ( )
123158 expect ( mockRobot1 . getDimensionsWithoutRotation ) . not . toHaveBeenCalled ( )
124159 } )
125160
126161 test ( "should penalize robot if it exceeds max height" , ( ) => {
127- RobotDimensionTracker . setConfigValues ( true , 3 , 5 )
162+ RobotDimensionTracker . setConfigValues ( true , 3 , 5 , 1.5 , 5 )
128163
129164 mockRobot1 . getDimensionsWithoutRotation = vi . fn ( ) . mockReturnValue ( { height : 2.0 , width : 1.0 , depth : 1.0 } )
130165 mockRobot2 . getDimensionsWithoutRotation = vi . fn ( ) . mockReturnValue ( { height : 3.5 , width : 1.0 , depth : 1.0 } )
@@ -139,8 +174,65 @@ describe("RobotDimensionTracker", () => {
139174 )
140175 } )
141176
177+ test ( "should penalize robot if it exceeds side max extension (width)" , ( ) => {
178+ RobotDimensionTracker . setConfigValues ( true , 10 , 5 , 0.5 , 2 )
179+
180+ mockRobot1 . getDimensions = vi . fn ( ) . mockReturnValue ( { height : 2.0 , width : 1.0 , depth : 1.0 } )
181+ mockRobot1 . getDimensionsWithoutRotation = vi . fn ( ) . mockReturnValue ( { height : 2.0 , width : 1.0 , depth : 1.0 } )
182+
183+ mockRobot2 . getDimensions = vi . fn ( ) . mockReturnValue ( { height : 2.0 , width : 1.0 , depth : 1.0 } )
184+ mockRobot2 . getDimensionsWithoutRotation = vi . fn ( ) . mockReturnValue ( { height : 2.0 , width : 1.0 , depth : 1.0 } )
185+
186+ RobotDimensionTracker . matchStart ( )
187+
188+ mockRobot2 . getDimensionsWithoutRotation = vi . fn ( ) . mockReturnValue ( { height : 2.0 , width : 1.7 , depth : 1.0 } )
189+
190+ RobotDimensionTracker . update ( mockSceneRenderer as unknown as TrackerUpdateParam )
191+
192+ expect ( SimulationSystem . robotPenalty ) . toHaveBeenCalledWith ( mockRobot2 , 2 , expect . any ( String ) )
193+ expect ( SimulationSystem . robotPenalty ) . not . toHaveBeenCalledWith (
194+ mockRobot1 ,
195+ expect . any ( Number ) ,
196+ expect . any ( String )
197+ )
198+ } )
199+
200+ test ( "should penalize robot if it exceeds side max extension (depth)" , ( ) => {
201+ RobotDimensionTracker . setConfigValues ( true , 10 , 5 , 0.3 , 3 )
202+
203+ mockRobot1 . getDimensions = vi . fn ( ) . mockReturnValue ( { height : 2.0 , width : 1.0 , depth : 1.2 } )
204+ mockRobot1 . getDimensionsWithoutRotation = vi . fn ( ) . mockReturnValue ( { height : 2.0 , width : 1.0 , depth : 1.2 } )
205+
206+ mockRobot2 . getDimensions = vi . fn ( ) . mockReturnValue ( { height : 2.0 , width : 1.0 , depth : 1.2 } )
207+ mockRobot2 . getDimensionsWithoutRotation = vi . fn ( ) . mockReturnValue ( { height : 2.0 , width : 1.0 , depth : 1.2 } )
208+
209+ RobotDimensionTracker . matchStart ( )
210+
211+ mockRobot2 . getDimensionsWithoutRotation = vi . fn ( ) . mockReturnValue ( { height : 2.0 , width : 1.0 , depth : 1.7 } )
212+
213+ RobotDimensionTracker . update ( mockSceneRenderer as unknown as TrackerUpdateParam )
214+
215+ expect ( SimulationSystem . robotPenalty ) . toHaveBeenCalledWith ( mockRobot2 , 3 , expect . any ( String ) )
216+ expect ( SimulationSystem . robotPenalty ) . not . toHaveBeenCalledWith (
217+ mockRobot1 ,
218+ expect . any ( Number ) ,
219+ expect . any ( String )
220+ )
221+ } )
222+
223+ test ( "should not penalize a robot for side extension if initial dimensions were not recorded" , ( ) => {
224+ RobotDimensionTracker . setConfigValues ( false , 10 , 5 , 0.3 , 3 )
225+
226+ mockRobot1 . getDimensions = vi . fn ( ) . mockReturnValue ( { height : 2.0 , width : 1.0 , depth : 1.2 } )
227+ mockRobot2 . getDimensions = vi . fn ( ) . mockReturnValue ( { height : 2.0 , width : 1.0 , depth : 1.2 } )
228+
229+ RobotDimensionTracker . update ( mockSceneRenderer as unknown as TrackerUpdateParam )
230+
231+ expect ( SimulationSystem . robotPenalty ) . not . toHaveBeenCalled ( )
232+ } )
233+
142234 test ( "should not penalize robot every frame" , ( ) => {
143- RobotDimensionTracker . setConfigValues ( true , 3 , 5 )
235+ RobotDimensionTracker . setConfigValues ( true , 3 , 5 , 1.5 , 5 )
144236
145237 mockRobot1 . getDimensionsWithoutRotation = vi . fn ( ) . mockReturnValue ( { height : 12 , width : 1.0 , depth : 1.0 } )
146238
@@ -151,7 +243,7 @@ describe("RobotDimensionTracker", () => {
151243 } )
152244
153245 test ( "should penalize multiple robots" , ( ) => {
154- RobotDimensionTracker . setConfigValues ( true , 3.048 , 5 )
246+ RobotDimensionTracker . setConfigValues ( true , 3.048 , 5 , 1.5 , 5 )
155247
156248 mockRobot1 . getDimensionsWithoutRotation = vi . fn ( ) . mockReturnValue ( { height : 12 , width : 1.0 , depth : 1.0 } )
157249 mockRobot2 . getDimensionsWithoutRotation = vi . fn ( ) . mockReturnValue ( { height : 12 , width : 1.0 , depth : 1.0 } )
@@ -162,7 +254,7 @@ describe("RobotDimensionTracker", () => {
162254 } )
163255
164256 test ( "should not penalize robot if it is not a robot" , ( ) => {
165- RobotDimensionTracker . setConfigValues ( true , 3 , 5 )
257+ RobotDimensionTracker . setConfigValues ( true , 3 , 5 , 1.5 , 5 )
166258
167259 mockNonRobot . getDimensions = vi . fn ( ) . mockReturnValue ( { height : 12 , width : 1.0 , depth : 1.0 } )
168260
0 commit comments