protected BattleTurn.ActionArgs PerformAction(Player[] players, HexGrid grid, bool commitAction) { //if in range of target => attack if (CoordRange.CoordInRange(cubeCoordinate, target.CubeCoordinate, Stats.Range.Value)) { if (commitAction) { BasicAttack(players, target, grid); } return(new BattleTurn.ActionArgs(this, target, BattleTurn.updateAction.Attack, null, -1)); } //if out of range => try to move into range, move by step distance in unit stats. else { //follow shortest path if possible. Vector3[] path = AStarPathFinder.GetPath(cubeCoordinate, target.CubeCoordinate, Stats.Range.Value, grid.Size, grid.GetAllOccupiedTiles()); if (!(path == null)) { //calculate the index of the path to move to depending on move distance. // i.e. a unit with move distance 2 can skip the first location on the path, // and move to the second in one update call. int moveIndex = (Stats.MoveDistance.Value > path.Length) ? path.Length - 1 : Stats.MoveDistance.Value - 1; Vector3 stepDestination = path[moveIndex]; if (commitAction) { MoveToTile(grid, stepDestination); } //return action log data about what move the unit is making i.e. (this unit is acting, its moving, along path specified)... return(new BattleTurn.ActionArgs(this, target, BattleTurn.updateAction.Move, path, moveIndex)); } //if no possible path is found, do nothing - there is no possible move. return(new BattleTurn.ActionArgs(this, null, BattleTurn.updateAction.None, null, -1)); } }
private void timer_Tick(object sender, EventArgs e) { var coordRange = new CoordRange(_triangle.Left.X, _triangle.Right.X, _triangle.Up.Y, _triangle.Right.Y); if (_shiftFactor >= 0.02) { _drawer.ClearArea(); var point = _randomizer.RandomizePointInTriangle(coordRange, _areaSize); var node = Translator.TranslatePointToNode(point); var nodes = _som.StartModifyNodes(node, _neighborRadius, _shiftFactor); var points = Translator.TranslateNodesToPoints(nodes); DrawWithFrequency(points, point); _iteration++; UpdateIterationInfo(); CalculateRadius(); CalculateShiftFactor(); } else { btnGenerate.Enabled = true; btnStartPause.Enabled = false; btnStop.Enabled = false; grpBoxConfig.Enabled = true; timer.Stop(); } }
private void InitializeSom() { var startedRange = new CoordRange(200, 300, 250, 350); var nodes = _randomizer.RandomizeStartedNodesInTriangle(_neuronsCount, startedRange, _areaSize); var points = Translator.TranslateNodesToPoints(nodes); _drawer.DrawPoints(points, _pointsDiameter, _pointsColor, PointType.Filled); _drawer.DrawLines(points, _lineWidth, _linesColor); _som = new SelfOrganizingMap(nodes); }