public Mice(Mice mice) { memory = new Memory(mice.getMemory()); curPoint = new Point(mice.getCurPoint().X, mice.getCurPoint().Y); this.healthPoint = mice.getHealthPoint(); this.manaPoint = mice.getManaPoint(); }
public Boolean isEndPoint(Mice m) { //출발지가 아니고, 자신의 위치 4방향에 출구가 있다면 탈출 Point curPoint = m.getCurPoint(); return(!(curPoint.X == 2 && curPoint.Y == 2) && ((curPoint.X + 1 == row && mazeArr[(int)curPoint.X + 1, (int)curPoint.Y] == 0) || (curPoint.Y + 1 == col && mazeArr[(int)curPoint.X, (int)curPoint.Y + 1] == 0) || (curPoint.X - 2 == 0 && mazeArr[(int)curPoint.X - 1, (int)curPoint.Y] == 0) || (curPoint.Y - 2 == 0 && mazeArr[(int)curPoint.X, (int)curPoint.Y - 1] == 0))); }
public State(Maze maze, Mice mice, String dir) { this.curMaze = new Maze(maze); this.curMice = new Mice(mice); Point p = curMice.getCurPoint(); cord = "( " + p.X + " , " + p.Y + " ) "; step = "" + curMice.getMemory().getStep(); this.dir = dir; }
public Point getCurBestPath(Point target) { Point nextPoint = target; if (target.X > 0 && target.Y > 0) { Point micePoint = mice.getCurPoint(); for (int i = 0; i < 4; i++) { int newX = (int)micePoint.X + dirPriority[i, 0]; int newY = (int)micePoint.Y + dirPriority[i, 1]; if (shortPath.getInnerTile(target, new Point(newX, newY)) != null) { nextPoint = new Point(newX, newY); break; } } } return(nextPoint); }
public void calculateInnerPath(Point p, Maze m, Mice mice) { int[,] dirPriority = new int[4, 2] { { 1, 0 }, { 0, 1 }, { -1, 0 }, { 0, -1 } }; bool[,] visit = new bool[m.getRow() + 2, m.getCol() + 2]; Queue <Node> buf = new Queue <Node>(); Node resultNode = null; Point endPoint = mice.getCurPoint(); buf.Enqueue(new Node(p, null)); visit[(int)p.X, (int)p.Y] = true; do { Node curNode = buf.Dequeue(); Point curPoint = curNode.getChild(); if (curPoint.X == endPoint.X && curPoint.Y == endPoint.Y) { resultNode = curNode; } for (int i = 0; i < 4; i++) { int newX = (int)curPoint.X + dirPriority[i, 0]; int newY = (int)curPoint.Y + dirPriority[i, 1]; if (newX <= 0 || newY <= 0 || newX > m.getRow() || newY > m.getCol()) { continue; } if (visit[newX, newY]) { continue; } if (mice.getMemory(newX, newY) == 0) { continue; } if (mice.getMemory(newX, newY) < 0 && !m.isAvailable(newX, newY)) { continue; } Point newPoint = new Point(newX, newY); buf.Enqueue(new Node(newPoint, curNode)); visit[newX, newY] = true; } } while (buf.Any()); if (resultNode != null) { Node curNode = resultNode; int step = 1; Point startPoint = curNode.getChild(); Point nextPoint = new Point(-1, -1); while (curNode != null) { innerChache[(int)startPoint.X, (int)startPoint.Y].Add(new TileNode(p, nextPoint, step++)); curNode = curNode.getParent(); if (curNode == null) { break; } nextPoint = startPoint; startPoint = curNode.getChild(); } } }