public static void TechniteStateChunk(Protocol.Client cl, Struct.TechniteStateChunk chunk) { Out.Log(Significance.Common, "Received technite state chunk containing " + chunk.states.Length + " technites"); if (chunk.FlagIsSet(Struct.TechniteChunkFlags.IsFirst)) { Technite.Reset(); } foreach (var state in chunk.states) { Technite.CreateOrUpdate(state); } if (chunk.FlagIsSet(Struct.TechniteChunkFlags.IsLast)) { Technite.Cleanup(); } }
public static void InstructTechnites(Protocol.Client cl, Struct.InstructTechnites instruct) { Technite.Cleanup(); //updates must be done by now Session.roundNumber = instruct.roundNumber; Session.techniteSubRoundNumber = instruct.techniteSubRoundNumber; Out.Log(Significance.Common, "Instructing technites in round " + Session.roundNumber + "/" + Session.techniteSubRoundNumber); Logic.ProcessTechnites(); SendColorState(cl); int numTechnites = Technite.Count; int numChunks = numTechnites / Struct.TechniteInstructionChunk.MaxPerChunk; if ((numTechnites % Struct.TechniteInstructionChunk.MaxPerChunk) != 0) { numChunks++; } Out.Log(Significance.Common, "Sending " + numChunks + " technite data response chunks"); var e = Technite.All.GetEnumerator(); int offset = 0; for (int i = 0; i < numChunks; i++) { int chunkSize = Math.Min(Struct.TechniteInstructionChunk.MaxPerChunk, numTechnites - offset); Struct.TechniteInstructionChunk chunk = new Struct.TechniteInstructionChunk(); chunk.offset = (uint)offset; chunk.instructions = new Struct.TechniteInstruction[chunkSize]; for (int j = 0; j < chunkSize; j++) { bool success = e.MoveNext(); Debug.Assert(success); Technite t = e.Current; chunk.instructions[j] = t.ExportInstruction(); } techniteInstructionChunk.SendTo(cl, chunk); offset += chunkSize; } }
/// <summary> /// Determines a feasible, possibly ideal neighbor technite target, based on a given evaluation function /// </summary> /// <param name="location"></param> /// <param name="f">Evaluation function. Must return 0/NotAChoice if not applicable, and >1 otherwise. Higher values indicate higher probability</param> /// <returns>Chocen relative cell, or Grid.RelativeCell.Invalid if none was found.</returns> public static Grid.RelativeCell EvaluateNeighborTechnites(Grid.CellID location, Func <Grid.RelativeCell, Technite, int> f) { return(EvaluateChoices(location, (relative, cell) => { Grid.Content content = Grid.World.GetCell(cell).content; if (content != Grid.Content.Technite) { return NotAChoice; } Technite other = Technite.Find(cell); if (other == null) { Out.Log(Significance.Unusual, "Located neighboring technite in " + cell + ", but cannot find reference to class instance"); return NotAChoice; } return f(relative, other); } )); }
static void Main(string[] args) { Console.CancelKeyPress += new ConsoleCancelEventHandler(onCancel); //Logging.Out.StartService(); //if multiple instances are started, the binding to a fixed ip is bad, so no service if (args.Length < 1) { Console.Error.WriteLine("Missing parameters. Use 'exe [port]'. Exiting"); ShutDown(-1); return; } ushort serverPort; if (!ushort.TryParse(args[0], out serverPort)) { Console.Error.WriteLine("Unable to parse parameter '" + args[0] + "' to port number. Exiting"); ShutDown(-1); return; } Interface.Register(); System.Threading.Thread.Sleep(100); for (;;) { Client client = new Client(); Out.Log(Logging.Significance.Important, "Connecting to server on port " + serverPort); client.Connect(serverPort); Grid.FlushAllData(); Technite.FlushAllData(); Objects.FlushAllData(); System.Threading.Thread.Sleep(2000); } //ShutDown(0); }
/// <summary> /// Determines a feasible neighborhood cell that can work as a replication destination. /// </summary> /// <param name="location"></param> /// <returns></returns> public static Grid.RelativeCell GetSplitTarget(Grid.CellID location) { return(EvaluateChoices(location, (relative, cell) => { Grid.Content content = Grid.World.GetCell(cell).content; int rs = 100; if (content != Grid.Content.Clear && content != Grid.Content.Water) { rs -= 90; } if (Grid.World.GetCell(cell.TopNeighbor).content == Grid.Content.Technite) { return NotAChoice; //probably a bad idea to split beneath technite } if (Technite.EnoughSupportHere(cell)) { return relative.HeightDelta + rs; } return NotAChoice; } )); }
/// <summary> /// Visually marks a world cell. /// The markings are bulk-transferred to the server at the end of the next Logic.ProcessTechnites() invokation. /// Older markings are preserved at reduced opacity. /// Visualization occurs in the form of a vertical bar atop the marked cell. /// The marking may be invisible, if the chosen layer is submerged too deeply. /// </summary> /// <param name="cell">Cell to visually mark.</param> /// <param name="c">Color to use. The rendering uses additive blending equations. Dark colors will be less visible, black will be invisible.</param> public static void Mark(CellID cell, Technite.Color c) { Interface.MarkCell(new Technite.CompressedLocation(cell).Data, new Interface.Struct.RGB8(c)); }
public TaskException(Technite t, string message) : base(message) { SourceTechnite = t; }