void Start() { //Create large Landscape largeMap = Map.createLandscape(20, 20); scoutingActive = false; healingActive = false; //Create tactical Map; smallMap = Map.createSmallHexa(); Map.setLookout(5); finishTile = EventFunctionCollection.GetRandomField(); Map.setFinish(finishTile); //WICHTIG DRIN BEHALTEN!!! caravanPosition = new HexaPos(0, 0); //Map.discoverAllTiles(true); //Gesamt Skalierung des Brettspiels hilfreich für die Kameraführung. Momentan skalierung 10x Initialisation.mapGO.transform.localScale = new Vector3(10, 10, 10); turn = 0; moveCaravan(new HexaPos(0, 0)); meeples = new List <Meeple>(); sandstorms = new List <Sandstorm>(); activeCompanion = null; rand = new System.Random(); activeMode = GameMode.PREPARATION; createMeeple <Hunter>("prep1", new HexaPos(2, 11), true); createMeeple <Mercenary>("prep2", new HexaPos(4, 12), true); createMeeple <Healer>("prep3", new HexaPos(5, 13), true); createMeeple <Scout>("prep4", new HexaPos(7, 14), true); createMeeple <PackAnimal>("prep5", new HexaPos(13, 12), true); createMeeple <Prince>("Prince", new HexaPos(8, 7)); }
public override HexaPath FindPath(PathPlanningGraph graph, HexaPos start) { int planningLength = graph.planningLength; HexaPath path = new HexaPath(); path.AddPos(start); _agent.Update(path, _localEntropy); double[][] estimations = Backpropagation(1, graph, _localEntropy); for (int i = 1; i < planningLength; i++) { Console.WriteLine("At level " + i.ToString()); for (int j = 0; j < estimations[i].Length; j++) { int posX = graph[i].mNodes[j].pos.X; int posY = graph[i].mNodes[j].pos.Y; Console.WriteLine("Pos[" + posX.ToString() + "," + posY.ToString() + "]=" + estimations[i][j].ToString()); } } for (int t = 1; t < planningLength; t++) { //_agent.Update(path, _localEntropy); //double[] estimations = Backpropagation(t, graph, _localEntropy); int index = FindMax(path[t - 1], estimations, t, graph); path.AddPos(graph[t].mNodes[index].pos); _agent.Update(path, _localEntropy); } return(path); }
public HexaPath FindPath(TopologyGraph graph, HexaPos start, HexaPos end) { HexaPath path = new HexaPath(); Graph G = new Graph(); int gridWidth = graph.hexes.GetLength(0); int gridHeight = graph.hexes.GetLength(1); List <Node> nodelist = new List <Node>(); for (int j = 0; j < gridHeight; j++) { for (int i = 0; i < gridWidth; i++) { HexaPos tempPos = graph.hexes[i, j].GetHexaPos(); Hex tempHex = _map.GetHex(tempPos.X, tempPos.Y); if (_map.mapState.IsObstacle(tempHex) == false) { Node n = G.AddNode(tempPos.X, tempPos.Y, 0); nodelist.Add(n); } } } List <HexaGridEdge> .Enumerator etE = graph.edgeList.GetEnumerator(); while (etE.MoveNext()) { Node a = findNode(nodelist, etE.Current.GetA().X, etE.Current.GetA().Y); Node b = findNode(nodelist, etE.Current.GetB().X, etE.Current.GetB().Y); if (a != null && b != null) { G.AddArc(a, b, 1); G.AddArc(b, a, 1); } } Node startNode = findNode(nodelist, start.X, start.Y); Node endNode = findNode(nodelist, end.X, end.Y); Console.WriteLine("- Best path to reach " + startNode.ToString() + " from " + endNode.ToString() + " :"); AStar AS = new AStar(G); if (AS.SearchPath(startNode, endNode)) { // foreach (Arc A in AS.PathByArcs) Console.WriteLine( A.ToString() ); foreach (Node N in AS.PathByNodes) { Console.WriteLine(N.ToString()); HexaPos n = new HexaPos((int)N.X, (int)N.Y); path.AddPos(n); } } else { Console.WriteLine("No result !"); } return(path); }
public static HexaPos getPositionDirectionalByDistance(HexaPos _originalPos, int _dir, int _dist) { switch (_dir) { case 0: _originalPos.x -= _dist; return(_originalPos); case 1: _originalPos.y -= _dist; return(_originalPos); case 2: _originalPos.x += _dist; _originalPos.y -= _dist; return(_originalPos); case 3: _originalPos.x += _dist; return(_originalPos); case 4: _originalPos.y += _dist; return(_originalPos); case 5: _originalPos.x -= _dist; _originalPos.y += _dist; return(_originalPos); } return(new HexaPos(0, 0)); }
private void mapViewPanel_Paint(object sender, PaintEventArgs e) { if (human != null) { int humanPathLength = human.path.Length; if (humanPathLength > 0) { HexSet humanHexSet = map.MapState.GetHexSet(human.hexSetIdx); for (int i = 0; i < humanPathLength; i++) { HexaPos pos = human.path[i]; humanHexSet.hexSet.Add(map.GetHex(pos.X, pos.Y)); } } else { if (map.MapState.GetHexSetNum() > 0) { HexSet humanHexSet = map.MapState.GetHexSet(human.hexSetIdx); humanHexSet.hexSet.Clear(); } } } if (mapVisible == true) { if (mapDrawer != null) { mapDrawer.Draw(e.Graphics); } } }
HexaPath EstimatePath(PathPlanningGraph graph, int currentLevel, HexaPos lastPos, Rewards reward) { HexaPath newpath = new HexaPath(); int endLevel = graph.planningLength - 1; for (int t = currentLevel; t <= endLevel; t++) { PlanningNode lastNode = graph[t - 1].GetNode(lastPos); List <PlanningEdge> edges = graph[t - 1].GetEdges(lastNode); double maxVal = -0.01; HexaPos maxPos = null; List <PlanningEdge> .Enumerator e = edges.GetEnumerator(); while (e.MoveNext()) { int nextIdx = graph[t].GetIndex(e.Current.to); if (reward.totalRewards[t][nextIdx] > maxVal) { maxPos = graph[t].mNodes[nextIdx].pos; maxVal = reward.totalRewards[t][nextIdx]; } } newpath.AddPos(maxPos); lastPos = maxPos; } return(newpath); }
public void DumpPath(HexaPath path, string filename) { using (StreamWriter sw = new StreamWriter(filename)) { XmlTextWriter xtw = new XmlTextWriter(sw); xtw.WriteStartDocument(); xtw.WriteStartElement("path"); xtw.WriteAttributeString("map", _mapFilename); for (int t = 0; t < path.Length; t++) { HexaPos pos = path[t]; xtw.WriteStartElement("position"); xtw.WriteAttributeString("idx_x", pos.X.ToString()); xtw.WriteAttributeString("idx_y", pos.Y.ToString()); xtw.WriteAttributeString("pos_x", _map.GetHex(pos.X, pos.Y).centroid.X.ToString()); xtw.WriteAttributeString("pos_y", _map.GetHex(pos.X, pos.Y).centroid.Y.ToString()); xtw.WriteString(t.ToString()); xtw.WriteEndElement(); } xtw.WriteEndElement(); xtw.WriteEndDocument(); } }
public static void positionAndParent_Meeple(GameObject Meeple, HexaPos position) { GameObject par = GameObject.Find("MeepleCollection"); GameObject fath = new GameObject(Meeple.GetComponent <Meeple>().meepleName); fath.transform.localScale = par.transform.lossyScale; fath.transform.position = par.transform.position; Meeple.transform.localScale = par.transform.lossyScale; Meeple.transform.position = par.transform.position; Meeple.transform.localEulerAngles = new Vector3(0, 180, 0); //Meeple.transform.Translate(new Vector3(0, 0.4f, 0), Space.Self); fath.transform.parent = par.transform; Meeple.transform.parent = fath.transform; setMeeplePos(Meeple, position); Meeple mip = Meeple.GetComponent <Meeple>(); if (mip.GetType().IsSubclassOf(typeof(Companion))) { Companion c = Meeple.GetComponent <Companion>(); if (c.GetType().Name != "PackAnimal") { c.setFoodPackages_hpBar(); } } }
public int GetExclusiveExpandingNodeNum(PathPlanningGraph graph, HexaPos start) { ExpandingTree tree = GetExclusiveExpandingTree(graph, start); tree.Draw("EXCLUSIVE-EXPANDING-TREE"); return(tree.nodeNum); }
void Awake() { alive = true; pos = new HexaPos(0, 0); walkRange = 1; meepleName = "StandardName"; Debug.Log("AWAKE MEEPOLE"); }
double CalcExhScore(HexaPos current, int level, PathPlanningGraph graph, double[,] entropy, HexaPath path) { _maxPath = null; _maxScore = 0.0; HexaPath newPath = (HexaPath)path.Clone(); FindMaxPath(graph, newPath, current); return(_maxScore); }
public static void discover(HexaPos tile) { GameObject undiscov = landscape[tile.x, tile.y].transform.FindChild("undiscovered").gameObject; undiscov.SetActive(false); GameObject actmap = landscape[tile.x, tile.y].transform.FindChild("actualTile").gameObject; actmap.SetActive(true); }
public void AddEdge(HexaPos a, HexaPos b) { HexaGridEdge edge = new HexaGridEdge(a, b); if (!_edgeList.Contains(edge)) { _edgeList.Add(edge); } }
public override HexaPath FindPath(PathPlanningGraph graph, HexaPos start) { int planningLength = graph.planningLength; HexaPath path = new HexaPath(); path.AddPos(start); return(path); }
public static HexaPos GetRandomField() { System.Random rnd = new System.Random(); int x = rnd.Next(0, SceneHandler.largeMap.GetLength(0)); int y = rnd.Next(0, SceneHandler.largeMap.GetLength(1)); HexaPos res = new HexaPos(x, y); return(res); }
public List <HexaPos> getGuidedPos() { List <HexaPos> guidedTiles = new List <HexaPos>(); HexaPos guidePos = Map.getPositionDirectionalByDistance(new HexaPos(Pos.x, Pos.y), 1, 1); guidedTiles.Add(guidePos); guidePos = Map.getPositionDirectionalByDistance(new HexaPos(Pos.x, Pos.y), 2, 1); guidedTiles.Add(guidePos); return(guidedTiles); }
public PlanningForm(PathPlanningGraph graph, HexagonalMap map, Agent agent, HexaPos startPos, HexagonalMapDrawer mapDrawer, HexaPath humanPath = null) { _graph = graph; _map = map; _mapDrawer = mapDrawer; _agent = agent; _startPos = startPos; _humanPath = humanPath; _planMethod = planMethod.UNKNOWN; InitializeComponent(); }
public static void moveCaravan(HexaPos pos) { lastPosition = caravanPosition; Vector3 pubPos = Map.MapTileToPosition(pos); Initialisation.innerTileHolderGO.transform.localPosition = pubPos; Map.setActiveTile(pos, lastPosition); Map.discover(pos); caravanPosition = pos; endTurn(true); }
void UpdateEstimation(Rewards reward, double[,] entropy, PathPlanningGraph graph, int fromLevel, int stopAt) { for (int t = fromLevel; t <= stopAt; t++) { int num = graph[t].mNodes.Count; for (int i = 0; i < num; i++) { HexaPos currentPos = graph[t].mNodes[i].pos; reward.instantRewards[t][i] = GetEstimation(_agent, entropy, currentPos, _map); reward.totalRewards[t][i] = reward.instantRewards[t][i]; } } }
public PlanningNode GetNode(HexaPos pos) { List <PlanningNode> .Enumerator e = mNodes.GetEnumerator(); while (e.MoveNext()) { if (e.Current.pos.X == pos.X && e.Current.pos.Y == pos.Y) { return(e.Current); } } return(null); }
private static void killTheNegative(List <HexaPos> li) { for (int i = 0; i < li.Count; i++) { HexaPos l = li[i]; if (l.x < 0 || l.y < 0) { li.RemoveAt(i); killTheNegative(li); break; } } }
public override HexaPath FindPath(PathPlanningGraph graph, HexaPos start) { //initial first beamNum of the paths for (int i = 0; i < beamNum; i++) { beamPaths[i].AddPos(start); } GenerateAllBeamPaths(graph); return(beamPaths[0]); }
public static int distance(HexaPos pos_1, HexaPos pos_2) { bool notYethit = true; if (pos_1.x == pos_2.x && pos_1.y == pos_2.y) { return(0); } int distCounter = 0; HexaPos temp = pos_1; while (notYethit) { int xdist = Mathf.Abs(pos_2.x - temp.x); int ydist = Mathf.Abs(pos_2.y - temp.y); distCounter++; List <HexaPos> tilesAround = tilesInRange(temp, 1); //Check if Tile is around foreach (HexaPos h in tilesAround) { if (h == pos_2) { return(distCounter); } } //Check the best Tile Direction foreach (HexaPos h in tilesAround) { int distCurX = Mathf.Abs(pos_2.x - h.x); int distCurY = Mathf.Abs(pos_2.y - h.y); if (distCurX < xdist && distCurY < ydist) { temp = h; xdist = distCurX; ydist = distCurY; break; } else if (distCurX < xdist || distCurY < ydist) { temp = h; xdist = distCurX; ydist = distCurY; } } } return(0); }
public override HexaPath FindPath(PathPlanningGraph graph, HexaPos start) { _maxPath = null; _maxScore = 0.0; _pathNumCnt = 0; HexaPath path = new HexaPath(); //path.AddPos(start); FindMaxPath(graph, path, start); return(_maxPath); }
private void btnRobotPath_Click(object sender, EventArgs e) { if (this.rbBatchTest.Checked == true) { //ParameterTester tester = new ParameterTester(this); //GdParameterTester tester = new GdParameterTester(this); TeleportTester tester = new TeleportTester(this); tester.Run(); MessageBox.Show("Finished batch test"); } else { // apply parameters _human.WingmanToleranceRange = int.Parse(tbWR.Text); _human.SetObservationRange(int.Parse(tbHR.Text)); TopologyGraphGenerator topologyGenerator = new TopologyGraphGenerator(_map); TopologyGraph tograph = topologyGenerator.GetTopologyGraph(); //graph.Print(); tograph.Draw(); PlanningGraphGenerator planningGenerator = new PlanningGraphGenerator(tograph); PathPlanningGraph planGraph = planningGenerator.GetPathPlanningGraph(this.HumanPath, this.human.WingmanToleranceRange); planGraph.Draw(); HexaPos startPos = _human.path[0]; PlanningGraphPruner pruner = new PlanningGraphPruner(); PathPlanningGraph newPlanGraph = pruner.GetPlanningGraph(planGraph, startPos); newPlanGraph.Draw("PlanningGraph2"); PathPlanningGraph prunedPlanGraph = pruner.BackwardPrune(newPlanGraph); prunedPlanGraph = pruner.ForwardPrune(prunedPlanGraph); prunedPlanGraph.Draw("PrunedPlanningGraph"); /* * ExhaustiveDFSPathPlanner planner = new ExhaustiveDFSPathPlanner(_map, _robot); * HexaPath maxPath = planner.FindPath(prunedPlanGraph, startPos); * * Console.WriteLine("PATH BY EXHAUSTIVE DFS: " + maxPath.ToString()); */ _planningForm = new PlanningForm(prunedPlanGraph, _map, _robot, startPos, _mapDrawer, _human.path); _planningForm.Show(); } }
public HexaPath FindPath(PathPlanningGraph graph, HexaPos start) { HexaPath path = null; double currentScore = 0.0; PlanningNode startNode = graph[0].GetNode(start); ExpandingNode root = new ExpandingNode(startNode); ExpandingTree expandingTree = new ExpandingTree(root); Console.WriteLine("The number of complete expanding node is " + graph.GetExpandingNodeNumber()); bool exhaustivelyEnumerated = false; bool stopCritera = false; int counter = 0; HexaPath maxPath = null; double maxScore = 0.0; do { path = ExpandToFindPath(expandingTree, graph, _localEntropy); if (path == null) { stopCritera = true; } else { currentScore = ScorePath(_agent, _localEntropy, path); if (currentScore > maxScore) { maxScore = currentScore; maxPath = path; } } //expandingTree.Draw("Expanding-Tree-" + counter.ToString()); counter++; Console.WriteLine(counter + ", " + maxScore + ", " + expandingTree.nodeNum); }while((iteratingOnce == false || exhaustivelyEnumerated == true) && (stopCritera == false)); //expandingTree.Draw("Expanding-Tree-N"); Console.WriteLine("The number of node expanded is " + expandingTree.nodeNum); return(maxPath); }
public PathPlanningGraph GetPathPlanningGraph(HexaPath path, int radius) { int planningLength = path.Length; PathPlanningGraph planningGraph = new PathPlanningGraph(planningLength); // create vertex for (int t = 0; t < planningLength; t++) { HexaPos pivot = path[t]; List <HexaPos> hexes = _topologicalGraph.GetMap().GetHexes(pivot.X, pivot.Y, radius, true); List <HexaPos> .Enumerator e = hexes.GetEnumerator(); while (e.MoveNext()) { Hex currentHex = _topologicalGraph.GetMap().GetHex(e.Current.X, e.Current.Y); if (false == _topologicalGraph.GetMap().MapState.IsObstacle(currentHex)) { PlanningNode node = new PlanningNode(e.Current); planningGraph.AddPlanningNode(node, t); } } } // create edge for (int t = 0; t < planningLength - 1; t++) { LevelPartite currentPartite = planningGraph[t]; LevelPartite nextPartite = planningGraph[t + 1]; List <PlanningNode> .Enumerator e1 = currentPartite.mNodes.GetEnumerator(); List <PlanningNode> .Enumerator e2 = nextPartite.mNodes.GetEnumerator(); while (e1.MoveNext()) { while (e2.MoveNext()) { if (_topologicalGraph.IsConnected(e1.Current.pos, e2.Current.pos)) { currentPartite.Connect(e1.Current, e2.Current); } } e2 = nextPartite.mNodes.GetEnumerator(); } } return(planningGraph); }
HexaPath GetMaxPath(int level, PlanningNode startNode, PathPlanningGraph graph, double[][] estimatedReward) { HexaPath path = new HexaPath(); int endLevel = graph.planningLength - 1; //path.AddPos(startNode.pos); HexaPos lastPos = startNode.pos; for (int t = level + 1; t <= endLevel; t++) { int index = FindMax(lastPos, estimatedReward[t - level], t, graph); path.AddPos(graph[t].mNodes[index].pos); lastPos = path[path.Length - 1]; } return(path); }
public HexaPos GetMaxPos(List <HexaPos> hexes) { double maxValue = 0; HexaPos maxPos = null; List <HexaPos> .Enumerator e = hexes.GetEnumerator(); while (e.MoveNext()) { if (_entropy[e.Current.X, e.Current.Y] >= maxValue) { maxPos = e.Current; } } return(maxPos); }
public void Update(Agent agent, HexaPos currentPos) { int radius = agent.GetObservationRange(); SetProbability(currentPos.X, currentPos.Y, 0); List <HexaPos> hexes = _map.GetHexes(currentPos.X, currentPos.Y, radius, false); List <HexaPos> .Enumerator e = hexes.GetEnumerator(); while (e.MoveNext()) { double prob = _probability[currentPos.X, currentPos.Y]; prob = prob * agent.confidenceFactor; SetProbability(currentPos.X, currentPos.Y, prob); } }