public void StartTracks(Coaster coaster) { List <BuildAction> buildActions = new List <BuildAction>(); //Stright for (int i = 0; i < (22); i++) { buildActions.Add(new BuildAction(TrackType.Stright)); } //Left for (int i = 0; i < (4 * 3); i++) { buildActions.Add(new BuildAction(TrackType.Left)); } //Stright 5 for (int i = 0; i < (11); i++) { buildActions.Add(new BuildAction(TrackType.Stright)); } BuildTracks(buildActions, coaster); coaster.NewChunks[coaster.NewChunkCount] = (coaster.NewTrackCount); coaster.NewChunkCount++; coaster.Merge(true); coaster.TracksStarted = true; }
public static bool CollisonNewTracks(Coaster coaster, float x, float y, float z) { int count = 0; foundIndex = 0; float j = 0; float q = 0; float g = 0; for (int i = 0; i < coaster.NewTrackCount; i++) { count++; if (count > coaster.NewTrackCount - 3) { return(true); } j = x - coaster.NewTracks[i].X; q = y - coaster.NewTracks[i].Y; g = z - coaster.NewTracks[i].Z; if (Math.Sqrt((j * j) + (q * q) + (g * g)) <= Globals.TRACK_LENGTH_2X) { return(false); } } return(true); }
public static TaskResults Run(Coaster coaster) { TaskResults taskResults = TaskResults.Successful; taskResults = BuildToYaw.Run( coaster, new List <float>() { MathHelper.KeepBetween360Degrees(coaster.Tracks[Rules.lastCollsionIndex].Yaw), MathHelper.KeepBetween360Degrees(coaster.Tracks[Rules.lastCollsionIndex].Yaw + 180), MathHelper.KeepBetween360Degrees(Builder.lastRuleIssueTrack.Yaw + 180) }); return(taskResults); //if(taskResults == TaskResults.Successful) //{ // return taskResults; //} ////Go To XYZ //float x = coaster.LastTrack.X; //float y = coaster.LastTrack.Y; //float z = coaster.LastTrack.Z; ////Determine //x = x + (float)(Math.Cos(MathHelper.ToRadians(coaster.LastTrack.Yaw)) * Math.Cos(MathHelper.ToRadians(coaster.LastTrack.Pitch)) * Globals.TRACK_LENGTH * 10); //y = y + (float)(Math.Sin(MathHelper.ToRadians(coaster.LastTrack.Yaw)) * Math.Cos(MathHelper.ToRadians(coaster.LastTrack.Pitch)) * Globals.TRACK_LENGTH * 10); //z = z + (float)(Math.Sin(MathHelper.ToRadians(coaster.LastTrack.Pitch)) * Globals.TRACK_LENGTH * 10); ////Check if there in bonunds and that there is no track at that location ////Try To Build To them ////If Fail return fail. }
public void Reset() { coaster = new Coaster(); builder.StartTracks(coaster); Stopwatch sw = new Stopwatch(); sw.Start(); }
public static TaskResults Run(Coaster coaster) { List <float> angles = new List <float>() { 90, 270, MathHelper.KeepBetween360Degrees(Builder.lastRuleIssueTrack.Yaw + 180) }; return(BuildToYaw.Run(coaster, angles)); }
public TaskResults Run(Coaster coaster) { List <BuildAction> buildActions = new List <BuildAction>(); buildActions.Add(new BuildAction(TrackType.Left)); buildActions.Add(new BuildAction(TrackType.Left)); buildActions.Add(new BuildAction(TrackType.Left)); return(Builder.BuildTracks(buildActions, coaster)); }
public TaskResults Run(Coaster coaster) { List <Command> commands = new List <Command>(); List <BuildAction> buildActions = new List <BuildAction>(); buildActions.Add(new BuildAction(TrackType.Down)); buildActions.Add(new BuildAction(TrackType.Down)); buildActions.Add(new BuildAction(TrackType.Down)); return(Builder.BuildTracks(buildActions, coaster)); }
public TaskResults Run(Coaster coaster) { TaskResults results = RCLibrary.Support.BuildToXY.Run( coaster, Globals.FINSH_AREA_X, Globals.FINSH_AREA_Y, Globals.FINSH_AREA_X_RANGE, Globals.FINSH_AREA_Y_RANGE); return(results); }
public TaskResults Run(Coaster coaster) { List <Command> commands = new List <Command>(); List <BuildAction> buildActions = new List <BuildAction>(); for (int i = 0; i < 3; i++) { buildActions.Add(new BuildAction(TrackType.Stright)); } return(Builder.BuildTracks(buildActions, coaster)); }
public TaskResults Run(Coaster coaster) { List <BuildAction> buildActions = new List <BuildAction>(); for (int i = 0; i < 24; i++) { buildActions.Add(new BuildAction(TrackType.Custom, .5f, Globals.STANDARD_ANGLE_CHANGE)); } for (int i = 0; i < 24; i++) { buildActions.Add(new BuildAction(TrackType.Custom, -.5f, Globals.STANDARD_ANGLE_CHANGE)); } return(Builder.BuildTracks(buildActions, coaster)); }
public bool ProcessBuildAction(Coaster coaster, BuilderTask task) { if (coaster.TracksStarted == false || (lastBuildActionFail && task.GetType() == lastBuildTask.GetType())) { return(false); } TaskResults results = task.Run(coaster); initialTaskResults = results; initialTaskResults = results; lastBuildTask = task; return(ProcessAfterBuildAttempt(coaster, results)); }
public TaskResults Run(Coaster coaster) { if (coaster.ChunkCount == 1) { return(TaskResults.RemoveStartingTracks); } List <BuildAction> buildActions = new List <BuildAction>(); for (int i = 0; i < coaster.Chunks[coaster.ChunkCount - 1]; i++) { buildActions.Add(new BuildAction(true)); } return(Builder.BuildTracks(buildActions, coaster, true)); }
public static bool CollisonX(Coaster coaster, float xA, float yA, float zA) { //IQNORE 3 + All "Back Tracks" int trackMaxPosition = coaster.TrackCountBuild - 3; int xT = (int)(xA / Globals.X_REGION_LENGTH); int yT = (int)(yA / Globals.Y_REGION_LENGTH); int zT = (int)(zA / Globals.Z_REGION_LENGTH); float j = 0; float q = 0; float g = 0; for (int x = xT - 1; x <= xT + 1; x++) { for (int y = yT - 1; y <= yT + 1; y++) { for (int z = zT - 1; z <= zT + 1; z++) { if (x >= 0 && x < Globals.REGIONS && y >= 0 && y < Globals.REGIONS && z >= 0 && z < Globals.REGIONS && coaster.Regions[x, y, z] != null) { foreach (Track t in coaster.Regions[x, y, z]) { j = xA - t.X; q = yA - t.Y; g = zA - t.Z; if ((Math.Sqrt((j * j) + (q * q) + (g * g)) <= Globals.TRACK_LENGTH_2X) && (t.Position < trackMaxPosition)) { lastCollsionIndex = t.Position; return(false); } } } } } } //Check New Tracks return(CollisonNewTracks(coaster, xA, yA, zA)); }
public TaskResults Run(Coaster coaster) { List <Command> commands = new List <Command>(); List <BuildAction> buildActions = new List <BuildAction>(); TaskResults result = TaskResults.Fail; bool loopDetected = true; for (int i = coaster.TrackCount - 42; i < coaster.TrackCount; i++) { if (coaster.Tracks[i].TrackType != TrackType.Up) { loopDetected = false; } } if (loopDetected) { for (int i = 0; i < 42; i++) { buildActions.Add(new BuildAction(true)); } result = Builder.BuildTracks(buildActions, coaster); if (result != TaskResults.Fail) { return((new BuildLoop()).Run(coaster)); } else { return(result); } } else { buildActions.Add(new BuildAction(TrackType.Up)); buildActions.Add(new BuildAction(TrackType.Up)); buildActions.Add(new BuildAction(TrackType.Up)); return(Builder.BuildTracks(buildActions, coaster)); } }
public static TaskResults RemoveTrack(Coaster coaster, bool removeChunk) { if (coaster.NewTrackCount == 0 && coaster.TrackCountBuild == 45) { return(TaskResults.OutOfBounds); } else { if (coaster.NewTrackCount > 0) { coaster.NewTrackCount--; } else if (removeChunk == true || coaster.LastTrack.TrackType != TrackType.Custom) { coaster.TrackCountBuild--; } else { return(TaskResults.RemoveCustomTrack); } } return(TaskResults.Successful); }
public TaskResults Run(Coaster coaster) { TaskResults results = TaskResults.Fail; List <BuildAction> buildActions = new List <BuildAction>(); if (coaster.LastTrack.Pitch == 0) { buildActions.Add(new BuildAction(TrackType.Custom)); for (int i = 0; i < 3; i++) { buildActions.Add(new BuildAction(TrackType.Custom)); } results = Builder.BuildTracks(buildActions, coaster); } else { results = BuildToPitch.Run(coaster, new List <float>() { 0 }); } return(results); }
public static TaskResults BuildTracks(List <BuildAction> buildActions, Coaster coaster, bool removeChunk = false) { //Check If Coater Finshed TaskResults result = TaskResults.Successful; foreach (BuildAction buildAction in buildActions) { if (buildAction.RemoveTrack == false) { result = BuildTrack(coaster, buildAction); } else { result = RemoveTrack(coaster, removeChunk); } if (result != TaskResults.Successful) { break; } } return(result); }
public static TaskResults BuildTrack(Coaster coaster, BuildAction action) { //Check If Coater Finshed float yaw = 0; float pitch = 0; float x = 0; float y = 0; float z = 0; Track lastTrack = new Track(); //Determine Starting Position if (coaster.TrackCountBuild == 0 && coaster.NewTrackCount == 0) { yaw = Globals.START_YAW; pitch = Globals.START_PITCH; x = Globals.START_X; y = Globals.START_Y; z = Globals.START_Z; } else { if (coaster.NewTrackCount > 0) { lastTrack = coaster.NewTracks[coaster.NewTrackCount - 1]; } else { lastTrack = coaster.LastTrack; } yaw = lastTrack.Yaw; pitch = lastTrack.Pitch; x = lastTrack.X; y = lastTrack.Y; z = lastTrack.Z; //Determine Yaw And Pitch switch (action.TrackType) { case TrackType.Stright: break; case TrackType.Left: yaw = yaw + Globals.STANDARD_ANGLE_CHANGE; break; case TrackType.Right: yaw = yaw - Globals.STANDARD_ANGLE_CHANGE; break; case TrackType.Up: pitch = pitch + Globals.STANDARD_ANGLE_CHANGE; break; case TrackType.Down: pitch = pitch - Globals.STANDARD_ANGLE_CHANGE; break; case TrackType.Custom: yaw = yaw + action.YawOffset; pitch = pitch + action.PitchOffset; break; } //IF X out of 360 if (yaw < 0) { yaw += 360; } if (yaw >= 360) { yaw += -360; } if (pitch < 0) { pitch += 360; } if (pitch >= 360) { pitch += -360; } //IF Y out of 360 //Determine X, Y, And Z x = lastTrack.X + (float)(Math.Cos(MathHelper.ToRadians(lastTrack.Yaw)) * Math.Cos(MathHelper.ToRadians(lastTrack.Pitch)) * Globals.HALF_TRACK_LENGTH) + (float)(Math.Cos(MathHelper.ToRadians(yaw)) * Math.Cos(MathHelper.ToRadians(pitch)) * Globals.HALF_TRACK_LENGTH); y = lastTrack.Y + (float)(Math.Sin(MathHelper.ToRadians(lastTrack.Yaw)) * Math.Cos(MathHelper.ToRadians(lastTrack.Pitch)) * Globals.HALF_TRACK_LENGTH) + (float)(Math.Sin(MathHelper.ToRadians(yaw)) * Math.Cos(MathHelper.ToRadians(pitch)) * Globals.HALF_TRACK_LENGTH); z = lastTrack.Z + (float)(Math.Sin(MathHelper.ToRadians(lastTrack.Pitch)) * Globals.HALF_TRACK_LENGTH) + (float)(Math.Sin(MathHelper.ToRadians(pitch)) * Globals.HALF_TRACK_LENGTH); } //Check Rules TaskResults result = CheckRules(coaster, x, y, z, yaw, pitch, action.TrackType); //Add Track if (TaskResults.Successful == result) { coaster.NewTracks[coaster.NewTrackCount] = new Track() { X = x, Y = y, Z = z, Pitch = pitch, Yaw = yaw, TrackType = action.TrackType }; // coaster.NewTracksQTree[coaster.NewTrackCount] = new TrackQuadTree(coaster.NewTracks[coaster.NewTrackCount]); // coaster.QTree.Add(coaster.NewTracksQTree[coaster.NewTrackCount]); coaster.NewTrackCount++; } return(result); }
public static TaskResults Run(Coaster coaster) { return(BuildToPitch.Run(coaster, angles)); }
public static bool CollisonGroupCheck(Coaster coaster) { float minX = coaster.NewTracks[0].X; float minY = coaster.NewTracks[0].Y; float maxX = coaster.NewTracks[0].X; float maxY = coaster.NewTracks[0].Y; float totalX = 0; float totalY = 0; for (int i = 0; i < coaster.NewTrackCount; i++) { totalX += coaster.NewTracks[i].X; totalY += coaster.NewTracks[i].Y; if (minX > coaster.NewTracks[i].X) { minX = coaster.NewTracks[i].X; } if (minY > coaster.NewTracks[i].Y) { minY = coaster.NewTracks[i].Y; } if (maxX < coaster.NewTracks[i].X) { maxX = coaster.NewTracks[i].X; } if (maxY < coaster.NewTracks[i].Y) { maxY = coaster.NewTracks[i].Y; } } float midX = totalX / coaster.NewTrackCount; float midY = totalY / coaster.NewTrackCount; float length = (float)(Math.Sqrt(Math.Pow(maxX - minX, 2) + Math.Pow(maxY - minY, 2))); List <Track> tracks = new List <Track>(); int count = 0; float deltaXSquared = 0; float deltaYSquared = 0; float sumRadiiSquared = 0; for (int i = 0; i < coaster.TrackCountBuild; i++) { if (count > coaster.TrackCountBuild - 2) { } else { deltaXSquared = midX - coaster.Tracks[i].X; // calc. delta X deltaXSquared *= deltaXSquared; // square delta X deltaYSquared = midY - coaster.Tracks[i].Y; // calc. delta Y deltaYSquared *= deltaYSquared; // square delta Y // Calculate the sum of the radii, then square it sumRadiiSquared = Globals.TRACK_LENGTH + length; sumRadiiSquared *= sumRadiiSquared; if (deltaXSquared + deltaYSquared <= sumRadiiSquared) { tracks.Add(coaster.Tracks[i]); } } } // if (tracks.Count == 0) { return(true); } for (int x = 0; x < tracks.Count; x++) { count = 0; for (int i = 0; i < coaster.TrackCountBuild; i++) { count++; if (count > coaster.TrackCountBuild - 2) { } else { deltaXSquared = coaster.NewTracks[x].X - coaster.Tracks[i].X; // calc. delta X deltaXSquared *= deltaXSquared; // square delta X deltaYSquared = coaster.NewTracks[x].Y - coaster.Tracks[i].Y; // calc. delta Y deltaYSquared *= deltaYSquared; // square delta Y // Calculate the sum of the radii, then square it sumRadiiSquared = Globals.TRACK_LENGTH; sumRadiiSquared *= sumRadiiSquared; if (deltaXSquared + deltaYSquared <= sumRadiiSquared) { // return false; } } } } return(true); //count = 0; //for (int i = 0; i < coaster.NewTrackCount; i++) //{ // count++; // if (count > coaster.NewTrackCount - 2) // { // // sw.Stop(); // return true; // } // deltaXSquared = (x - coaster.NewTracks[i].X); // calc. delta X // deltaXSquared *= deltaXSquared; // square delta X // deltaYSquared = y - coaster.NewTracks[i].Y; // calc. delta Y // deltaYSquared *= deltaYSquared; // square delta Y // // Calculate the sum of the radii, then square it // sumRadiiSquared = Globals.TRACK_LENGTH; // sumRadiiSquared *= sumRadiiSquared; // if (deltaXSquared + deltaYSquared <= sumRadiiSquared) // { // // sw.Stop(); // return false; // } //} //// sw.Stop(); //return true; }
public bool ProcessAfterBuildAttempt(Coaster coaster, TaskResults results, string lastTaskName = "") { this.lastTaskName = lastTaskName; if (results != TaskResults.Successful) { coaster.Reset(); } switch (results) { case TaskResults.MaxX: results = FixX.Run(coaster); break; case TaskResults.MaxY: results = FixY.Run(coaster); break; case TaskResults.MinX: results = FixX.Run(coaster); break; case TaskResults.MinY: results = FixY.Run(coaster); break; case TaskResults.MinZ: results = FixZ.Run(coaster); break; case TaskResults.Collison: results = FixTrackCollison.Run(coaster); break; } if (results == TaskResults.Successful) { //Chunk anything that has not already been Chunked int totalNewTracksChunked = 0; for (int i = 0; i < coaster.NewChunkCount; i++) { totalNewTracksChunked += coaster.NewChunks[i]; } int tracksWihtNoChunk = coaster.NewTrackCount - totalNewTracksChunked; if (tracksWihtNoChunk > 0) { coaster.NewChunks[coaster.NewChunkCount] = tracksWihtNoChunk; coaster.NewChunkCount++; } lastBuildActionFail = false; coaster.Merge(); return(true); } else { lastBuildActionFail = true; coaster.Reset(); return(false); } }
private static TaskResults CheckRules(Coaster coaster, float x, float y, float z, float yaw, float pitch, TrackType trackType) { TaskResults result = TaskResults.Successful; if (coaster.TracksStarted == false || coaster.TracksInFinshArea == true) { return(result); } if (!Rules.AngleCheck(yaw, pitch, trackType)) { result = TaskResults.Angle; } if (!Rules.MaxX(x)) { result = TaskResults.MaxX; } else if (!Rules.MaxY(y)) { result = TaskResults.MaxY; } else if (!Rules.MinX(x)) { result = TaskResults.MinX; } else if (!Rules.MinY(y)) { result = TaskResults.MinY; } else if (!Rules.MinZ(yaw, pitch, z)) { result = TaskResults.MinZ; } else if (!Rules.MaxZ(z)) { result = TaskResults.MaxZ; } else if (!Rules.CollisonX(coaster, x, y, z)) { result = TaskResults.Collison; } if (result != TaskResults.Successful) { lastRuleIssueTrack = new Track() { X = x, Y = y, Z = z, Yaw = yaw, Pitch = pitch, TrackType = trackType } } ; return(result); } }