public void Generate(Dictionary <String, int[]> dmAndItems, String filename) { /* * * ScriptGenerator sg = new ScriptGenerator(); * int[] bamsItems = new int[] { 9, 26, 33, 23, 29, 10, 37, 65, 16, 39, 32, 4, 31, 21, 53, 30, 59, 8, 17, 38 }; * int[] fireScoutItems = new int[] { 45, 19, 35, 58, 17, 46, 68, 71, 11, 37, 7, 43, 14, 57, 61, 20, 55, 12, 64, 66 }; * Dictionary<String,int[]> dict = new Dictionary<String, int[]>(); * dict.Add("BAMS DM", bamsItems); * dict.Add("Firescout DM", fireScoutItems); * sg.Generate(dict, "CalibrationScenario2"); * */ List <ScheduledItem> allScheduledItems = new List <ScheduledItem>(); foreach (String dm_id in dmAndItems.Keys) { ScheduledItem[] scheduledItems = MakeScheduledItemsForDM(dm_id, dmAndItems[dm_id]); allScheduledItems.AddRange(scheduledItems); } T_SeamateItems seamateItems = new T_SeamateItems(); seamateItems.Timeline = allScheduledItems.ToArray(); seamateItems.Items = items; System.IO.File.WriteAllText(@"C:\Work\SEAMATE\" + filename + ".xml", seamateItems.Serialize()); }
public static T_SeamateItems ParseItemsConfiguration(String configPath) { TextReader tr = null; XmlTextReader xml = null; XmlValidatingReader validate = null; xml = new XmlTextReader(configPath); validate = new XmlValidatingReader(xml); validate.ValidationEventHandler += new ValidationEventHandler(xsdValidationHandler); while (validate.Read()) { } validate.Close(); try { tr = new StreamReader(configPath); XmlSerializer serializer = new XmlSerializer(typeof(T_SeamateItems)); T_SeamateItems config = (T_SeamateItems)serializer.Deserialize(tr); tr.Close(); return(config); } catch (Exception ex) { if (tr != null) { tr.Close(); } throw new Exception("Unable to read configuration file: " + configPath, ex); } return(null); }
public void Generate(Dictionary<String, int[]> dmAndItems, String filename) { /* ScriptGenerator sg = new ScriptGenerator(); int[] bamsItems = new int[] { 9, 26, 33, 23, 29, 10, 37, 65, 16, 39, 32, 4, 31, 21, 53, 30, 59, 8, 17, 38 }; int[] fireScoutItems = new int[] { 45, 19, 35, 58, 17, 46, 68, 71, 11, 37, 7, 43, 14, 57, 61, 20, 55, 12, 64, 66 }; Dictionary<String,int[]> dict = new Dictionary<String, int[]>(); dict.Add("BAMS DM", bamsItems); dict.Add("Firescout DM", fireScoutItems); sg.Generate(dict, "CalibrationScenario2"); * */ List<ScheduledItem> allScheduledItems = new List<ScheduledItem>(); foreach (String dm_id in dmAndItems.Keys) { ScheduledItem[] scheduledItems = MakeScheduledItemsForDM(dm_id, dmAndItems[dm_id]); allScheduledItems.AddRange(scheduledItems); } T_SeamateItems seamateItems = new T_SeamateItems(); seamateItems.Timeline = allScheduledItems.ToArray(); seamateItems.Items = items; System.IO.File.WriteAllText(@"C:\Work\SEAMATE\"+filename+".xml", seamateItems.Serialize()); }
public void TestMethod1() { string configPath = @"C:\Work\SVN\DDD\fresh phoenix\src\Agents\SEAMATE Item Generator\SeamateRuntimeEngine\SeamateRuntimeEngine\xsd\sample.xml"; T_SeamateItems items = null; try { items = ItemParser.ParseItemsConfiguration(configPath); } catch (Exception ex) { } foreach (T_Item item in items.Items) { Console.WriteLine("Item read!"); } }
private void LoadItems(String filePath) { T_SeamateItems items = ItemParser.ParseItemsConfiguration(filePath); foreach (T_Item i in items.Items) { if (i.Action != null) { foreach (object o in i.Action) { if (o is T_Reveal) { ((T_Reveal)o).TimeAfter *= 1000; } else if (o is T_Move) { ((T_Move)o).TimeAfter *= 1000; } else if (o is T_Interaction) { ((T_Interaction)o).TimeAfter *= 1000; } else if (o is T_ChangeState) { ((T_ChangeState)o).TimeAfter *= 1000; } } } if (!i.ID.Contains("PT-")) { _items.Add(i.ID, i); } else { _ptItems.Add(i.ID, i); } } foreach (ScheduledItem si in items.Timeline) { si.Time *= 1000; _timelineEvents.Add(si); } }
public void Generate(String outputFilename) { //minute, DM, vesselID,"stimuli,stimuli" //Example Data for 20 min seaside scenario 2 //Right now I create this with "replace" in notepad. object[][] spreadsheet = new object[][] { new object [] {1,"BAMS",2469,"Move, Reveal"}, new object [] { 1,"BAMS",7738,"Move, Reveal"}, new object [] { 1,"BAMS",2779,"Move, Reveal"}, new object [] { 1,"BAMS",1604,"Move, Reveal"}, new object [] { 1,"BAMS",2228,"Move, Reveal"}, new object [] { 1,"BAMS",6348,"Move, Reveal"}, new object [] { 1,"BAMS",2994,"Move, Reveal"}, new object [] { 1,"FireScout",7648,"Move, Reveal"}, new object [] { 1,"FireScout",1818,"Move, Reveal"}, new object [] { 1,"FireScout",4633,"Move, Reveal"}, new object [] { 1,"FireScout",5069,"Move, Reveal"}, new object [] { 1,"FireScout",3734,"Move, Reveal"}, new object [] { 1,"FireScout",2213,"Move, Reveal"}, new object [] { 1,"FireScout",4475,"Move, Reveal"}, new object [] { 1,"FireScout",4633,"Move, Reveal"}, new object [] { 2,"BAMS",8736,"Move, Reveal"}, new object [] { 2,"BAMS",1961,"Move, Reveal"}, new object [] { 2,"BAMS",5553,"Move, Reveal"}, new object [] { 2,"BAMS",5958,"Move, Reveal"}, new object [] { 2,"FireScout",8893,"Move, Reveal"}, new object [] { 3,"BAMS",2228,"Move"}, new object [] { 3,"FireScout",1848,"Move, Reveal"}, new object [] { 4,"BAMS",1135,"Reveal"}, new object [] { 4,"FireScout",3502,"Move, Reveal"}, new object [] { 5,"FireScout",7648,"Move"}, new object [] { 5,"FireScout",1818,"Move, Reveal"}, new object [] { 6,"BAMS",2377,"Move, Reveal"}, new object [] { 6,"FireScout",3593,"Move, Reveal"}, new object [] { 7,"BAMS",8948,"Move, Reveal"}, new object [] { 7,"BAMS",3106,"Move, Reveal"}, new object [] { 7,"FireScout",3593,"Move"}, new object [] { 7,"FireScout",6074,"Move, Reveal"}, new object [] { 7,"FireScout",6077,"Move, Reveal"}, new object [] { 7,"FireScout",9167,"Move, Reveal"}, new object [] { 7,"FireScout",4318,"Move, Reveal"}, new object [] { 7,"FireScout",7679,"Move, Reveal"}, new object [] { 8,"FireScout",7232,"Move, Reveal"}, new object [] { 9,"BAMS",7112,"Move, Reveal"}, new object [] { 10,"FireScout",3170,"Move, Reveal"}, new object [] { 11,"BAMS",4940,"Move, Reveal"}, new object [] { 11,"BAMS",5304,"Move, Reveal"}, new object [] { 11,"BAMS",5965,"Move, Reveal"}, new object [] { 11,"BAMS",8560,"Move, Reveal"}, new object [] { 11,"FireScout",1606,"Move, Reveal"}, new object [] { 11,"FireScout",7151,"Move, Reveal"}, new object [] { 13,"BAMS",1212,"Move, Reveal"}, new object [] { 13,"BAMS",9809,"Move, Reveal"}, new object [] { 13,"BAMS",4685,"Move, Reveal"}, new object [] { 13,"BAMS",1608,"Move, Reveal"}, new object [] { 13,"BAMS",3537,"Move, Reveal"}, new object [] { 13,"FireScout",4322,"Move, Reveal"}, new object [] { 13,"FireScout",4257,"Move, Reveal"}, new object [] { 13,"FireScout",3170,"Move, Reveal"}, new object [] { 14,"BAMS",1621,"Move, Reveal"}, new object [] { 14,"FireScout",7626,"Move, Reveal"}, new object [] { 15,"FireScout",6081,"Move, Reveal"}, new object [] { 15,"BAMS",3957,"Move, Reveal"}, new object [] { 15,"BAMS",9081,"Move, Reveal"}, new object [] { 15,"BAMS",1966,"Move, Reveal"}, new object [] { 15,"FireScout",8940,"Move, Reveal"}, new object [] { 15,"FireScout",6015,"Move, Reveal"}, new object [] { 18,"BAMS",9081,"Move"}, new object [] { 18,"BAMS",1604,"Move, Reveal"}, new object [] { 18,"BAMS",4306,"Move, Reveal"}, new object [] { 18,"FireScout",2471,"Move, Reveal"}, new object [] { 18,"FireScout",4758,"Move, Reveal"}, new object [] { 18,"FireScout",4257,"Move"}, new object [] { 19,"BAMS",2285,"Move, Reveal"}, new object [] { 19,"BAMS",9228,"Move, Reveal"}, new object [] { 19,"BAMS",6290,"Move, Reveal"}}; List<ScheduledItem> allScheduledItems = new List<ScheduledItem>(); List<T_Item>allItems = new List<T_Item>(); foreach (object[] line in spreadsheet) { if (line.Length < 4) continue; //allows you to paste in and ignore empty lines (with no stimuli) int minute = (int)line[0]; int time = minute *60; String dm_id = MakeDMID((String)line[1]); int obj_id = (int)line[2]; String actions = (String)line[3]; if (actions == null) continue; ScheduledItem scheduledItem = null; T_Item item = null; //see if we've already made an "ScheduledItem" that this action belongs to foreach (ScheduledItem maybeScheduledItem in allScheduledItems) { if (maybeScheduledItem.DM_ID == dm_id && maybeScheduledItem.Time == time) { scheduledItem = maybeScheduledItem; //find corresponding abstract "Item" foreach (T_Item maybeItem in allItems) { if (maybeItem.ID == scheduledItem.ID) { item = maybeItem; } } break; } } if (scheduledItem == null) //make new "scheduledItem" and "item" (uid) { //Dummy item that contains a UID and empty actions list item = new T_Item(); uid = uid+1; item.ID = uid.ToString(); item.Action = new object[0]; item.Parameters = new Parameters(); item.Parameters.ThreatType = T_ThreatType.Nonimminent; item.Parameters.Threat = T_Threat.Unambiguous; item.Parameters.Crossing = false; item.Parameters.Groupings = T_Groupings.One; item.Parameters.PlayerResources = T_ResourceAvailability.Available; item.Parameters.TeammateResources = T_ResourceAvailability.Available; item.Parameters.FF_Difficulty =1.0; item.Parameters.TT_Difficulty = 1.0; allItems.Add(item); scheduledItem = new ScheduledItem(); scheduledItem.Time = time; scheduledItem.DM_ID = dm_id; scheduledItem.ID = uid.ToString(); allScheduledItems.Add(scheduledItem); } //OK. We've verified that the scheduled item exists and we have the pointer to the item. //Add actions to item.Action: List<T_ScriptedItem> listToAddToAction = new List<T_ScriptedItem>(); if (actions.Contains("Reveal")) { T_ScriptedItem reveal = new T_ScriptedItem(); reveal.ID = obj_id.ToString(); reveal.ActionType = "Reveal"; listToAddToAction.Add(reveal); } if (actions.Contains("Move")) { T_ScriptedItem move = new T_ScriptedItem(); move.ID = obj_id.ToString(); move.ActionType = "Move"; listToAddToAction.Add(move); } List<object> copyOfActions = item.Action.ToList(); copyOfActions.AddRange(listToAddToAction); item.Action = copyOfActions.ToArray(); } T_SeamateItems seamateItems = new T_SeamateItems(); seamateItems.Timeline = allScheduledItems.ToArray(); seamateItems.Items = allItems.ToArray(); System.IO.File.WriteAllText(@"C:\Work\SEAMATE\"+outputFilename+".xml", seamateItems.Serialize()); }
public void Generate(String filename) { /* * * StimulusScriptGenerator ssg = new StimulusScriptGenerator(); * ssg.Generate("SeasideStimulusScript1"); * */ object[][] spreadsheet = new object[][] { new object[] { 1, "BAMS", 2469, "Reveal,Move" }, new object[] { 1, "BAMS", 8893, "Reveal,Move" }, new object[] { 1, "BAMS", 7738, "Reveal,Move" }, new object[] { 1, "BAMS", 5553, "Reveal,Move" }, new object[] { 1, "BAMS", 5962, "Reveal,Move" }, new object[] { 1, "BAMS", 2377, "Reveal,Move" }, new object[] { 1, "BAMS", 6348, "Reveal,Move" }, new object[] { 1, "BAMS", 1604, "Reveal,Move" }, new object[] { 1, "FireScout", 9228, "Reveal,Move" }, new object[] { 1, "FireScout", 2588, "Reveal,Move" }, new object[] { 1, "FireScout", 5951, "Reveal,Move" }, new object[] { 1, "FireScout", 7679, "Reveal,Move" }, new object[] { 1, "FireScout", 7151, "Reveal,Move" }, new object[] { 1, "FireScout", 1606, "Reveal,Move" }, new object[] { 1, "FireScout", 4633, "Reveal,Move" }, new object[] { 1, "FireScout", 5069, "Reveal,Move" }, new object[] { 2, "BAMS", 2643, "Reveal,Move" }, new object[] { 2, "FireScout", 5069, }, new object[] { 2, "FireScout", 3734, "Reveal,Move" }, new object[] { 3, "BAMS", 4257, "Reveal,Move" }, new object[] { 3, "BAMS", 1608, "Reveal,Move" }, new object[] { 3, "BAMS", 1608, }, new object[] { 3, "FireScout", 1608, }, new object[] { 3, "FireScout", 7679, }, new object[] { 3, "FireScout", 3734, "Move" }, new object[] { 4, "BAMS", 4257, }, new object[] { 4, "BAMS", 8736, "Reveal,Move" }, new object[] { 4, "BAMS", 1961, "Reveal,Move" }, new object[] { 4, "BAMS", 4257, }, new object[] { 4, "BAMS", 8736, }, new object[] { 4, "BAMS", 1961, }, new object[] { 4, "BAMS", 4306, "Reveal,Move" }, new object[] { 4, "FireScout", 7151, "Move" }, new object[] { 4, "FireScout", 3734, "Move" }, new object[] { 5, "BAMS", 2285, "Reveal,Move" }, new object[] { 5, "BAMS", 2643, }, new object[] { 5, "BAMS", 7738, }, new object[] { 5, "FireScout", 9228, }, new object[] { 5, "FireScout", 3734, }, new object[] { 5, "FireScout", 1608, }, new object[] { 6, "BAMS", 2377, }, new object[] { 6, "BAMS", 1604, "Move" }, new object[] { 6, "BAMS", 4257, "Move" }, new object[] { 6, "BAMS", 8736, "Move" }, new object[] { 6, "BAMS", 1961, "Move" }, new object[] { 6, "BAMS", 6348, }, new object[] { 6, "FireScout", 9809, "Reveal,Move" }, new object[] { 6, "FireScout", 9809, }, new object[] { 6, "FireScout", 7648, "Reveal,Move" }, new object[] { 6, "FireScout", 1818, "Reveal,Move" }, new object[] { 6, "FireScout", 3502, "Reveal,Move" }, new object[] { 7, "BAMS", 6348, "Move" }, new object[] { 7, "BAMS", 8062, "Reveal,Move" }, new object[] { 7, "FireScout", 5069, }, new object[] { 7, "FireScout", 9809, }, new object[] { 7, "FireScout", 7648, }, new object[] { 7, "FireScout", 1818, }, new object[] { 7, "FireScout", 3502, }, new object[] { 7, "FireScout", 7151, }, new object[] { 8, "BAMS", 2469, "Move" }, new object[] { 8, "BAMS", 8893, "Move" }, new object[] { 8, "BAMS", 2643, "Move" }, new object[] { 8, "BAMS", 4306, }, new object[] { 8, "BAMS", 8062, }, new object[] { 8, "FireScout", 4306, }, new object[] { 8, "FireScout", 8062, }, new object[] { 8, "BAMS", 8536, "Reveal,Move" }, new object[] { 8, "FireScout", 4940, "Reveal,Move" }, new object[] { 9, "BAMS", 7738, "Move" }, new object[] { 9, "BAMS", 1604, "Move" }, new object[] { 9, "BAMS", 4475, "Reveal,Move" }, new object[] { 9, "BAMS", 1135, "Reveal,Move" }, new object[] { 9, "BAMS", 2213, "Reveal,Move" }, new object[] { 9, "FireScout", 3734, "Move" }, new object[] { 9, "FireScout", 4306, }, new object[] { 9, "FireScout", 8062, }, new object[] { 9, "FireScout", 3593, "Reveal,Move" }, new object[] { 9, "FireScout", 6290, "Reveal,Move" }, new object[] { 10, "BAMS", 1135, }, new object[] { 10, "BAMS", 2469, }, new object[] { 10, "BAMS", 8893, }, new object[] { 10, "FireScout", 2469, }, new object[] { 10, "FireScout", 8893, }, new object[] { 10, "FireScout", 3734, }, new object[] { 10, "FireScout", 7648, "Move" }, new object[] { 10, "FireScout", 1818, "Move" }, new object[] { 10, "FireScout", 3502, "Move" }, new object[] { 11, "BAMS", 1604, }, new object[] { 11, "BAMS", 2643, }, new object[] { 11, "BAMS", 7232, "Reveal,Move" }, new object[] { 11, "BAMS", 7232, }, new object[] { 11, "BAMS", 8940, "Reveal,Move" }, new object[] { 11, "BAMS", 8560, "Reveal,Move" }, new object[] { 11, "FireScout", 1604, }, new object[] { 11, "FireScout", 2643, }, new object[] { 11, "FireScout", 8062, }, new object[] { 12, "BAMS", 6348, "Move" }, new object[] { 12, "BAMS", 7494, "Reveal,Move" }, new object[] { 12, "BAMS", 2468, "Reveal,Move" }, new object[] { 12, "BAMS", 7112, "Reveal,Move" }, new object[] { 12, "FireScout", 8948, "Reveal,Move" }, new object[] { 12, "FireScout", 1510, "Reveal,Move" }, new object[] { 12, "FireScout", 6077, "Reveal,Move" }, new object[] { 13, "BAMS", 1135, "Move" }, new object[] { 13, "BAMS", 7112, "Move" }, new object[] { 13, "FireScout", 1606, }, new object[] { 13, "FireScout", 4306, "Move" }, new object[] { 13, "FireScout", 9809, "Move" }, new object[] { 14, "BAMS", 2643, }, new object[] { 14, "BAMS", 8893, }, new object[] { 14, "BAMS", 7232, "Move" }, new object[] { 14, "BAMS", 2228, "Reveal,Move" }, new object[] { 14, "BAMS", 2471, "Reveal,Move" }, new object[] { 14, "FireScout", 4306, }, new object[] { 14, "FireScout", 1604, "Move" }, new object[] { 14, "FireScout", 6081, "Reveal,Move" }, new object[] { 14, "FireScout", 6074, "Reveal,Move" }, new object[] { 15, "BAMS", 7112, }, new object[] { 15, "FireScout", 3593, }, new object[] { 15, "FireScout", 4322, "Reveal,Move" }, new object[] { 16, "BAMS", 2213, }, new object[] { 16, "FireScout", 2213, }, new object[] { 16, "FireScout", 9809, "Move" }, new object[] { 16, "FireScout", 6077, "Move" }, new object[] { 17, "BAMS", 4685, "Reveal,Move" }, new object[] { 17, "FireScout", 6077, }, new object[] { 17, "FireScout", 3170, "Reveal,Move" }, new object[] { 17, "FireScout", 2643, }, new object[] { 17, "FireScout", 9809, "Move" }, new object[] { 18, "BAMS", 5304, "Reveal,Move" }, new object[] { 18, "BAMS", 2625, "Reveal,Move" }, new object[] { 18, "BAMS", 8940, "Move" }, new object[] { 18, "FireScout", 4306, "Move" }, new object[] { 18, "FireScout", 1848, "Reveal,Move" }, new object[] { 18, "FireScout", 3170, "Move" }, new object[] { 19, "BAMS", 6348, "Move" }, new object[] { 19, "BAMS", 5304, }, new object[] { 19, "BAMS", 2625, }, new object[] { 19, "BAMS", 8940, }, new object[] { 19, "BAMS", 2471, }, new object[] { 19, "BAMS", 2779, "Reveal,Move" }, new object[] { 19, "BAMS", 9167, "Reveal,Move" }, new object[] { 19, "BAMS", 6015, "Reveal,Move" }, new object[] { 19, "FireScout", 2471, }, new object[] { 19, "FireScout", 6074, "Move" }, new object[] { 19, "FireScout", 8948, "Move" }, new object[] { 19, "FireScout", 4322, }, new object[] { 19, "FireScout", 1848, "Move" }, new object[] { 19, "FireScout", 1212, "Reveal,Move" }, new object[] { 19, "FireScout", 4318, "Reveal,Move" }, new object[] { 20, "BAMS", 9167, }, new object[] { 20, "BAMS", 1212, }, new object[] { 20, "BAMS", 4318, }, new object[] { 20, "FireScout", 6015, }, new object[] { 20, "FireScout", 8948, } }; List <ScheduledItem> allScheduledItems = new List <ScheduledItem>(); List <T_Item> allItems = new List <T_Item>(); foreach (object[] line in spreadsheet) { if (line.Length < 4) { continue; } int minute = (int)line[0]; int time = minute * 60; String dm_id = (String)line[1]; int obj_id = (int)line[2]; String actions = (String)line[3]; if (actions == null) { continue; } ScheduledItem scheduledItem = null; T_Item item = null; //see if we've already made an "ScheduledItem" that this action belongs to foreach (ScheduledItem maybeScheduledItem in allScheduledItems) { if (maybeScheduledItem.DM_ID == dm_id && maybeScheduledItem.Time == time) { scheduledItem = maybeScheduledItem; //find corresponding abstract "Item" foreach (T_Item maybeItem in allItems) { if (maybeItem.ID == scheduledItem.ID) { item = maybeItem; } } break; } } if (scheduledItem == null) //make new "scheduledItem" and "item" (uid) { //Dummy item that contains a UID and empty actions list item = new T_Item(); uid = uid + 1; item.ID = uid.ToString(); item.Action = new object[0]; item.Parameters = new Parameters(); item.Parameters.ThreatType = T_ThreatType.Nonimminent; item.Parameters.Threat = T_Threat.Unambiguous; item.Parameters.Crossing = false; item.Parameters.Groupings = T_Groupings.One; item.Parameters.PlayerResources = T_ResourceAvailability.Available; item.Parameters.TeammateResources = T_ResourceAvailability.Available; item.Parameters.Difficulty = 1.0; allItems.Add(item); scheduledItem = new ScheduledItem(); scheduledItem.Time = time; scheduledItem.DM_ID = dm_id; scheduledItem.ID = uid.ToString(); allScheduledItems.Add(scheduledItem); } //OK. We've verified that the scheduled item exists and we have the pointer to the item. //Add actions to item.Action: List <T_ScriptedItem> listToAddToAction = new List <T_ScriptedItem>(); if (actions.Contains("Reveal")) { T_ScriptedItem reveal = new T_ScriptedItem(); reveal.ID = obj_id.ToString(); reveal.ActionType = "Reveal"; listToAddToAction.Add(reveal); } if (actions.Contains("Move")) { T_ScriptedItem move = new T_ScriptedItem(); move.ID = obj_id.ToString(); move.ActionType = "Move"; listToAddToAction.Add(move); } List <object> copyOfActions = item.Action.ToList(); copyOfActions.AddRange(listToAddToAction); item.Action = copyOfActions.ToArray(); } T_SeamateItems seamateItems = new T_SeamateItems(); seamateItems.Timeline = allScheduledItems.ToArray(); seamateItems.Items = allItems.ToArray(); System.IO.File.WriteAllText(@"C:\Work\SEAMATE\" + filename + ".xml", seamateItems.Serialize()); }