public World(string name, WorldAction worldAction, string stuffTemplate = "ToTDefault_01") { BlocksBase = new List <Block>(); BlocksNorth = new List <Block>(); BlocksSouth = new List <Block>(); BlocksWest = new List <Block>(); BlocksEast = new List <Block>(); FileManager fm = new FileManager(); StuffTemplate = fm.LoadTemplate(TEMPLATESPATH + stuffTemplate + ".tott"); if (worldAction == WorldAction.GenerateNew) { Name = name; BlocksBase.Add(new Block() { Position = new Vector2(0, 0), Dimensions = new Vector2(1440, 900), Level = 0, TemplateName = "MainBase", Coords = "B:0" }); AddTiles(BlocksNorth, 5, Orientation.North, StuffTemplate); AddTiles(BlocksSouth, 5, Orientation.South, StuffTemplate); AddTiles(BlocksWest, 5, Orientation.West, StuffTemplate); AddTiles(BlocksEast, 5, Orientation.East, StuffTemplate); } }
public PerformingActionAtTimeQuery(QuestionType questionType, WorldAction worldAction = null, int time = -1) : base(QueryType.PerformingActionAtTime, questionType) { this._worldAction = worldAction; this._time = time; _logger.Info("Creates:\n " + this); }
public ImpossibleActionIfRecord(WorldAction worldAction, string ifExpression) : base(WorldDescriptionRecordType.ImpossibleActionIf) { this.logicExpression = ServiceLocator.Current.GetInstance <ILogicExpression>(); this.ifExpression = ifExpression; this.worldAction = worldAction; }
public void SetUp() { _idWorldAction = "idWorldAction"; _startTime = 8; _durationTime = 5; _worldAction = new WorldAction(_idWorldAction, _startTime, _durationTime); _fluent = new Fluent() { Name = "a", Value = true }; _state = new State { Fluents = new List <Fluent> { new Fluent { Name = "a", Value = true }, new Fluent { Name = "b", Value = true }, new Fluent { Name = "c", Value = true }, new Fluent { Name = "d", Value = true } } }; }
void OnStartAddRemove() { if (AddRemoveActive) { AddRemoveTimer.Stop(); AddRemoveActive = false; RaisePropertyChanged(nameof(AddButtonText)); return; } AddRemoveActive = true; AddRemoveTimer.Interval = TimeSpan.FromMilliseconds(RefreshInterval); RaisePropertyChanged(nameof(AddButtonText)); AddRemoveTimer.Tick += (s, e) => { WorldAction action = (WorldAction)Randomizer.Next(3); switch (action) { case WorldAction.Add: People.Add(new Person() { Name = Names[Randomizer.Next(Names.Count)], Id = Names.Count, Worth = RandomCash() }); break; case WorldAction.Remove: People.RemoveAt(Randomizer.Next(People.Count)); break; } Application.Current.Dispatcher.Invoke(() => RaisePropertyChanged(nameof(People))); }; AddRemoveTimer.Start(); }
private void ButtonAddAction_Click(object sender, RoutedEventArgs e) { if (TextBoxActionName.Text == "") { LabelFluentsActionsValidation.Content = "Action name is required."; return; } if (!System.Text.RegularExpressions.Regex.IsMatch(TextBoxActionName.Text, @"[a-zA-Z]+[a-zA-Z0-9\-]*$")) { LabelFluentsActionsValidation.Content = "Action name should be alphanumeric."; return; } if (!UpDownTime.Value.HasValue) { LabelFluentsActionsValidation.Content = "Please specify the duration."; return; } int duration = UpDownTime.Value.Value; if (!Actions.Contains(Actions.FirstOrDefault(f => (f.Id == TextBoxActionName.Text && f.Duration == duration)))) { var action = new WorldAction { Id = TextBoxActionName.Text, Duration = duration }; Actions.Add(action); TextBoxActionName.Text = ""; UpDownTime.Value = null; LabelFluentsActionsValidation.Content = ""; } else { LabelFluentsActionsValidation.Content = "Such action already exists."; } }
// Check if an action is applicable. Actions that don't concern the player // are by default applicable. public bool CheckActionApplicable(WorldAction action) { // Note this code is redundant but cost is negligible? if (action == jumpAction) { return(noFall || wallStick > 0); } else if (action == fireAction) { return((Ammo > 0 || IsMaster) && fireWait == 0 && weapon != WeaponType.None); } else if (action == rightAction) { return((!world.CheckGround(X + (-18.0f) - Speed, Y - 25.0f) && !world.CheckGround(X + (-18.0f) - Speed, Y + 24.0f)) || vSpeed > 0); // TODO Double-check this } else if (action == leftAction) { return((!world.CheckGround(X + (18.0f) + Speed, Y - 25.0f) && !world.CheckGround(X + (18.0f) + Speed, Y + 24.0f)) || vSpeed > 0); } return(true); }
public bool ValidateActions() { bool result = true; SortActionsByStartTime(NextActions); for (int i = 0; i < NextActions.Count; ++i) { WorldAction nextAction = NextActions[i]; if (nextAction.GetEndTime() != nextAction.StartAt + nextAction.Duration) { result = false; break; } if (ActualWorldAction != null && nextAction.StartAt < ActualWorldAction.GetEndTime()) { result = false; break; } if (i < NextActions.Count - 1) { if (NextActions[i + 1].StartAt.HasValue && NextActions[i + 1].StartAt < nextAction.GetEndTime()) { result = false; break; } } } return(result); }
private void deleteSelection() { if (selection.Count > 0) { WorldAction action = new WorldAction(ActionType.Delete, selection, selectionIndices); add(action); for (int i = 0; i < World.Lines.Count; i++) { LineGraph line = World.Lines[i]; for (int j = 0; j < selection.Count; j++) { WorldPoint point = selection[j]; if (line.Remove(point)) { selection.RemoveAt(j--); } } if (line.Count <= 1) { World.Lines.RemoveAt(i--); } Invalidate(); } } }
public void Redo() { if (actionIndex < actionList.Count) { WorldAction action = actionList[actionIndex]; switch (action.Type) { case ActionType.FreeDraw: case ActionType.PointDraw: World.Lines.Add(action.Line); break; case ActionType.Delete: for (int i = action.Points.Count - 1; i >= 0; i--) { WorldPoint point = action.Points[i]; point.Parent.RemoveAt(action.PointIndices[i]); } break; case ActionType.MoveSelection: foreach (WorldPoint point in action.Points) { point.X += action.Dx; point.Y += action.Dy; } break; } actionIndex++; } Invalidate(); }
public void Undo() { if (actionIndex > 0) { WorldAction action = actionList[actionIndex - 1]; switch (action.Type) { case ActionType.FreeDraw: case ActionType.PointDraw: World.Lines.Remove(action.Line); break; case ActionType.Delete: for (int i = 0; i < action.Points.Count; i++) { WorldPoint point = action.Points[i]; point.Parent.Insert(point, action.PointIndices[i]); } break; case ActionType.MoveSelection: foreach (WorldPoint point in action.Points) { point.X -= action.Dx; point.Y -= action.Dy; } break; } actionIndex--; } Invalidate(); }
public ActionCausesIfRecord(WorldAction worldAction, string resultExpression, string ifExpression) : base(WorldDescriptionRecordType.ActionCausesIf) { this.logicExpression = ServiceLocator.Current.GetInstance <ILogicExpression>(); this.resultExpression = resultExpression; this.ifExpression = ifExpression; this.worldAction = worldAction; }
public ActionReleasesIfRecord(WorldAction worldAction, Fluent fluent, string ifExpression) : base(WorldDescriptionRecordType.ActionReleasesIf) { this.logicExpression = ServiceLocator.Current.GetInstance <ILogicExpression>(); this.ifExpression = ifExpression; this.worldAction = worldAction; this.fluent = fluent; }
public ActionCausesIfRecord(WorldAction worldAction, string resultExpression, string ifExpression) : base(WorldDescriptionRecordType.ActionCausesIf) { this.logicExpression = ServiceLocator.Current.GetInstance<ILogicExpression>(); this.resultExpression = resultExpression; this.ifExpression = ifExpression; this.worldAction = worldAction; }
public ActionReleasesIfRecord(WorldAction worldAction, Fluent fluent, string ifExpression) : base(WorldDescriptionRecordType.ActionReleasesIf) { this.logicExpression = ServiceLocator.Current.GetInstance<ILogicExpression>(); this.ifExpression = ifExpression; this.worldAction = worldAction; this.fluent = fluent; }
public ActionInvokesAfterIfRecord(WorldAction worldAction, WorldAction result, int after, string ifExpression) : base(WorldDescriptionRecordType.ActionInvokesAfterIf) { this.logicExpression = ServiceLocator.Current.GetInstance<ILogicExpression>(); this.ifExpression = ifExpression; this.worldAction = worldAction; this.result = result; this.after = after; }
private void add(WorldAction action) { if (actionIndex < actionList.Count) { actionList.RemoveRange(actionIndex, actionList.Count - actionIndex); } actionList.Add(action); actionIndex++; }
public ActionInvokesAfterIfRecord(WorldAction worldAction, WorldAction result, int after, string ifExpression) : base(WorldDescriptionRecordType.ActionInvokesAfterIf) { this.logicExpression = ServiceLocator.Current.GetInstance <ILogicExpression>(); this.ifExpression = ifExpression; this.worldAction = worldAction; this.result = result; this.after = after; }
public Vertex(State state, WorldAction worldAction, int time, Vertex root) { ActualState = state; this.ActualWorldAction = worldAction; Time = time; Root = root; Initialize(); }
private void pointDrawActionMouseRightDown(MouseEventArgs e) { if (currentLineGraph != null && currentLineGraph.Count > 1) { World.Lines.Add(currentLineGraph); WorldAction action = new WorldAction(ActionType.PointDraw, currentLineGraph); add(action); } currentLineGraph = null; }
public void GetResultTest( [Values(0, 1)] int time, [Values(0, 1)] int expected) { _ifExpression = "a && b && c && d"; _expressionTriggersActionRecord = new ExpressionTriggersActionRecord(_worldAction, _ifExpression); WorldAction worldAction = _expressionTriggersActionRecord.GetResult(time); Assert.AreEqual(expected, _worldAction.StartAt); }
public void IsFulfilledWrongActionDurationTest() { _ifExpression = "a && b && c && d"; _actionReleasesIfRecord = new ActionReleasesIfRecord(_worldAction, _fluent, _ifExpression); _endedWorldAction = new WorldAction(_idWorldAction, _startTime, 7); bool result = _actionReleasesIfRecord.IsFulfilled(_state, _endedWorldAction); Assert.IsFalse(result); }
public void Process() { foreach (WorldObject obj in objects) { WorldAction action = obj.Process(this); if (action != WorldAction.None) { DoAction(obj, action); } } }
private void drawActionMouseUp(MouseEventArgs e) { if (currentLineGraph != null && currentLineGraph.Count > 1) { World.Lines.Add(currentLineGraph); WorldAction action = new WorldAction(ActionType.FreeDraw, currentLineGraph); add(action); } currentLineGraph = null; currentAction = ActionType.None; }
public bool IsFulfilled(State state, WorldAction endedWorldAction) { // Sprawdzamy czy to dana akcja się skończyła if(!endedWorldAction.Equals(this.worldAction)) return false; // Sprawdzamy czy zachodzi warunek this.logicExpression.SetExpression(ifExpression); var fluents = this.logicExpression.GetFluentNames(); var values = fluents.Select(t => new Tuple<string, bool>(t, state.Fluents.First(x => x.Name == t).Value)); return this.logicExpression.Evaluate(values); }
public bool CheckRecords(State state, WorldAction worldAction, int time) { foreach (ScenarioObservationRecord obs in observations) { if (!obs.CheckState(state, time)) { return(false); } } return(true); }
public void GetNextActionTimeWithOneAction() { const int Time = 1; var worldAction = new WorldAction(); worldAction.StartAt = Time; _vertex.NextActions.Add(worldAction); int result = _vertex.GetNextActionTime(); Assert.AreEqual(Time, result); }
// Searches the world for an action public ActionWithFiller ComputeBestAction(World world, WorldAction currentFillerAction, int currentPathIndex) { WorldAction bestAction = WorldAction.NoAction; WorldAction bestFillerAction = WorldAction.NoAction; float bestActionUtility = float.MinValue; // Determine which actions are possible World.Player currentPlayer = playerNum == 1 ? world.Player1 : world.Player2; List <WorldAction> possibleActions = currentPlayer.GetPossibleActions(); // Choose maximum-utility action out of all possibilies foreach (WorldAction action in possibleActions) { // Make a new clone of the world to run a simulated step World newState = world.Clone(); World.Player newCurrentPlayer = playerNum == 1 ? newState.Player1 : newState.Player2; newCurrentPlayer.Advance(new List <WorldAction>() { action }); newState.Advance(emptyList, false, false); //currentPathIndex = PathIndexFunction(newCurrentPlayer, currentPathIndex); // Decide filler action and do it repeatedly WorldAction potentialFillerAction = FillerActionFunction(action, currentFillerAction); List <WorldAction> fillerActionList = new List <WorldAction>() { potentialFillerAction }; for (int i = 0; i < StepSize - 1; i++) { newCurrentPlayer.Advance(fillerActionList); newState.Advance(emptyList, false, false); //currentPathIndex = PathIndexFunction(newCurrentPlayer, currentPathIndex); } // Calculate utility and update maximum //float utility = 0.0f; float utility = calculateUtility(newState, 0, true, float.MinValue, float.MaxValue, potentialFillerAction, currentPathIndex); if (utility > bestActionUtility) { bestAction = action; bestFillerAction = potentialFillerAction; bestActionUtility = utility; } } return(new ActionWithFiller(bestAction, bestFillerAction)); }
bool calculatePathNextFrame; // Indicates a path must be found in the next frame. // This allows for exact filtering for danger zone and A* pathfinding to be done in different // frames to improve the speed // Defines the association between level 1 actions and filler actions WorldAction getFillerAction(WorldAction action, WorldAction prevFillerAction) { // Decide filler action - should never be jumping or firing if (action == leftAction || action == rightAction || action == WorldAction.NoAction) { return(action); } else { return(prevFillerAction); } }
public void DoAction(WorldObject obj, WorldAction action) { switch (action) { case WorldAction.None: break; case WorldAction.UP: { if (obj.pos.Y > 0) { obj.pos.Y--; } obj.Reward(-1); break; } case WorldAction.DOWN: { if (obj.pos.Y < ny - 1) { obj.pos.Y++; } obj.Reward(-1); break; } case WorldAction.LEFT: { if (obj.pos.X > 0) { obj.pos.X--; } break; } case WorldAction.RIGHT: { if (obj.pos.X < nx - 1) { obj.pos.X++; } obj.Reward(-1); break; } case WorldAction.END: { worldEnd = true; break; } } }
public void GetNextActionTimeWithManyActions() { const int Time = 1; for (int i = Time; i < 5; ++i) { var worldAction = new WorldAction(); worldAction.StartAt = i; _vertex.NextActions.Add(worldAction); } int result = _vertex.GetNextActionTime(); Assert.AreEqual(Time, result); }
public bool IsFulfilled(State state, WorldAction endedWorldAction) { // Sprawdzamy czy to dana akcja się skończyła if (!endedWorldAction.Equals(this.worldAction)) { return(false); } // Sprawdzamy czy zachodzi warunek this.logicExpression.SetExpression(ifExpression); var fluents = this.logicExpression.GetFluentNames(); var values = fluents.Select(t => new Tuple <string, bool>(t, state.Fluents.First(x => x.Name == t).Value)); return(this.logicExpression.Evaluate(values)); }
private void picMain_Paint(object sender, PaintEventArgs e) { Graphics g = e.Graphics; //g.DrawLine(SC2ExtendImageData.penBlack, 0, 0, 500, 500); //world.Draw(g, new Rectangle(0, 0, 500, 500)); if (learningAgent != null) { if (chkMenuETable.Checked && (learningAgent is SARSALearningAgent)) { SARSALearningAgent l = (SARSALearningAgent)learningAgent; Bound bound = learningAgent.GetBound(l.eTable); foreach (float[] state in l.eTable.Keys) { Point p = world.StateToXY(state); Rectangle rect = world.GetRect(p.X, p.Y, new Rectangle(0, 0, 500, 500)); float[] eData = l.eTable[state]; float eMax = eData.Max(); int eMaxIndex = eData.ToList().IndexOf(eMax); WorldAction act = Me.IndexToAction(eMaxIndex); int c = (int)bound.map(eMax, 0, 255); g.FillRectangle(new SolidBrush(Color.FromArgb(c, c, c)), rect); g.DrawString(String.Format("{0:0.00}", eMax), drawFont, rect.Left, rect.Top); g.DrawString(String.Format("{0}", act.ToString()), drawFont, rect.Left, rect.Top + 12); } } else { Bound bound = learningAgent.GetBound(learningAgent.qTable); foreach (float[] state in learningAgent.qTable.Keys) { Point p = world.StateToXY(state); Rectangle rect = world.GetRect(p.X, p.Y, new Rectangle(0, 0, 500, 500)); float[] qData = learningAgent.qTable[state]; float qMax = qData.Max(); int qMaxIndex = qData.ToList().IndexOf(qMax); WorldAction act = Me.IndexToAction(qMaxIndex); int c = (int)bound.map(qMax, 0, 255); g.FillRectangle(new SolidBrush(Color.FromArgb(c, c, c)), rect); g.DrawString(String.Format("{0:0.00}", qMax), drawFont, rect.Left, rect.Top); g.DrawString(String.Format("{0}", act.ToString()), drawFont, rect.Left, rect.Top + 12); } } } world.Draw(g, new Rectangle(0, 0, 500, 500)); //g.DrawGrid(SC2ExtendImageData.penBlack, ,10,10); }
internal List <Vertex> GenerateChildsForLeaf(WorldDescription worldDescription, ScenarioDescription scenarioDescription, int TInf) { List <Vertex> vertices = new List <Vertex>(); int nextTime = GetNextTimestamp(scenarioDescription, TInf); if (!CheckNearestObservations(scenarioDescription, nextTime)) { return(GetImpossibleChilds()); } var implications = worldDescription.GetImplications(this, nextTime); WorldAction nextAction = scenarioDescription.GetActionAtTime(nextTime); vertices = CreateChildsBasedOnImplications(implications, nextAction, nextTime); return(vertices); }
public ExpressionTriggersActionRecord(WorldAction worldAction, string ifExpression) : base(WorldDescriptionRecordType.ExpressionTriggersAction) { this.logicExpression = new SimpleLogicExpression(ifExpression); this.worldAction = worldAction; }
public ImpossibleActionAtRecord(WorldAction worldAction, int time) : base(WorldDescriptionRecordType.ImpossibleActionAt) { this.worldAction = worldAction; this.time = time; }