public static List<Hex> GetConnectedSeas(MapCM map, int playerID, Hex h, int moveLimit, bool is_possible_to_attack_enemy) { List<Hex> res = new List<Hex>(); res.Add(h); _GetConnectedSeas(map, playerID, h, moveLimit, res, is_possible_to_attack_enemy); return res; }
public static List<Hex> GetSeaPath(MapCM map, Hex from, Hex to, int playerID, int moveLimit, bool is_possible_to_attack_enemy = true) { Dictionary<Hex, int> moveCosts = new Dictionary<Hex, int>(); moveCosts[from] = 0; _GetSeaPathMoveCosts(moveCosts, map, from, playerID, moveLimit, 1, is_possible_to_attack_enemy); if (!moveCosts.ContainsKey(to)) return null; List<Hex> path = new List<Hex>(); _GetSeaPathFromMoveCosts(map, from, to, moveCosts, path, moveCosts[to]); return path; }
private static void _GetConnectedSeas(MapCM map, int playerID, Hex h, int moveLimit, List<Hex> res, bool is_possible_to_attack_enemy) { if (moveLimit < 1) return; List<Hex> neighbours = map.GetPointNeighbors(h); for(int i = 0; i < neighbours.Count; ++i) { Hex n = neighbours[i]; if (!res.Contains(n)) { if (map.IsPointAccessibleForShip(n, playerID, false)) { res.Add(n); _GetConnectedSeas(map, playerID, n, moveLimit - 1, res, is_possible_to_attack_enemy); } else if (is_possible_to_attack_enemy && map.IsPointAccessibleForShip(n, playerID, true)) { res.Add(n); continue; } } } }
protected static void _GetSeaPathFromMoveCosts(MapCM map, Hex from, Hex to, Dictionary<Hex, int> moveCosts, List<Hex> path, int curCost) { List<Hex> neibors = map.GetNeiborSeasByMapPos(from); for (int i = 0; i < neibors.Count; ++i) { Hex h = neibors[i]; if (moveCosts.ContainsKey(h) && moveCosts[h] == curCost - 1) { path.Add(h); if (h == to) return; else _GetSeaPathFromMoveCosts(map, from, to, moveCosts, path, moveCosts[h]-1); break; } } }
protected static void _GetSeaPathMoveCosts(Dictionary<Hex, int> moveCosts, MapCM map, Hex from, int playerID, int moveLimit, int curCost, bool is_possible_to_attack_enemy) { if (moveLimit == 0) return; List<Hex> neibors = map.GetNeiborSeasByMapPos(from); for (int i = 0; i < neibors.Count; ++i) { Hex h = neibors[i]; if (map.IsPointAccessibleForShip(h, playerID, is_possible_to_attack_enemy)) { if (!moveCosts.ContainsKey(h) || moveCosts[h] > curCost) { moveCosts[h] = curCost; int enemyID = map.GetSeaPointOwnerID(h); if (enemyID == playerID || enemyID == PlayerInfoCM.NoID) _GetSeaPathMoveCosts(moveCosts, map, h, playerID, moveLimit - 1, curCost + 1, is_possible_to_attack_enemy); } } } }
internal void CreateMap() { map = new MapCM(); if (OnCreateMap != null) OnCreateMap(); }