public void InitialiseInstance(SolverNode parent, VectorInt2 playerBefore, VectorInt2 push, IBitmap crateMap, IBitmap moveMap) { base.Parent = parent; base.Clear(); // Check init/use should have a NEW id to avoid same-ref bugs; it is effectively a new instance solverNodeId = Interlocked.Increment(ref nextId); this.playerBefore = new VectorByte2(playerBefore); this.push = push switch { (0, 0) => (byte)0, (0, -1) => (byte)1, (0, 1) => (byte)2, (-1, 0) => (byte)3, (1, 0) => (byte)4, _ => throw new ArgumentOutOfRangeException(push.ToString()) }; this.crateMap = crateMap; this.moveMap = moveMap; this.status = (byte)SolverNodeStatus.UnEval; unchecked { var hashCrate = CrateMap.GetHashCode(); var hashMove = MoveMap.GetHashCode(); #if NET47 hash = hashCrate ^ (hashMove << (MoveMap.Width / 2)); #else hash = HashCode.Combine(hashCrate, hashMove); #endif } }
private void OnCollisionEnter2D(Collision2D collision) { if (collision.gameObject.tag == "Player") { Debug.Log("Map Move"); MoveMap?.Invoke(this, type); } }
private void OnTriggerEnter2D(Collider2D collision) { if (collision.tag == "Player") { Debug.Log("Map Move"); MoveMap?.Invoke(this, type); } }
private List <Vector2Int> moveTowardsPosition(Vector2Int pos) { MoveMap <GameObject> mm = master.staticMap; int w = mm.getWidth(); int h = mm.getHeight(); Location[,] walkMap = new Location[w, h]; transposeMoveMapOntoWalkMap(ref mm, ref walkMap); transposeMoveMapOntoWalkMap(ref master.entityMap, ref walkMap); List <Location> nextToCheck = new List <Location>(); Location start = new Location(position); start.state = Location.State.Closed; nextToCheck.Add(start); nextToCheck.AddRange(getAdjacentWalkable(ref walkMap, ref start, pos)); nextToCheck.Sort((loc1, loc2) => loc1.f.CompareTo(loc2.f)); for (int i = 0; i < nextToCheck.Count; i++) { Location loc = nextToCheck[i]; if (loc.point == pos) { //TODO THIS RETURN ISN'T RETURNING A WHOLE LIST List <Vector2Int> path = new List <Vector2Int>(); Location curr = loc; while (curr.prev != null) { path.Add(curr.point); curr = curr.prev; } path.Reverse(); return(path); } else { if (search(ref walkMap, ref loc, pos)) { //TODO THIS RETURN ISN'T RETURNING A WHOLE LIST List <Vector2Int> path = new List <Vector2Int>(); Location curr = loc; while (curr.prev != null) { path.Add(curr.point); curr = curr.prev; } path.Reverse(); return(path); } } } return(null); }
/// <summary> /// マップ表示更新 /// </summary> public void UpdateMapColor() { MonitorData monitor = MonitorData.GetInstance(); MoveMap moveMap = MoveMap.GetInstance(); for (int y = 0; y < dgvMap.Rows.Count; y++) { for (int x = 0; x < dgvMap.Columns.Count; x++) { dgvMap[x, y].Style.BackColor = moveMap.GetColor(x, y); } } }
/// <summary> /// 設定更新 /// </summary> private void updateSettings() { SettingData setting = SettingData.GetInstance(); DoubleText doubleText = null; // ロボットの縦 doubleText = (DoubleText)pnlSetting.Controls[0]; doubleText.Value = setting.RobotSize.Vertical; // ロボットの横 doubleText = (DoubleText)pnlSetting.Controls[1]; doubleText.Value = setting.RobotSize.Horizontal; // 畑の縦 doubleText = (DoubleText)pnlSetting.Controls[2]; doubleText.Value = setting.FarmSize.Vertical; // 畑の横 doubleText = (DoubleText)pnlSetting.Controls[3]; doubleText.Value = setting.FarmSize.Horizontal; // 草刈り開始時刻 usrKusakariStart.DayOfWeek = (int)setting.KusakariStart.DayOfWeek; usrKusakariStart.Hour = setting.KusakariStart.Hour; usrKusakariStart.Minute = setting.KusakariStart.Minulte; // 夜警開始時刻 usrYakeiStart.DayOfWeek = (int)setting.YakeiStart.DayOfWeek; usrYakeiStart.Hour = setting.YakeiStart.Hour; usrYakeiStart.Minute = setting.YakeiStart.Minulte; // 動作完了判定閾値 FloatText floatText = (FloatText)pnlSetting.Controls[4]; floatText.Value = setting.MoveEndRate * 100; // エリアマップ生成 AreaMap areaMap = AreaMap.GetInstance(); areaMap.Allocate(setting.MapLength, setting.MapWidth); // 動作マップ生成 MoveMap moveMap = MoveMap.GetInstance(); moveMap.Allocate(setting.MapLength, setting.MapWidth); }
private void transposeMoveMapOntoWalkMap(ref MoveMap <GameObject> mm, ref Location[,] walkMap) { for (int x = 0; x < mm.getWidth(); x++) { for (int y = 0; y < mm.getHeight(); y++) { if (mm[x, y] != null) { if (walkMap[x, y] == null) { walkMap[x, y] = new Location(x, y); } walkMap[x, y].state = Location.State.Closed; } } } }
/// <summary> /// モニタ更新 /// </summary> private void updateMonitors() { foreach (Control control in pnlMonitor.Controls) { MonitorLabel label = (MonitorLabel)control; label.UpdateValue(); } foreach (Control control in pnlDetail.Controls) { MonitorLabel label = (MonitorLabel)control; label.UpdateValue(); } foreach (Control control in pnlSystemError.Controls) { MonitorLabel label = (MonitorLabel)control; label.UpdateValue(); } lblMovedRate.Text = string.Format("{0:F1}", MoveMap.GetInstance().MovedRate); lblStateDateTime.Text = MonitorData.GetInstance().Commander.LastStartDate.ToString(); }
public void SelectMap(BaseTile root) { MoveMap.SelectMap((HexTile)root, Player); AttackMap.SelectMap((HexTile)root, Player); }
/* * Request a PathMap given a MoveMap and starting position. * Early exits a particular path after reaching maxTotalMove. */ public static PathMap RequestPathMap(MoveMap moveMap, Vector2Int startPosition, float maxTotalMove) { PathMap pathMap = new PathMap(startPosition); // 'Priority queue' for tracking which nodes to move forward from List <PathNode> frontier = new List <PathNode> () { new PathNode(startPosition, 0) }; //TODO: Can be simplified by using actual graph nodes instead of Vector2Int coordinates // Neighbors could be gathered simply with 'currNode.neighbors', and be graph shape agnostic // The cost of additional references may or may not outweigh the overhead of vector math below Vector2Int[] neighborDirs = new Vector2Int[] { Vector2Int.up, Vector2Int.right, Vector2Int.down, Vector2Int.left }; while (frontier.Count > 0) { PathNode curr = frontier[0]; frontier.RemoveAt(0); for (int i = 0; i < neighborDirs.Length; i++) { Vector2Int next = curr.location + neighborDirs[i]; // Unpathable, ignore completely if (moveMap.GetMoveCost(next.x, next.y) == float.PositiveInfinity) { continue; } float totalMoveCost = curr.moveCost + moveMap.GetMoveCost(next.x, next.y); // Not enough move left to push frontier if (totalMoveCost > maxTotalMove) { continue; } // Either add new node or replace existing values if (!pathMap.nodes.ContainsKey(next)) { pathMap.nodes.Add(next, new PathNode(curr.location, totalMoveCost)); } else if (pathMap.nodes.ContainsKey(next) && pathMap.nodes[next].moveCost > totalMoveCost) { pathMap.nodes[next] = new PathNode(curr.location, totalMoveCost); } // New totalMoveCost isn't good enough to push frontier else { continue; } frontier.Add(new PathNode(next, totalMoveCost)); } // Would possibly perform better if using a sorted list instead of resorting entire list each time frontier.Sort((n1, n2) => n1.moveCost.CompareTo(n2.moveCost)); } return(pathMap); }
protected override void analyzeCore(byte[] data) { MoveMap moveMap = MoveMap.GetInstance(); moveMap.Update(data); }
public override IoCommand GetReverseCommand() { Dictionary <string, string> reverseMap = MoveMap.ToDictionary(x => x.Value, x => x.Key); return(new MoveFileCommand(reverseMap)); }
// Use this for initialization void Start() { staticMap = new MoveMap <GameObject>(MAP_WIDTH, MAP_HEIGHT); entityMap = new MoveMap <GameObject>(MAP_WIDTH, MAP_HEIGHT); }