public static void SaveAI(AIContainer data) { using (Stream stream = File.Open(Application.dataPath + "/AI.bin", FileMode.OpenOrCreate)) { BinaryFormatter bin = new BinaryFormatter(); bin.Serialize(stream, data); Debug.Log("Wrote a file to: " + Application.dataPath + "/AI.bin"); } }
private void LoadAI(string AIPath) { string Name = AIPath.Substring(0, AIPath.Length - 5).Substring(12); this.Text = Name + " - Project Eternity AI Editor"; ActiveAI = new AIContainer(); aiViewer.AIPath = Name; }
// todo: ally class is probably not necessary public Ally(int actorNumber, ActorClass actorClass, string uniqueId, Area spawnedArea, float posX, float posY, float posZ, float rot, ushort actorState, uint animationId, string customDisplayName) : base(actorNumber, actorClass, uniqueId, spawnedArea, posX, posY, posZ, rot, actorState, animationId, customDisplayName) { aiContainer = new AIContainer(this, new AllyController(this), new PathFind(this), new TargetFind(this)); this.allegiance = CharacterTargetingAllegiance.Player; this.isAutoAttackEnabled = true; this.isMovingToSpawn = false; }
public static AIContainer LoadAI() { AIContainer r = new AIContainer(); using (Stream stream = File.Open(Application.dataPath + "/AI.bin", FileMode.OpenOrCreate)) { BinaryFormatter bin = new BinaryFormatter(); r = (AIContainer)bin.Deserialize(stream); } return(r); }
public void LoadGraph(string fileName) { _containerCache = Resources.Load <AIContainer>(fileName); if (_containerCache == null) { EditorUtility.DisplayDialog("File Not Found", "Target AI graph does not exist!", "Ok"); return; } ClearGraph(); CreateNodes(); ConnectNodes(); }
//TODO Need a similiar structure for the Association rules indexed by actor(type) preferably. //TrainingExample[] examples, Feature[] features, DecisionNode decisionNode public static void CreateTree(DecisionTree.TrainingExample[] examples) { try { DecisionTrees.Add(examples[0].Actor.name, new DecisionTree.DecisionTree(examples, examples[0].Features)); AIContainer d = new AIContainer(); d.Key = examples[0].Actor.name; d.DTree = DecisionTrees[examples[0].Actor.name]; XMLManager.SaveAI(d); } catch (ArgumentException) { DecisionTree.DecisionTree d = new DecisionTree.DecisionTree(examples, examples[0].Features); Debug.Log("There already exists a Decision Tree for this actor!, Overwriting previous tree."); DecisionTrees[examples[0].Actor.name] = d; AIContainer con = new AIContainer(); con.Key = examples[0].Actor.name; con.DTree = DecisionTrees[examples[0].Actor.name]; XMLManager.SaveAI(con); } }
public static State GetDecision(GameObject actor, State currentState) { AssRulesResult CARresult = null; bool CARhasResult = false; if (CARResults != null && CARResults.Count > 0) { CARhasResult = true; foreach (AssRulesResult r in CARResults) { if (Convert.ToInt32(actor.name) == r.input[0]) { if (r.input[1] == Convert.ToInt32(currentState.StateName)) { CARresult = r; } } } } if (DecisionTrees.Count <= 0) { AIContainer result = XMLManager.LoadAI(); DecisionTrees.Add(result.Key, result.DTree); } Dictionary <string, float> dtreeresult = DecisionTrees[actor.name].Query(); string highestState = "default"; float highestProbability = -1; if (dtreeresult != null) { foreach (KeyValuePair <string, float> r in dtreeresult) { if (r.Value > highestProbability) { highestProbability = r.Value; highestState = r.Key; } } } if (CARhasResult) { if (CARresult.confidence > highestProbability && CARresult.support >= 1) { //foreach(State s in State.States) for (int i = 0; i < FiniteStateMachine.States.Count; ++i) { if (i == CARresult.output[0]) { return(FiniteStateMachine.States[i]); } } } } else { return(TurnManager.CurrentTurnManInstance.UnitFSM.FSM.GetState(highestState)); } return(TurnManager.CurrentTurnManInstance.UnitFSM.FSM.GetState(highestState)); //TODO Implement the retrievable of ASSRULES //TODO Compare confidence of ass rules to probablity of DecisionTree. }
public void SaveObjects() { aiContainer = new AIContainer(); aiContainer.ai = NPCs; aiContainer.Save("Assets/Resources/ai.xml"); }
private void ProcessKeyboard() { prevKeyboardState = currentKeyboardState; currentKeyboardState = Keyboard.GetState(); prevMouseState = currentMouseState; currentMouseState = Mouse.GetState(); if (KeyJustPressed(Keys.Escape)) { this.Exit(); } if (currentKeyboardState.IsKeyDown(Keys.LeftAlt)) { camera.Velocity *= 10.0f; } if (currentKeyboardState.IsKeyUp(Keys.LeftAlt)) { camera.Velocity = new Vector3(Settings.CAMERA_VELOCITY); } if (currentKeyboardState.IsKeyDown(Keys.LeftAlt) || currentKeyboardState.IsKeyDown(Keys.RightAlt)) { if (KeyJustPressed(Keys.Enter)) { ToggleFullScreen(); } } if (KeyJustPressed(Keys.D1)) { camera.CurrentBehavior = Camera.Behavior.FirstPerson; camera.Velocity = new Vector3(Settings.CAMERA_VELOCITY); camera.Acceleration = new Vector3(Settings.CAMERA_ACCELERATION); } if (KeyJustPressed(Keys.D2)) { camera.CurrentBehavior = Camera.Behavior.Spectator; camera.Velocity = new Vector3(Settings.CAMERA_VELOCITY) * 1.5f; camera.Acceleration = new Vector3(Settings.CAMERA_ACCELERATION) * 2.0f; } if (KeyJustPressed(Keys.D3)) { camera.CurrentBehavior = Camera.Behavior.FreeView; camera.Velocity = new Vector3(Settings.CAMERA_VELOCITY) * 1.5f; camera.Acceleration = new Vector3(Settings.CAMERA_ACCELERATION) * 2.0f; } //if (KeyJustPressed(Keys.D4)) //{ // camera.CurrentBehavior = Camera.Behavior.Orbit; // camera.Velocity = new Vector3(Settings.CAMERA_VELOCITY) * 1.5f; // camera.Acceleration = new Vector3(Settings.CAMERA_ACCELERATION) * 2.0f; //} if (KeyJustPressed(Keys.D4)) { camera.CurrentBehavior = Camera.Behavior.Flight; camera.Velocity = new Vector3(Settings.CAMERA_VELOCITY) * 0.3f; camera.Acceleration = new Vector3(Settings.CAMERA_ACCELERATION) * 0.5f; } // SETTINGS WITH CONTROL if (currentKeyboardState.IsKeyDown(Keys.LeftControl)) { if (KeyJustPressed(Keys.Z)) { AI.AIParams.CONFIG_ENABLE_DEFAULT_LIGHTING = !AI.AIParams.CONFIG_ENABLE_DEFAULT_LIGHTING; } if (KeyJustPressed(Keys.Space)) { terrain.ToggleDrawingTechnique(); } if (KeyJustPressed(Keys.C)) { cursor.IsActivated = !cursor.IsActivated; AIGame.terrain.ShowGroundCursor = !AIGame.terrain.ShowGroundCursor; } if (KeyJustPressed(Keys.F)) { Settings.FOG_ENABLED = !Settings.FOG_ENABLED; } if (KeyJustPressed(Keys.P)) { camera.PerspectiveInitial(); } if (KeyJustPressed(Keys.B)) { Settings.DRAW_BOUNDING_BOXES = !Settings.DRAW_BOUNDING_BOXES; } if (KeyJustPressed(Keys.R)) { Settings.DRAW_RANGE_CIRCLES = !Settings.DRAW_RANGE_CIRCLES; } if (KeyJustPressed(Keys.A)) { Settings.ACCELERATED_MODE = !Settings.ACCELERATED_MODE; } if (KeyJustPressed(Keys.PageDown)) { Settings.GAME_SPEED -= 0.1f; if (Settings.GAME_SPEED < 0.2f) { Settings.GAME_SPEED = 0.2f; } } if (KeyJustPressed(Keys.PageUp)) { Settings.GAME_SPEED += 0.1f; } if (KeyJustPressed(Keys.Home)) { Settings.GAME_SPEED = 1f; } if (KeyJustPressed(Keys.L)) { Settings.DRAW_STATICS_LABELS = !Settings.DRAW_STATICS_LABELS; } if (KeyJustPressed(Keys.H)) { Settings.DRAW_GRAPH = !Settings.DRAW_GRAPH; } if (currentKeyboardState.IsKeyDown(Keys.LeftShift) && KeyJustPressed(Keys.L)) { Settings.DRAW_OBJECTS_LABELS = !Settings.DRAW_OBJECTS_LABELS; } if (KeyJustPressed(Keys.G)) { AIParams.CONFIG_DUMP_ANN_VECTORS = !AIParams.CONFIG_DUMP_ANN_VECTORS; } } // SETTINGS WITHOUT CONTROL else { // Clear selection if (KeyJustPressed(Keys.U)) { _aicontainer.ClearSelect(); } // FOLLOW FITTEST OBJECT if (KeyJustPressed(Keys.F) && _aicontainer.GenethicAlgorithm.FittestObject != null) { if (camera.ObjectToFollow != null) { camera.ObjectToFollow = null; } else { camera.ObjectToFollow = _aicontainer.GenethicAlgorithm.FittestObject; camera.Position = camera.ObjectToFollow.Position + Vector3.UnitY * 1000; camera.LookAt(camera.ObjectToFollow.Position); AIContainer.Select(camera.ObjectToFollow); } } // process teams and objects movements if (camera.CurrentBehavior == Camera.Behavior.FreeView && _aicontainer.IsOneOfAIObjectSelected) { // toggle objects status: walk, run, crawl, cover if (KeyJustPressed(Keys.Z)) { _aicontainer.SelectedObject.ToggleMoveStatus(); } // toggle formation if (KeyJustPressed(Keys.F)) { _aicontainer.SelectedTeam.ToggleFormation(); } // toggle oaau if (KeyJustPressed(Keys.O)) { _aicontainer.SelectedTeam.OperateAsAUnit = !_aicontainer.SelectedTeam.OperateAsAUnit; } // toggle kf if (KeyJustPressed(Keys.K)) { _aicontainer.SelectedTeam.KeepFormation = !_aicontainer.SelectedTeam.KeepFormation; } // go to cover if (KeyJustPressed(Keys.C)) { _aicontainer.SelectedObject.TakeCover(); } // pick up static if (KeyJustPressed(Keys.B)) { _aicontainer.SelectedObject.PickUpBonus(); } // pick up static if (KeyJustPressed(Keys.M)) { _aicontainer.SelectedObject.PickUpMedKit(); } } } }