public void TestDfsAi() { IMapGenerator simpleMapGenerator = new OpenMapGenerator(); int w = 5; int h = 1; Map map = simpleMapGenerator.GenerateMap(w, h, IMapGeneratorConstants.NO_SEED); AbstractPlayer simpleAIPlayer = new SimpleAIPlayer("Test simple AI player", map.Grid[0, 0]) { IgnoreSpeed = true }; map.AddCreature(simpleAIPlayer); // player should get to the block [4,0] in 4 turns for (int i = 0; i < w - 1; i++) { simpleAIPlayer.Think(); // check taht correct action was produced AbstractAction nextAction = simpleAIPlayer.NextAction; Assert.IsNotNull(nextAction, $"Next action is nul in {i} iteration!"); Assert.AreEqual(typeof(Move), nextAction.GetType(), $"Wrong type of action in {i} iteration!"); Assert.AreEqual(Direction.EAST, ((Move)nextAction).Direction, $"Wrong direction in {i} iteration!"); // execute the action and check the position is correct nextAction.Execute(); Assert.AreEqual(0, simpleAIPlayer.Position.Y, $"Wrong Y coordinate in {i} direction!"); Assert.AreEqual(i + 1, simpleAIPlayer.Position.X, $"Wrong X coordinate in {i} direction!"); } }
private void Update() { if (actionsQueue.Count == 0) { AbstractAction action = PickAction(); actionsQueue.Add(action); } currentAction.Execute(); currentAction.Update(); if (currentAction.IsDone()) { currentAction = actionsQueue[0]; actionsQueue.RemoveAt(0); } if (eggTimer >= Random.Range(minEggFrequency, maxEggFrequency)) { EggBehaviour newEgg = Instantiate(egg, new Vector3(transform.position.x, transform.position.y, transform.position.z - transform.forward.z * -1), Quaternion.identity); newEgg.transform.GetChild(0).GetComponent <MeshRenderer>().material.color = transform.GetChild(0).GetComponent <MeshRenderer>().material.color; eggTimer = 0; } eggTimer += Time.deltaTime; }
void Update() { if (currentAction != null && currentAction.IsDone() && actionQ.Any()) { currentAction = actionQ.Dequeue(); currentAction.Execute(); } }
void Start() { ds = GetComponent <DataSource>(); getPokemonData(); new SetEnemyData().Execute(); new SetPlayerData().Execute(); actionQ.Enqueue(new HideButtonsFrameAction()); actionQ.Enqueue(new DisplayTextAction("Welcome to the pokemon battle simulator")); actionQ.Enqueue(new ShowButtonsFrameAction()); currentAction = actionQ.Dequeue(); currentAction.Execute(); }
public List <UMLFile> CreateFiles(IDictionary relationships) { List <PreFile> prefiles = new List <PreFile>(); List <PreRET> retsToDelete; List <UMLFile> files = new List <UMLFile>(); IDictionary <String, String> tnamemap; IDictionary <String, UMLClass> tclasses; UMLFile tfile; String tname; int tdets; UMLAttribute tattrib; //0. Pre-Pre-Processing (set dependencies in relationships) foreach (DictionaryEntry entry in relationships) { UMLRelationship r = (UMLRelationship)entry.Value; if (r is UMLDependency) { foreach (DictionaryEntry entry2 in relationships) { UMLRelationship q = (UMLRelationship)entry2.Value; if (q is UMLAssociation) { if ((((UMLDependency)r).Client.Guid.Equals(((UMLAssociation)q).End1.Participant.Guid)) && (((UMLDependency)r).Supplier.Guid.Equals(((UMLAssociation)q).End2.Participant.Guid)) || (((UMLDependency)r).Client.Guid.Equals(((UMLAssociation)q).End2.Participant.Guid)) && (((UMLDependency)r).Supplier.Guid.Equals(((UMLAssociation)q).End1.Participant.Guid))) { ((UMLAssociation)q).DependencyType = "D"; } } } } } //1. PreFile Generation (Pre-Processing) foreach (DictionaryEntry entry in relationships) { UMLRelationship r = (UMLRelationship)entry.Value; if (!(r is UMLDependency)) { ActionKey key = new ActionKey(r); AbstractAction action = map.GetAction(key); if (action != null) { action.Execute(r, map, prefiles); } else { throw new ArgumentException("There is no defined action for the actionKey given."); } } } //2. File Generation (Processing) if (prefiles.Count == 0) { return(null); } else { //2.1 Clean-up (eliminate parents in PreFiles - Generalization cases) foreach (PreFile prefile in prefiles) { retsToDelete = new List <PreRET>(); foreach (PreRET preret in prefile.Rets) { foreach (PreRET parent in preret.Parents) { //2.1.1 Merge preret.Merge(parent); //mark parent ret for deletion if (!retsToDelete.Contains(parent)) { retsToDelete.Add(parent); } } } //2.1.2 Deletion (optimized since rets are only in one file) foreach (PreRET retToDelete in retsToDelete) { prefile.Rets.Remove(retToDelete); } //2.1.3 File generation tfile = new UMLFile(); //Rets tfile.Rets = prefile.Rets.Count; //Dets & Name tdets = 0; tname = ""; tnamemap = new Dictionary <String, String>(); tclasses = new Dictionary <String, UMLClass>(); foreach (PreRET ret in prefile.Rets) { UMLFile.RET tret = new UMLFile.RET(); foreach (UMLClass c in ret.Classes) { tnamemap[c.Name] = c.Name; tret.Classes.Add(c); if (!(tclasses.ContainsKey(c.Name))) { tclasses[c.Name] = c; c.LoadAttributes(); tdets += c.Attributes.Count; foreach (UMLAttribute attrib in c.Attributes) { tattrib = new UMLAttribute(); tattrib.Name = c.Name + "." + attrib.Name; tfile.Attributes.Add(tattrib); } } } tfile.RetsCollection.Add(tret); } foreach (KeyValuePair <String, String> kvp in tnamemap) { tname += kvp.Value + "_"; } tfile.Dets = tdets; tfile.Dets += prefile.DefaultDets; tname = tname.Remove(tname.Length - 1, 1); //limit File name size to 50 chars (could cause name collisions) tfile.Name = tname.Length > 50 ? tname.Substring(1, 50) : tname; files.Add(tfile); } return(files); } }