Beispiel #1
0
        private void ProcessGame()
        {
            int i = 0;

            foreach (var sequence in Sequences)
            {
                InitiliazeTurtleForSequence();

                i++;
                PrintMessage(string.Format("Sequence number {0}: ", i));

                foreach (var move in sequence)
                {
                    if (move == "m")
                    {
                        _turtle.MoveTurtle();
                    }
                    else if (move == "r")
                    {
                        _turtle.RotateTurtle();
                    }

                    if (GameState.IsOutsideOfBounds(_turtle))
                    {
                        PrintMessage("Turtle outside bounds \n");
                        goto breakLoops;
                    }

                    if (GameState.IsHitMine(_turtle))
                    {
                        PrintMessage("Hit Mine! \n");
                        goto breakLoops;
                    }

                    if (GameState.IsExit(_turtle))
                    {
                        PrintMessage("Sucess :) \n");
                        goto breakLoops;
                    }
                }

                if (GameState.IsStillInDange(_turtle))
                {
                    PrintMessage("Missing Turtle on board \n");
                }

                breakLoops :;
            }
        }
Beispiel #2
0
        /// <summary>
        /// Process sequence of moves represented as binary array. If turtle moves, check for terminal result or continue until all moves processed. Return incomplete if moves list exhausted.
        /// </summary>
        /// <param name="args">Sequence of moves to complete, board to complete them on</param>

        public static string ProcessMoveSequence(int[] moves, Board board)
        {
            Turtle.Pos = (int[])board.StartPos.Clone();
            Turtle.Dir = board.StartDir;

            for (int i = 0; i < moves.Length; i++)
            {
                if (moves[i] == MOVE)
                {
                    Turtle.MoveTurtle();

                    int x = Turtle.Pos[0];
                    int y = Turtle.Pos[1];

                    bool isOutOfBounds = ((x < 0 || board.N <= x) || (y < 0 || board.M <= y));

                    if (isOutOfBounds)
                    {
                        return(OUTOFBOUNDS);
                    }
                    else if (board.Tiles[x, y] == Board.EXIT)
                    {
                        return(SUCCESS);
                    }
                    else if (board.Tiles[x, y] == Board.MINE)
                    {
                        return(FAILURE);
                    }
                }
                else if (moves[i] == ROTATE)
                {
                    Turtle.RotateTurtle();
                }
            }

            return(INCOMPLETE);
        }