public void SetPlayerOrigineZone(int playerId, Zone zone) { GameData game = GameData.Instance; if (playerId < 0 || playerId > 3) { return; } players[playerId].origine = zone; if (playerId == GameData.Instance.myId) { game.myFlag = CentralMap.GetMap(zone); game.myFlagZone = zone; } else { game.enemyFlag = CentralMap.GetMap(zone); game.enemyFlagZone = zone; } if (game.myFlag != null && game.enemyFlag != null) { ShortestWayNode swn = null; game.enemyFlag.TryGetValue(game.myFlagZone.id, out swn); NodeZone nz = swn.GetNextNodeZone(); game.enemyDistance = nz.cost; Player.DebugLog("Dist based:" + game.enemyDistance); } }
public void Add(NodeZone node) { if (node != null) { directions.Add(node); } }
/// <summary> /// J'ajouter les feuilles d'exploration à la carte. /// L'idée est que chaque case doit possèder des liens vers c'est parent du tour avant. /// Et le nombre de ressource pour arriver au point voulu /// </summary> /// <param name="parent"> The direction where to go</param> /// <param name="leaf">La zone de feuille à ajoute à la map</param> /// <param name="currentCost">Le cout total pour arrivé à destination</param> /// <param name="map">La carte actuelle</param> private static void AddLeafToMap(Zone parent, Zone leaf, int currentCost, ref Dictionary <int, ShortestWayNode> map) { ShortestWayNode swn = null; map.TryGetValue(leaf.id, out swn); if (swn == null) { swn = new ShortestWayNode(leaf); map.Add(leaf.id, swn); } NodeZone nz = new NodeZone(parent, currentCost); swn.Add(nz); }
public NodeZone GetNextNodeZone() { int minCost = 10000; NodeZone next = null; foreach (NodeZone nz in directions) { if (nz.cost < minCost) { next = nz; minCost = nz.cost; } } return(next); }
public void SetPlayerOrigineZone(bool isEnemy, Zone zone) { if (isEnemy) { enemyFlagLocalisation = zone; enemyFlagPath = CentralMap.GetMap(zone); } else { myFlagLocalisation = zone; myFlagPath = CentralMap.GetMap(zone); } if (myFlagLocalisation != null && enemyFlagPath != null) { ShortestWayNode swn = null; enemyFlagPath.TryGetValue(myFlagLocalisation.id, out swn); NodeZone nz = swn.GetNextNodeZone(); enemyDistance = nz.cost; } }
static public List <GameObject> AlgorithmCluster(GameObject previous_node, GameObject next_node) { // Dictionary<GameObject,Dictionary<list<gameobject>,float> List <GameObject> connectors_in_start_cluster = new List <GameObject>(); List <GameObject> connectors_in_end_cluster = new List <GameObject>(); float temp_cost = 10000000f; List <GameObject> c_path = new List <GameObject>(); //step0: check if 2 node in same zone NodeZone previouse_zone = previous_node.GetComponent <PathNode>().my_zone; NodeZone next_zone = next_node.GetComponent <PathNode>().my_zone; if (previouse_zone == next_zone) { return(AlgorithmA(previous_node, next_node)); } //step1: find all connector nodes in start cluster && all connector nodes in end cluster for (int i = 0; i < all_connector_nodes.Count; i++) { if (all_connector_nodes[i].GetComponent <PathNode>().my_zone == previouse_zone) { connectors_in_start_cluster.Add(all_connector_nodes[i]); } else if (all_connector_nodes[i].GetComponent <PathNode>().my_zone == next_zone) { connectors_in_end_cluster.Add(all_connector_nodes[i]); } } //step2: For each connector node in start cluster, find all path from previous node to each connector //add them to dictionary with key which is that connector node Dictionary <GameObject, Node> all_path_form_previous_to_all_start_cluster = new Dictionary <GameObject, Node>(); //(endnode,pathfromstart(allpath,totalcost) foreach (GameObject go in connectors_in_start_cluster) { List <GameObject> pathes_btw_previous_go = new List <GameObject>(); pathes_btw_previous_go = AlgorithmA(previous_node, go); float cost = go.GetComponent <PathNode>().total_cost; Node pathes_and_cost_btw_previous_go = new Node(pathes_btw_previous_go, cost, HeuristicType.Dijkstra); //add into the table of all_path_from... all_path_form_previous_to_all_start_cluster.Add(go, pathes_and_cost_btw_previous_go); } //step3: For each connector node in end cluster, find all path from each connector to end node Dictionary <GameObject, Node> all_path_form_all_end_cluster_to_next = new Dictionary <GameObject, Node>(); //(startnode,pathtonextnode(allpathes,totalcost)) foreach (GameObject go in connectors_in_end_cluster) { List <GameObject> pathes_btw_go_next = new List <GameObject>(); pathes_btw_go_next = AlgorithmA(go, next_node); float cost = go.GetComponent <PathNode>().total_cost; Node pathes_and_cost_btwin_go_next = new Node(pathes_btw_go_next, cost, HeuristicType.Dijkstra); all_path_form_all_end_cluster_to_next.Add(go, pathes_and_cost_btwin_go_next); } // Step4:try to find a path can connect from start zone to end zone // by match ( end node of table of start cluster) to (startnode from connectertable) //then match ( end node from connectertable) to (start node of table of endcluster) foreach (KeyValuePair <GameObject, Node> start_kvp in all_path_form_previous_to_all_start_cluster) { // beacuse finding path with algorithA ==> only one element in Dictionary<List<GameObject>, float>> float startcost = start_kvp.Value.cost; List <GameObject> temp_start_path = start_kvp.Value.path; foreach (KeyValuePair <GameObject, Node> end_kvp in all_path_form_all_end_cluster_to_next) { float endcost = end_kvp.Value.cost; List <GameObject> temp_end_path = end_kvp.Value.path; KeyValuePair <GameObject, Dictionary <GameObject, Node> > pair1 = new KeyValuePair <GameObject, Dictionary <GameObject, Node> >(start_kvp.Key, connecters_path_table[start_kvp.Key]); KeyValuePair <GameObject, Node> pair2 = new KeyValuePair <GameObject, Node>(end_kvp.Key, connecters_path_table[start_kvp.Key][end_kvp.Key]); float temp_total_cost = startcost + endcost + pair2.Value.cost; //find path with shortest cost===> add to path if (temp_total_cost < temp_cost) { temp_cost = temp_total_cost; // List<GameObject> temp_total_path = new List<GameObject>(); c_path.AddRange(temp_start_path); c_path.AddRange(pair2.Value.path); c_path.AddRange(temp_end_path); } } } // Debug.Log(c_path.Count); return(c_path); }