Live Tree Gen
Added client-server communication to sync client techs with DB techs and visualize the tree of actual techs
This commit is contained in:
parent
dabfc62481
commit
6ca699be26
7 changed files with 159 additions and 111 deletions
|
|
@ -6,7 +6,6 @@ using System.Reflection;
|
|||
using System.Text.RegularExpressions;
|
||||
using LiteNetLib;
|
||||
using MessagePack;
|
||||
using QuickGraph;
|
||||
using Unity.Mathematics;
|
||||
using static Unity.Mathematics.math;
|
||||
using Random = Unity.Mathematics.Random;
|
||||
|
|
@ -293,33 +292,33 @@ public static class ObjectExtensions
|
|||
(r2.y + r2.height >= r1.y && r2.y <= r1.y + r1.height);
|
||||
}
|
||||
|
||||
public static IEnumerable<T> FindPath<T>(this IEnumerable<Edge<T>> data, T source, T target, Func<T, T, double> costFunction, bool bestFirst = true) where T : class
|
||||
{
|
||||
List<DijkstraVertex<T>> members = new List<DijkstraVertex<T>>{new DijkstraVertex<T>{Vertex = source}};
|
||||
List<T> searched = new List<T>();
|
||||
while (true)
|
||||
{
|
||||
var v = members.Where(m=>!searched.Contains(m.Vertex)).OrderBy(m=>bestFirst?m.Heuristic:m.Cost).FirstOrDefault();
|
||||
if (v == null) return null; // No vertices left unsearched
|
||||
if (v.Vertex == target)
|
||||
{
|
||||
Stack<DijkstraVertex<T>> path = new Stack<DijkstraVertex<T>>();
|
||||
path.Push(v);
|
||||
while(path.Peek().Parent!=null)
|
||||
path.Push(path.Peek().Parent);
|
||||
return path.Select(dv => dv.Vertex).ToList();
|
||||
}
|
||||
members.AddRange(data.Where(l => l.Source == v.Vertex).Select(l => l.Target).Concat(data.Where(l => l.Target == v.Vertex).Select(l => l.Source))
|
||||
.Where(n => members.All(m => m.Vertex != n)).Select(n =>
|
||||
{
|
||||
var c = new DijkstraVertex<T> {Parent = v, Vertex = n, Cost = v.Cost + costFunction(v.Vertex,n)};
|
||||
if (bestFirst)
|
||||
c.Heuristic = c.Cost + costFunction(c.Vertex,target);
|
||||
return c;
|
||||
}));
|
||||
searched.Add(v.Vertex);
|
||||
}
|
||||
}
|
||||
// public static IEnumerable<T> FindPath<T>(this IEnumerable<Edge<T>> data, T source, T target, Func<T, T, double> costFunction, bool bestFirst = true) where T : class
|
||||
// {
|
||||
// List<DijkstraVertex<T>> members = new List<DijkstraVertex<T>>{new DijkstraVertex<T>{Vertex = source}};
|
||||
// List<T> searched = new List<T>();
|
||||
// while (true)
|
||||
// {
|
||||
// var v = members.Where(m=>!searched.Contains(m.Vertex)).OrderBy(m=>bestFirst?m.Heuristic:m.Cost).FirstOrDefault();
|
||||
// if (v == null) return null; // No vertices left unsearched
|
||||
// if (v.Vertex == target)
|
||||
// {
|
||||
// Stack<DijkstraVertex<T>> path = new Stack<DijkstraVertex<T>>();
|
||||
// path.Push(v);
|
||||
// while(path.Peek().Parent!=null)
|
||||
// path.Push(path.Peek().Parent);
|
||||
// return path.Select(dv => dv.Vertex).ToList();
|
||||
// }
|
||||
// members.AddRange(data.Where(l => l.Source == v.Vertex).Select(l => l.Target).Concat(data.Where(l => l.Target == v.Vertex).Select(l => l.Source))
|
||||
// .Where(n => members.All(m => m.Vertex != n)).Select(n =>
|
||||
// {
|
||||
// var c = new DijkstraVertex<T> {Parent = v, Vertex = n, Cost = v.Cost + costFunction(v.Vertex,n)};
|
||||
// if (bestFirst)
|
||||
// c.Heuristic = c.Cost + costFunction(c.Vertex,target);
|
||||
// return c;
|
||||
// }));
|
||||
// searched.Add(v.Vertex);
|
||||
// }
|
||||
// }
|
||||
|
||||
class DijkstraVertex<T>
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue