private void runAgentButton_Click(object sender, EventArgs e) { // TODO put stuff on input-link // TODO this should also be in output handler foreach (var entry in changes) { // create an ID on input link sml.Identifier squareID = agent.GetInputLink().CreateIdWME("square"); // add x, y, and color squareID.CreateIntWME("x", entry.Key.Item1); squareID.CreateIntWME("y", 19 - entry.Key.Item2); squareID.CreateStringWME("color", entry.Value.ToString().ToLower()); } // clear color changes changes.Clear(); // TODO run agent agent.RunSelf(1); }
//public delegate void UpdateEventCallback(smlUpdateEventId eventID, IntPtr callbackData, IntPtr kernel, smlRunFlags runFlags); public void HandleAgentOuput(sml.smlUpdateEventId eventID, IntPtr data, IntPtr kernel, sml.smlRunFlags runFlags) { // get stuff from output-link sml.Identifier moveCommand = agent.GetCommand("move"); if (moveCommand != null) { // get placement info sml.Identifier placement = moveCommand.FindIDByAttribute("placement"); if (placement != null) { // iterate over squares foreach (sml.Identifier squareID in placement.GetIDChildren("square")) { // get x,y from command int x = (int)squareID.FindIntByAttribute("x"); int y = (int)squareID.FindIntByAttribute("y"); // color square in board view ((Square)boardView[x, 19 - y].Value).color = BlokusColor.Blue; boardView.InvalidateCell(x, 19 - y); // put change in change list to send back to agent changes[Tuple.Create(x, 19 - y)] = BlokusColor.Blue; } // clear output changes agent.ClearOutputLinkChanges(); // mark command as complete moveCommand.AddStatusComplete(); agent.Commit(); } else { Console.WriteLine("Error getting placement info: placement attribute DNE"); } } }
public AttributeNotFoundException(string attr, sml.Identifier el) { attribute = attr; element = el; }