상속: Model.Entity
예제 #1
0
            public static List <Node> GetAvilableNeighbor(Model.Unit agent, Node node)
            {
                List <Node> neighbor = new List <Node>();

                Vector2Int[] UDLR      = { Vector2Int.up, Vector2Int.down, Vector2Int.left, Vector2Int.right };
                Vector2Int[] diagonals =
                {
                    Vector2Int.up + Vector2Int.left,   Vector2Int.up + Vector2Int.right,
                    Vector2Int.down + Vector2Int.left, Vector2Int.down + Vector2Int.right
                };

                List <Vector2Int> positions = new List <Vector2Int>();

                foreach (Vector2Int vector in UDLR)
                {
                    positions.Add(node.unitPosition + vector);
                }

                foreach (Vector2Int vector in diagonals)
                {
                    positions.Add(node.unitPosition + vector);
                }

                foreach (Vector2Int position in positions)
                {
                    if (FieldManager.IsInField(position) && FieldManager.GetTile(position).IsPositionable(agent))
                    {
                        neighbor.Add(new Node(position, node));
                    }
                }

                return(neighbor);
            }
        public Unit Get_Unit_By_Id(int ID)
        {
            Unit _Unit = new Unit();

            DataTable dt = Unit_DA.Get_Unit_By_Id(ID);

            foreach (DataRow row in dt.Rows)
            {
                _Unit.ID = ID;
                _Unit.Name= row["Name"].ToString();
            }
            return _Unit;
        }
예제 #3
0
        /// <summary>
        /// 유닛의 이동경로를 찾는 알고리즘.
        /// </summary>
        /// <param name="unit">이동 유닛</param>
        /// <param name="from">출발 위치</param>
        /// <param name="to">도착 위치</param>
        /// <returns></returns>
        public static List <Vector2Int> PathFindAlgorithm(Model.Unit agent, Vector2Int from, Vector2Int to)
        {
            if (FieldManager.GetTile(to) == null || FieldManager.GetTile(to).HasUnit())
            {
                Debug.LogWarning("길찾기 알고리즘 오류");
                return(null);
            }

            Node        node     = new Node(from, to);
            List <Node> frontier = new List <Node>(); // priority queue ordered by Path-Cost, with node as the only element
            List <Node> explored = new List <Node>(); // an empty set

            frontier.Add(node);

            while (true)
            {
                InfiniteLoopDebug.Run("Pathfind", "GetClosestReachableDest", 258);
                if (frontier.Count == 0)
                {
                    Debug.Log("목적지에 갈수 있는 길이 존재하지 않습니다.");
                    return(null); // 답이 없음.
                }

                node = Node.PopSmallestCostNode(frontier);
                frontier.Remove(node);

                if (node.unitPosition.Equals(to)) // goal test
                {
                    return(Node.RebuildPath(node));
                }

                explored.Add(node); // add node.State to explored

                foreach (var child in Node.GetAvilableNeighbor(agent, node))
                {
                    bool isExplored = false;
                    foreach (var item in explored)
                    {
                        if (item.unitPosition == child.unitPosition)
                        {
                            isExplored = true;
                        }
                    }
                    if (isExplored.Equals(true))
                    {
                        continue;
                    }

                    bool isFrontiered = false;

                    for (int i = frontier.Count - 1; i >= 0; i--)
                    {
                        if (frontier[i].unitPosition.Equals(child.unitPosition))
                        {
                            isFrontiered = true;
                            if (child.unitPosition == frontier[i].unitPosition &&
                                child.evaluationCost < frontier[i].evaluationCost)
                            {
                                frontier.Remove(frontier[i]);
                                frontier.Add(child);
                            }
                        }
                    }

                    if (isFrontiered.Equals(false))
                    {
                        frontier.Add(child);
                    }
                }
            }
        }
예제 #4
0
		public void Add(Unit unit)
		{
			this.idUnits.Add(unit.Id, unit);
		}
        public string Insert(string Name)
        {
            Unit _Unit = new Unit();
            _Unit.Name = Name;
            _Unit.CreatedBy = Session["User"].ToString();

            return Unit_DA.Insert(_Unit);
        }
 /// <summary>
 ///     Decorates the specified <see cref="Report" />.
 /// </summary>
 /// <param name="report">The <see cref="Report" />.</param>
 /// <param name="unit">The <see cref="Unit" /> the <see cref="Report" /> belongs to.</param>
 /// <returns>The decorated <see cref="Report" />.</returns>
 public ReportDecorator Decorate(Report report, Unit unit)
 {
     return new ReportDecorator(report, unit, this._equipmentProvider, this._awardProvider, this._heroProvider);
 }
        public string Update(int ID, string Name)
        {
            Unit _Unit = new Unit();
            _Unit.ID = ID;
            _Unit.Name = Name;
            _Unit.UpdatedBy = Session["User"].ToString();

            if (_Unit.UpdatedBy.ToString().ToUpper() == ("Mr. Asif").ToString().ToUpper() || _Unit.UpdatedBy.ToString().ToUpper() == ("Saud Piracha").ToString().ToUpper())
            {
                return Unit_DA.Update(_Unit);
            }
            else
            {
                return "-1";
            }
        }
 /// <summary>
 ///     Decorates the specified <see cref="Unit" />.
 /// </summary>
 /// <param name="unit">The <see cref="Unit" />.</param>
 /// <returns>The decorated <see cref="Unit" />.</returns>
 public UnitDecorator Decorate(Unit unit)
 {
     return new UnitDecorator(unit, this);
 }
        /// <summary>
        ///     Gets the statistic progression for the specified unit.
        /// </summary>
        /// <param name="unit">A unit.</param>
        /// <param name="statistic">The statistic to use.</param>
        /// <returns>
        ///     The statistic progression for the specified unit.
        /// </returns>
        public static IEnumerable<KeyValuePair<string, double>> GetProgression(Unit unit, Statistic statistic)
        {
            if (statistic == Statistic.KillRatio)
            {
                return GetKillRatio(GetProgression(unit, Statistic.Kills), GetProgression(unit, Statistic.Losses));
            }

            return
                unit.Reports.Select(
                    report => new KeyValuePair<string, double>(report.ScenarioName, ReportFunctions[statistic](report)));
        }
        /// <summary>
        ///     Gets the statistic per scenario for the specified unit.
        /// </summary>
        /// <param name="unit">A unit.</param>
        /// <param name="statistic">The statistic to use.</param>
        /// <returns>
        ///     The statistic per scenario for the specified unit.
        /// </returns>
        public static IEnumerable<KeyValuePair<string, double>> GetPerScenario(Unit unit, Statistic statistic)
        {
            if (statistic == Statistic.KillRatio)
            {
                return GetKillRatio(GetPerScenario(unit, Statistic.Kills), GetPerScenario(unit, Statistic.Losses));
            }

            Func<Report, double> function = ReportFunctions[statistic];

            return
                unit.Reports.SelectByPrevious(
                    first => new KeyValuePair<string, double>(first.ScenarioName, function(first)),
                    (previous, current) =>
                    new KeyValuePair<string, double>(current.ScenarioName, (function(current) - function(previous))));
        }
        public static string Insert(Unit _Unit)
        {
            DbCommand command = Catalog_Access.CreateCommand();
            //Have to wite the stored procedure
            command.CommandText = "sp_insert_Unit";

            DbParameter param;

            param = command.CreateParameter();
            param.ParameterName = "@Name";
            param.Value = _Unit.Name;
            param.DbType = DbType.String;
            command.Parameters.Add(param);

            param = command.CreateParameter();
            param.ParameterName = "@CreatedBy";
            param.Value = _Unit.CreatedBy;
            param.DbType = DbType.String;
            command.Parameters.Add(param);

            param = command.CreateParameter();
            param.ParameterName = "@Return";
            param.DbType = DbType.String;
            param.Size = 2;
            param.Direction = ParameterDirection.Output;
            command.Parameters.Add(param);

            Catalog_Access.ExecuteNonQuery(command);

            string Return = command.Parameters["@Return"].Value.ToString();

            return Return;
        }
        public static string Update(Unit _Unit)
        {
            DbCommand command = Catalog_Access.CreateCommand();
            command.CommandText = "sp_Update_Unit";

            DbParameter param;

            param = command.CreateParameter();
            param.ParameterName = "@ID";
            param.Value = _Unit.ID;
            param.DbType = DbType.Int32;
            command.Parameters.Add(param);

            param = command.CreateParameter();
            param.ParameterName = "@Name";
            param.Value = _Unit.Name;
            param.DbType = DbType.String;
            command.Parameters.Add(param);

            param = command.CreateParameter();
            param.ParameterName = "@UpdatedBy";
            param.Value = _Unit.UpdatedBy;
            param.DbType = DbType.String;
            command.Parameters.Add(param);

            param = command.CreateParameter();
            param.ParameterName = "@Return";
            param.DbType = DbType.String;
            param.Size = 2;
            param.Direction = ParameterDirection.Output;
            command.Parameters.Add(param);
            Catalog_Access.ExecuteNonQuery(command);

            string Return = command.Parameters["@Return"].Value.ToString();

            return Return;
        }