-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathBallPrediction.cs
More file actions
80 lines (65 loc) · 2.31 KB
/
BallPrediction.cs
File metadata and controls
80 lines (65 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
using System.Diagnostics;
using Bridge.Models.Phys;
using Bridge.State;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using RLBotCS.Conversion;
using RLBotCS.ManagerTools;
namespace RLBotCSTests;
[TestClass]
public class BallPrediction
{
private TestContext? testContextInstance;
/// <summary>
/// Gets or sets the test context which provides
/// information about and functionality for the current test run.
/// </summary>
public TestContext TestContext
{
get { return testContextInstance!; }
set { testContextInstance = value; }
}
[TestMethod]
public void TestBallPred()
{
BallPredictor.SetMode(PredictionMode.Standard);
var packet = new GameState();
packet.Balls[12345] = new();
var gTP = packet.ToFlatBuffers();
BallPredictor.Generate(1, gTP.Balls[0], null, -650f);
packet.Balls[12345].Physics = new Physics(
new Vector3(0, 0, 1.1f * 91.25f),
new Vector3(600, 1550, 0),
new Vector3(0, 0, 0),
new Rotator(0, 0, 0)
);
var gTP2 = packet.ToFlatBuffers();
var ballPred = BallPredictor.Generate(1, gTP2.Balls[0], null, -650f);
int numSlices = 6 * 120;
Assert.HasCount(numSlices, ballPred.Slices);
Assert.IsInRange(6.9999, 7.0001, ballPred.Slices[numSlices - 1].GameSeconds);
// comment out to see results of the below test
// dotnet test -c "Release" for best results
return;
Stopwatch stopWatch = new Stopwatch();
int numIterations = 20_000;
for (int i = 0; i < numIterations; i++)
{
packet.Balls[12345].Physics = new Physics(
new Vector3(0, 0, 1.1f * 91.25f),
new Vector3(600, 1550, 0),
new Vector3(0, 0, 0),
new Rotator(0, 0, 0)
);
var gTP3 = packet.ToFlatBuffers();
stopWatch.Start();
BallPredictor.Generate(1, gTP3.Balls[0], null, -650f);
stopWatch.Stop();
}
float averageTime = (float)stopWatch.ElapsedMilliseconds / numIterations;
TestContext.WriteLine(
"Average time to generate ball prediction: " + averageTime + "ms"
);
// makes the above result print out
Assert.Fail();
}
}