Пример #1
0
 public void rotation(Maze m, Mice mice, int temp = 0)
 {
     if (count != -1)            //스캔으로 도착지를 찾지 않았다면
     {
         //도착지 로테이션 구현
         //쥐가 기억하고 있는 위치이고, 벽이라면 목적지 변경
         while ((mice.getMemory().getMemory(end_row, end_col) == Constants.MEMORY && !m.isAvailable(end_row, end_col)) || temp == -1)
         {
             if (end_col == 1 && end_row < m.getRow())
             {
                 end_row++;
             }
             else if (end_col < m.getCol() && end_row == m.getRow())
             {
                 end_col++;
             }
             else if (end_col == m.getCol() && end_row > 1)
             {
                 end_row--;
             }
             else if (end_col > 1 && end_row == 1)
             {
                 end_col--;
             }
             temp = 0;
         }
     }
 }
Пример #2
0
        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)));
        }
Пример #3
0
 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();
 }
Пример #4
0
        public Simulation(String content, Canvas myCanvas, ListView myListView, DockPanel rightPanel, ProgressBar hpStatus, ProgressBar mpStatus)
        {
            maze = new Maze(content);

            MAX_HP     = 2 * maze.getRow() * maze.getCol();
            MIN_WEIGHT = (maze.getRow() * maze.getCol()) * 2;

            mice      = new Mice(MAX_HP, 0);
            shortPath = new ShortestPath();

            traceback = new Stack <Point>();
            stateLog  = new ObservableCollection <State>();

            traceback.Push(new Point(1, 2));

            dirPriority = new int[4, 2] {
                { 1, 0 }, { 0, 1 }, { -1, 0 }, { 0, -1 }
            };

            actionState = 0;

            this.myCanvas    = myCanvas;
            this.myListView  = myListView;
            this.rightPanel  = rightPanel;
            this.hpStatus    = hpStatus;
            this.mpStatus    = mpStatus;
            hpStatus.Maximum = MAX_HP;
            hpStatus.Value   = hpStatus.Maximum;
            mpStatus.Maximum = MAX_HP;
            mpStatus.Value   = 0;

            this.myListView.ItemsSource = stateLog;
        }
Пример #5
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;
        }
Пример #6
0
        public void loadState(State state)      //클릭한 번호로 상태를 로드(완벽하지는 않음)
        {
            int idx = stateLog.IndexOf(state);

            if (MessageBox.Show(idx + "번째로 돌아갑니까?", "Question", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.No)
            {
                return;
            }

            for (int i = stateLog.Count - 1; i > idx; i--)
            {
                stateLog.RemoveAt(i);
                traceback.Pop();
            }

            clearPath();
            actionState = 0;

            maze = state.getMaze();
            mice = state.getMice();

            initCanvas();
        }
Пример #7
0
        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();
                }
            }
        }