Newer
Older
using System.Linq;
Marco Zimmer
committed
using System.Collections.Generic;
using UnityEngine;
using static CommunicationEvents;
using static UnityEditor.PlayerSettings;
using static CanonBallProblemCalculator;
using Unity.Mathematics;
using System;
Marco Zimmer
committed
public class GenerateDemoFiles
{
public static void GenerateAll()
{
if (UnityEngine.Object.FindObjectOfType<GadgetBehaviour>(true) == null)
Debug.LogError("Cannot GenerateDemoFiles without populated GadgetManager");
return;
}
Marco Zimmer
committed
Debug.LogWarning("Generating and Overwriting Stage Files");
Action[] DemoGeneration = new Action[]{
GenerateTreeStage,
GenerateRiverStage,
GenerateCanonBallStage
};
foreach (Action action in DemoGeneration)
try
{
action();
Debug.Log("Successfully executed " + action.Method.Name);
}
catch (Exception ex)
{
Debug.LogError("Exception while executing " + action.Method.Name);
Debug.LogException(ex);
}
StageStatic.StageOfficial = null;
StageStatic.StageLocal = null;
Marco Zimmer
committed
}
Marco Zimmer
committed
{
// Params
float minimalSolutionHight = 6;
// Generate Stage
(
number: 1,
category: "Demo Category",
name: "TechDemo A",
scene: "RiverWorld",
description: "Tree Stage",
local: false
);
Marco Zimmer
committed
// needed to generate facts
Marco Zimmer
committed
StageStatic.StageOfficial = new Dictionary<string, Stage>
Marco Zimmer
committed
{
{ demo.name, demo },
};
Marco Zimmer
committed
StageStatic.SetStage(demo.name, false);
Marco Zimmer
committed
// Populate Solution
PointFact
Marco Zimmer
committed
buttom = new PointFact(Vector3.zero, Vector3.up, StageStatic.stage.solution),
top = new PointFact(Vector3.zero + Vector3.up * minimalSolutionHight, Vector3.up, StageStatic.stage.solution);
Marco Zimmer
committed
StageStatic.stage.solution.Add(buttom, out _, false, null, null);
StageStatic.stage.solution.Add(top, out _, true, null, null);
Marco Zimmer
committed
Marco Zimmer
committed
LineFact target = new LineFact(buttom.Id, top.Id, StageStatic.stage.solution);
var target_Id = StageStatic.stage.solution.Add(target, out _, true, null, null);
Marco Zimmer
committed
// Set Solution
Marco Zimmer
committed
StageStatic.stage.solution.ValidationSet =
Marco Zimmer
committed
{ new SolutionOrganizer.SubSolution(new HashSet<string> { target_Id }, null, null, new LineFactHightDirectionComparer()) };
Marco Zimmer
committed
StageStatic.stage.AllowedGadgets = null;
Marco Zimmer
committed
// Save
Marco Zimmer
committed
StageStatic.SetMode(StageStatic.Mode.Create);
StageStatic.stage.store(false, true);
Marco Zimmer
committed
}
{
// Params
float minimalSolutionHight = 6;
// Generate Stage
Stage demo = new Stage
(
number: 2,
category: "Demo Category",
name: "TechDemo B",
scene: "RiverWorld",
description: "River Stage",
local: false
);
// needed to generate facts
StageStatic.StageOfficial = new Dictionary<string, Stage>
{
{ demo.name, demo },
};
StageStatic.SetStage(demo.name, false);
// Populate Solution
PointFact
buttom = new PointFact(Vector3.zero, Vector3.up, StageStatic.stage.solution),
top = new PointFact(Vector3.zero + Vector3.up * minimalSolutionHight, Vector3.up, StageStatic.stage.solution);
StageStatic.stage.solution.Add(buttom, out _, false, null, null);
StageStatic.stage.solution.Add(top, out _, true, null, null);
LineFact target = new LineFact(buttom.Id, top.Id, StageStatic.stage.solution);
var target_Id = StageStatic.stage.solution.Add(target, out _, true, null, null);
// Set Solution
StageStatic.stage.solution.ValidationSet =
new List<SolutionOrganizer.SubSolution> {
new SolutionOrganizer.SubSolution(new HashSet<string> { target_Id }, null, null, new LineFactHightDirectionComparer()),
new SolutionOrganizer.SubSolution(new HashSet<string> { target_Id }, null, null, new LineSpanningOverRiverWorldComparer()),
new SolutionOrganizer.SubSolution(null, new List<int> { 1 }, new List<int> { 0 }, new LineFactHightComparer()),
};
StageStatic.stage.AllowedGadgets = new() { new Pointer(), new Tape(), new AngleTool(), new LineTool(), new LotTool(), new Pendulum(), new Remover() }; //, new EqualCircleGadget(), new TestMiddlePoint() };
StageStatic.stage.AllowedScrolls = new() {
"http://mathhub.info/FrameIT/frameworld?OppositeLen",
//"http://mathhub.info/FrameIT/frameworld?SupplementaryAngles",
//"http://mathhub.info/FrameIT/frameworld?AngleSum",
//"http://mathhub.info/FrameIT/frameworld?Pythagoras",
//"http://mathhub.info/FrameIT/frameworld?CylinderVolumeScroll",
//"http://mathhub.info/FrameIT/frameworld?CircleLineAngleToAngleScroll",
//"http://mathhub.info/FrameIT/frameworld?Midpoint",
//"http://mathhub.info/FrameIT/frameworld?CircleScroll",
//"http://mathhub.info/FrameIT/frameworld?CircleLineAngleScroll",
//"http://mathhub.info/FrameIT/frameworld?CircleAreaScroll",
//"http://mathhub.info/FrameIT/frameworld?ConeVolumeScroll",
//"http://mathhub.info/FrameIT/frameworld?TruncatedConeVolumeScroll",
};
Marco Zimmer
committed
StageStatic.SetMode(StageStatic.Mode.Create);
StageStatic.stage.store(false, true);
public static void GenerateCanonBallStage()
{
// Params //List<Wall> walls, T starPos, T starVec, T gravity, int dimension
int
dim_const = 0,
dim_A = 2,
dim_B = 1;
float Py_factor = 0.04905f;
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
float2 StartPos_py = new(380, 300);
float2 StartVec_py = new(-490, 150);
float2 Gravity_py = new(0, -200);
(int x, int y, int width, int angle_deg, double bounce)[] PythonParams = {
(250, 0, 50, 0, 2.0 ),
(0, 0, 400, 90, 0.9 ),
(400, 0, 400, 90, 0.9),
(0, 400, 400, 0, 0.9),
(50, 200, 100, 45, 1),
(150, 100, 50, 0, 0.9),
(200, 200, 100, 120, 0.9),
(300, 300, 80, 150, 0.9),
(300, 100, 100, 30, 0.8),
(50, 50, 100, 60, 0.9),
(300, 0, 100, 0, 0.4),
(0, 0, 250, 0, 0.1),
};
//Parse PythonParams
Vector3
StartPos = Vector3.zero,
StartVec = Vector3.zero,
Gravity = Vector3.zero;
StartPos[dim_A] = StartPos_py[0] * Py_factor;
StartPos[dim_B] = StartPos_py[1] * Py_factor;
StartVec[dim_A] = StartVec_py[0] * Py_factor;
StartVec[dim_B] = StartVec_py[1] * Py_factor;
Gravity[dim_A] = Gravity_py[0] * Py_factor;
Gravity[dim_B] = Gravity_py[1] * Py_factor;
float[,,] Wall_parameter = new float[PythonParams.Length, 2, 2];
float[] Bounce_parameter = new float[PythonParams.Length];
for (uint i = 0; i < PythonParams.Length; i++)
{
Wall_parameter[i, 0, 0] = Py_factor * (PythonParams[i].x);
Wall_parameter[i, 0, 1] = Py_factor * (PythonParams[i].y);
Wall_parameter[i, 1, 0] = Py_factor * (PythonParams[i].x + PythonParams[i].width * Mathf.Cos(MathfExtensions.ToRadians(PythonParams[i].angle_deg)));
Wall_parameter[i, 1, 1] = Py_factor * (PythonParams[i].y + PythonParams[i].width * Mathf.Sin(MathfExtensions.ToRadians(PythonParams[i].angle_deg)));
Bounce_parameter[i] = (float)PythonParams[i].bounce;
}
// Generate Stage
Stage demo = new Stage
(
number: 2,
category: "Demo Category",
name: "CanonBall A",
scene: "RiverWorld",
description: "CanonBall Test",
local: false
);
// needed to generate facts
StageStatic.StageOfficial = new Dictionary<string, Stage>
{
{ demo.name, demo },
};
StageStatic.SetStage(demo.name, false);
// Populate Solution
List<Wall> Walls = new();
for (int i = 0; i < PythonParams.Length; i++)
{
Vector3 tmpVec = Vector3.zero;
tmpVec[dim_A] = Wall_parameter[i, 0, 0];
tmpVec[dim_B] = Wall_parameter[i, 0, 1];
PointFact topA = new(tmpVec, Vector3.up, StageStatic.stage.solution);
string topAURI = StageStatic.stage.solution.Add(topA, out _, false, null, null);
tmpVec[dim_A] = Wall_parameter[i, 1, 0];
tmpVec[dim_B] = Wall_parameter[i, 1, 1];
PointFact topB = new(tmpVec, Vector3.up, StageStatic.stage.solution);
string topBURI = StageStatic.stage.solution.Add(topB, out _, true, null, null);
LineFact topology = new(topAURI, topBURI, StageStatic.stage.solution);
MaZiFAU
committed
string lineURI = StageStatic.stage.solution.Add(topology, out _, true, null, null);
StageStatic.stage.solution.ExposedSolutionFacts.Add(lineURI);
Walls.Add(new(topology, Bounce_parameter[i]));
}
// Set Solution
StageStatic.stage.solution.Add( // for CannonBallScroll
new ListFact(Walls.Select(w => w.Topology.Id).ToArray(), typeof(LineFact), StageStatic.stage.solution),
// special case for Prototype
string[] RRRRTupel = new string[Walls.Count];
for (int i = 0; i < Walls.Count; i++)
{
RRRRTupel[i] = StageStatic.stage.solution.Add(
new TupelFact(null,
new[] {
SOMDoc.MakeTupel(new OMF[] { new(Walls[i].Topology.Point1.Point[dim_A]), new(Walls[i].Topology.Point1.Point[dim_B]) }),
SOMDoc.MakeTupel(new OMF[] { new(Walls[i].Topology.Point2.Point[dim_A]), new(Walls[i].Topology.Point2.Point[dim_B]) }),
},
StageStatic.stage.solution),
out bool _, true, null, null
);
}
StageStatic.stage.solution.Add(
new ListFact(RRRRTupel, typeof(TupelFact), StageStatic.stage.solution),
out bool _, true, null, null
);
#endregion CannonBallScroll
string BallURI = StageStatic.stage.solution.Add(
new PointFact(StartPos, Vector3.up, StageStatic.stage.solution),
out _, false, null, null);
MaZiFAU
committed
StageStatic.stage.solution.ExposedSolutionFacts.Add(BallURI);
CanonBallProblemCalculator calc = new(Walls, StartPos, StartVec, Gravity, dim_const, dim_A, dim_B, StageStatic.stage.solution);
string attacheFactURI = StageStatic.stage.solution.Add(
new AttachedPositionFunction(BallURI, calc.Result_FuncCall_Id.ToArray(), StageStatic.stage.solution),
out _, true, null, null);
StageStatic.stage.solution.ExposedSolutionFacts.Add(attacheFactURI);
//StageStatic.stage.solution.ValidationSet =
// new List<SolutionOrganizer.SubSolution> {
// new SolutionOrganizer.SubSolution(new HashSet<string> { target_Id }, null, null, new LineFactHightDirectionComparer()),
// new SolutionOrganizer.SubSolution(new HashSet<string> { target_Id }, null, null, new LineSpanningOverRiverWorldComparer()),
// new SolutionOrganizer.SubSolution(null, new List<int> { 1 }, new List<int> { 0 }, new LineFactHightComparer()),
// };
// Set Gadgets/ Scrolls
StageStatic.stage.AllowedGadgets = null;
StageStatic.stage.AllowedScrolls = null;
// Save
StageStatic.SetMode(StageStatic.Mode.Create);
StageStatic.stage.store(false, true);
}