public void Init(int energy, Grid grid) { _grid = grid; _energy = energy; _exec.Score = 0; _nextEnergyReceiver = 0; _changeTracker.Clear(); }
private CoreSociety.Grid CreateGrid() { Grid grid = new Grid(Width, Height); int i = 0; foreach (XElement node in _xml.Descendants("grid").Descendants("core")) { Grid.Entry entry = grid.ListOfEntries[i++]; if (node.Value != "") entry.Core.Decode(node.Value); if (node.Attribute("color") != null) entry.Color = ColorFromHex(node.Attribute("color").Value); if (node.Attribute("listing") != null) entry.ListingID = int.Parse(node.Attribute("listing").Value); } return grid; }
/* * STATIC */ public static Scenario Create(Grid grid, int budget, IEnumerable<Listing> listings, string mission, bool writeCoreState) { XDocument xdoc = new XDocument( new XElement("scenario", new XElement("mission", new XText(mission)), new XElement("budget", new XText(budget.ToString())), new XElement("deck"), new XElement("grid", new XAttribute("width", grid.Width.ToString()), new XAttribute("height", grid.Height.ToString())) ) ); XElement deckNode = xdoc.Descendants("deck").First(); foreach (Listing listing in listings) { XElement listingNode = new XElement("listing"); listingNode.Value = listing.Lines.Aggregate((agg, token) => agg + "\n" + token); listingNode.SetAttributeValue("color", ColorToHex(listing.Color)); if(listing.Identity.IsValid) { string range = ByteToHex(listing.Identity.Min)+"-"+ByteToHex(listing.Identity.Max); listingNode.SetAttributeValue("idrange", range); } deckNode.Add(listingNode); } XElement gridNode = xdoc.Descendants("grid").First(); foreach (Grid.Entry entry in grid.ListOfEntries) { XElement coreNode = new XElement("core"); if (writeCoreState) coreNode.Value = entry.Core.Encode(); coreNode.SetAttributeValue("listing", entry.ListingID); coreNode.SetAttributeValue("color", ColorToHex(entry.Color)); gridNode.Add(coreNode); } return new Scenario(xdoc); }