public IList <DdrPs2FileDataTableEntry> Read(HeuristicResult heuristicResult, Stream stream)
        {
            var table   = _ddrPs2FileDataTableChunkStreamReader.GetUnbound(stream);
            var decoded = _ddrPs2FileDataUnboundTableDecoder.Decode(table);

            return(decoded);
        }
Beispiel #2
0
    string PrintHeuristic(HeuristicResult hr)
    {
        System.Reflection.FieldInfo[] fieldInfos = hr.GetType().GetFields(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic);

        string output = "======" + hr.m_Unit + "'s " + hr.m_Node.m_NodeHighlight.name + "======\n";

        foreach (var item in fieldInfos)
        {
            try
            {
                output += $"{item.Name}: {item.GetValue(hr)}\n";
            }
            catch (ArgumentException)
            {
                output += $"{item.Name}: unobtainable\n";
            }
        }

        return(output);
    }
Beispiel #3
0
    /// <summary>
    /// Updates the movement values of a heuristic result or adds one if it doesn't exist
    /// </summary>
    /// <param name="value"></param>
    /// <param name="n"></param>
    /// <param name="u"></param>
    /// <param name="distance"></param>
    private void AddOrUpdateHeuristic(float value, Node node, Unit unit)
    {
        HeuristicResult hr = FindHeuristic(node, unit);

        if (hr != null)         // If the heuristic already exists, update it
        {
            // If the existing heuristic already a better score, move on
            if (hr.m_MovementValue >= value)
            {
                return;
            }

            // Otherwise set values
            hr.m_MovementValue = value;
        }
        else         // Otherwise create a new heuristic with the values
        {
            m_HeuristicResults.Add(new HeuristicResult(unit, node, value));
        }
    }
Beispiel #4
0
    /// <summary>
    /// Updates the movement values of a heuristic result or adds one if it doesn't exist
    /// </summary>
    /// <param name="value"></param>
    /// <param name="n"></param>
    /// <param name="u"></param>
    /// <param name="distance"></param>
    private void AddOrUpdateHeuristic(int distance, Node node, Unit unit)
    {
        HeuristicResult hr = FindHeuristic(node, unit);

        if (hr != null)         // If the heuristic already exists, update it
        {
            // If the existing heuristic already a lower distance score
            if (hr.m_MoveDistance < distance)
            {
                return;
            }

            // Otherwise set values
            hr.m_MoveDistance = distance;
        }
        else         // Otherwise create a new heuristic with the values
        {
            m_HeuristicResults.Add(new HeuristicResult(unit, node, distance));
        }
    }
Beispiel #5
0
    private void FindPath(ref List <IPathResult> sequence, PathingData data)
    {
        List <HeuristicResult> results = new List <HeuristicResult>(m_generators.Count);

        foreach (var gen in m_generators)
        {
            gen.Initialise(data);
            float heuristicOuput = gen.Execute();

            results.Add(new HeuristicResult
            {
                HeuristicValue = heuristicOuput,
                Node           = gen
            });

            //This means we have found a perfect result.
            if (1.0f == heuristicOuput)
            {
                break;
            }
        }

        //sort by heuricitc
        results = results.OrderBy(r => r.HeuristicValue).ToList();
        //get the first value as this should be the best result.
        HeuristicResult res = results[0];

        IPathResult path = res.Node.Path;

        sequence.Add(path);

        //if we haven't reached our destination keep going.
        if (path.EndPoint != data.TargetLocation)
        {
            data.CurrentPosition = path.EndPoint;
            data.CurrentTime     = path.EndPointTime;
            data.FacingDir       = path.FacingDir;

            FindPath(ref sequence, data);
        }
    }
Beispiel #6
0
        public SvagContainer Read(HeuristicResult result, Stream stream)
        {
            if (!(result is VagHeuristicResult info))
            {
                return(null);
            }

            if (info.Start != null)
            {
                stream.TryRead(0, (int)info.Start);
            }

            var output = _vagStreamReader.Read(stream, info.Channels ?? 1, info.Interleave ?? 0);

            output.Volume     = info.Volume;
            output.SampleRate = info.SampleRate;
            output.Length     = info.Length;

            return(new SvagContainer
            {
                SampleRate = info.SampleRate,
                VagChunk = output
            });
        }
        public VagChunk Read(HeuristicResult result, Stream stream)
        {
            if (!(result is VagHeuristicResult info))
            {
                return(null);
            }

            var decryptStream = info.Key != null
                ? new BeatmaniaPs2NewAudioDecryptStream(stream, info.Key)
                : stream;

            if (info.Start != null)
            {
                stream.TryRead(0, (int)info.Start);
            }

            var output = _vagStreamReader.Read(decryptStream, info.Channels ?? 1, info.Interleave ?? 0);

            output.Volume     = info.Volume;
            output.SampleRate = info.SampleRate;
            output.Length     = info.Length;

            return(output);
        }
Beispiel #8
0
 public IEnumerable <SsqChunk> Read(HeuristicResult heuristicResult, Stream stream)
 {
     return(_ssqStreamReader.Read(stream));
 }
Beispiel #9
0
 public TimImage Read(HeuristicResult heuristicResult, Stream stream)
 {
     return(_timStreamReader.Read(stream));
 }
        public VagChunk Read(HeuristicResult result, Stream stream)
        {
            var info = result as VagHeuristicResult;

            return(_vagStreamReader.Read(stream, info?.Channels ?? 1, info?.Interleave ?? 0));
        }
Beispiel #11
0
    /// <summary>
    /// Makes all AI units take their turns
    /// </summary>
    public void TakeAITurn()
    {
        if (UnitsManager.m_Instance.m_ActiveEnemyUnits.Count == 0)
        {
            Debug.Log("<color=#471d1d>[AI]</color> No enemies. Ending turn");
            BattleManager.m_Instance.EndCurrentTurn();
            return;
        }

        if (!m_CurrentAIUnit)           // If no AI unit is currently taking their turn
        {
            m_HeuristicResults.Clear(); // Get rid of the cached heuristics
            // Calculate all the new heuristics for each unit
            foreach (Unit unit in UnitsManager.m_Instance.m_ActiveEnemyUnits)
            {
                // Only calculate movement heuristics if the unit can move
                if (unit.GetCurrentMovement() > 0)
                {
                    Debug.Log($"<color=#8440a8>[Movement]</color> {unit.name} has {unit.GetCurrentMovement()} movement");
                    // Movement Heuristics
                    DoMovementHeuristics(unit);
                }

                // Only calculate skill heuristics if the unit has actions
                if (unit.GetActionPoints() > 0)
                {
                    foreach (BaseSkill skill in unit.GetSkills())
                    {
                        // Make sure the skill isn't on cooldown.
                        if (skill.GetCurrentCooldown() > 0)
                        {
                            continue;
                        }

                        List <Node> nodesWithUnits = Grid.m_Instance.GetNodesWithinRadius(
                            skill.m_AffectedRange + skill.m_CastableDistance + unit.GetCurrentMovement(),
                            Grid.m_Instance.GetNode(unit.transform.position),
                            true
                            ).Where(n => n.unit != null).ToList();

                        switch (skill)
                        {
                        case StatusSkill ss:
                            DoStatusHeuristic(nodesWithUnits, ss, unit);
                            break;

                        case DamageSkill ds:
                            DoAttackHeuristic(nodesWithUnits, ds, unit);
                            break;

                        case HealSkill hs:
                            DoHealHeuristic(nodesWithUnits, hs, unit);
                            break;

                        default:
                            Debug.LogError("<color=#9c4141>[Skill]</color><color=#6e4747> Bad skill!</color>", skill);
                            break;
                        }
                    }
                }
            }


            // Remove all the empty choices made by setting the movement costs
            m_HeuristicResults = m_HeuristicResults.Where(c => c.SumHeuristics() != 0).ToList();

            if (m_HeuristicResults.Count == 0)
            {
                // No AI moves left, end your turn.
                BattleManager.m_Instance.EndCurrentTurn();
                return;
            }

            // Sort all the moves regardless of whether they're reachable
            List <HeuristicResult> sortedChoices = m_HeuristicResults.OrderByDescending(hr => hr.SumHeuristics()).ToList();

            foreach (HeuristicResult choice in sortedChoices)
            {
                if (choice.SumHeuristics() == 0)
                {
                    continue;
                }

                Unit aiUnit = choice.m_Unit;

                // Get all the nodes the unit could move to.
                List <Node> nodesInMovement = Grid.m_Instance.GetNodesWithinRadius(aiUnit.GetCurrentMovement(), Grid.m_Instance.GetNode(aiUnit.transform.position));

                // Check if the current best node is within the movement range of the unit.
                if (nodesInMovement.Contains(choice.m_Node))
                {
                    m_BestOption    = choice;
                    m_CurrentAIUnit = m_BestOption.m_Unit;
                    Debug.Log($"===={m_CurrentAIUnit.name} taking turn====");
                    Debug.Log($"<color=#3f5c9e>[Heuristics]</color> Found best option: {m_CurrentAIUnit.name} moving to {m_BestOption.m_Node.m_NodeHighlight.name} from {Grid.m_Instance.GetNode(m_CurrentAIUnit.transform.position).m_NodeHighlight.name}");
                    m_MakingAction = true;
                    PlayerManager.m_Instance.SetSelectedUnit(m_CurrentAIUnit);
                    if (m_BestOption.m_MoveDistance != 0)
                    {
                        m_CurrentAIUnit.DecreaseCurrentMovement(m_BestOption.m_MoveDistance);
                        FindPathToOptimalNode();
                    }
                    else
                    {
                        // There's no movement, so just run the function that runs at the end of moving
                        OnFinishMoving();
                    }
                    return;
                }
                else
                {
                    Debug.Log($"<color=#3f5c9e>[Heuristics]</color><color=#6e4747> A better move for {aiUnit.name} was found outside of the movable area</color>");
                }
            }

            if (!m_CurrentAIUnit)
            {
                // Assume no more units left.
                BattleManager.m_Instance.EndCurrentTurn();
                return;
            }
        }
    }