示例#1
0
        public LINK_POINT               Follow(LINK_POINT _entryPoint)
        {
            switch (m_type)
            {
            //				case 0:								// Full block: can't use
            case 1: return(LINK_POINT.BOTTOM);                          // Cross shape: fall down anyway

            // Tube shapes
            case 2:                                                                             // Horizontal tube: pass through
                switch (_entryPoint)
                {
                case LINK_POINT.LEFT: return(LINK_POINT.RIGHT);                                         // Pass from left to right

                case LINK_POINT.RIGHT: return(LINK_POINT.LEFT);                                         // Pass from right to left
                }
                break;

            case 3:                                                                             // Vertical tube: fall through
                if (_entryPoint == LINK_POINT.TOP)
                {
                    return(LINK_POINT.BOTTOM);
                }
                break;

            // 2 bent tubes-shapes
            case 4:                                                                             // 2 bent tubes: top=>left, right=>down
                switch (_entryPoint)
                {
                case LINK_POINT.TOP: return(LINK_POINT.LEFT);                                           // Fall from top to left

                case LINK_POINT.RIGHT: return(LINK_POINT.BOTTOM);                                       // Fall from right to bottom

                case LINK_POINT.LEFT: throw new LoseMomentumException();
                }
                break;

            case 5:                                                                             // 2 bent tubes: top=>right, left=>down
                switch (_entryPoint)
                {
                case LINK_POINT.TOP: return(LINK_POINT.RIGHT);                                          // Fall from top to right

                case LINK_POINT.LEFT: return(LINK_POINT.BOTTOM);                                        // Fall from left to bottom

                case LINK_POINT.RIGHT: throw new LoseMomentumException();
                }
                break;

            // T-shapes
            case 6:                                                                             // T opening to top
                switch (_entryPoint)
                {
                case LINK_POINT.TOP: throw new CrashException();                                        // Crashes from top

                case LINK_POINT.LEFT: return(LINK_POINT.RIGHT);                                         // Pass from left to right

                case LINK_POINT.RIGHT: return(LINK_POINT.LEFT);                                         // Pass from right to left
                }
                break;

            case 7:                                                                             // T opening to right
                switch (_entryPoint)
                {
                case LINK_POINT.TOP: return(LINK_POINT.BOTTOM);                                         // Fall through

                case LINK_POINT.RIGHT: return(LINK_POINT.BOTTOM);                                       // Fall from right to bottom
                }
                break;

            case 8:                                                                             // T opening to bottom
                switch (_entryPoint)
                {
                case LINK_POINT.LEFT: return(LINK_POINT.BOTTOM);                                        // Fall from left to bottom

                case LINK_POINT.RIGHT: return(LINK_POINT.BOTTOM);                                       // Fall from right to bottom
                }
                break;

            case 9:                                                                             // T opening to left
                switch (_entryPoint)
                {
                case LINK_POINT.TOP: return(LINK_POINT.BOTTOM);                                         // Fall through

                case LINK_POINT.LEFT: return(LINK_POINT.BOTTOM);                                        // Fall from left to bottom
                }
                break;

            // Curve shapes
            case 10:
                switch (_entryPoint)
                {
                case LINK_POINT.TOP: return(LINK_POINT.LEFT);

                case LINK_POINT.LEFT: throw new LoseMomentumException();
                }
                break;

            case 11:
                switch (_entryPoint)
                {
                case LINK_POINT.TOP: return(LINK_POINT.RIGHT);

                case LINK_POINT.RIGHT: throw new LoseMomentumException();
                }
                break;

            case 12:
                if (_entryPoint == LINK_POINT.RIGHT)
                {
                    return(LINK_POINT.BOTTOM);
                }
                break;

            case 13:
                if (_entryPoint == LINK_POINT.LEFT)
                {
                    return(LINK_POINT.BOTTOM);
                }
                break;
            }
            throw new Exception("Unhandled!");
        }
示例#2
0
    public static void Main(string[] args)
    {
        string line = Console.ReadLine();                  // represents a line in the grid and contains W integers. Each integer represents one room of a given type.

        Console.Error.WriteLine(line);
        string[] inputs = line.Split(' ');
        int      W      = int.Parse(inputs[0]); // number of columns.
        int      H      = int.Parse(inputs[1]); // number of rows.

        Room[,] rooms = new Room[W, H];
        for (int Y = 0; Y < H; Y++)
        {
            line = Console.ReadLine();             // represents a line in the grid and contains W integers. Each integer represents one room of a given type.
            Console.Error.WriteLine(line);

            string[] RoomTypes = line.Split(' ');
            for (int X = 0; X < W; X++)
            {
                rooms[X, Y] = new Room()
                {
                    X = X, Y = Y, m_type = int.Parse(RoomTypes[X])
                }
            }
            ;
        }

        line = Console.ReadLine();         // the coordinate along the X axis of the exit (not useful for this first mission, but must be read).
        Console.Error.WriteLine(line);
        int EX = int.Parse(line);

        // game loop
        while (true)
        {
            line = Console.ReadLine();             // the coordinate along the X axis of the exit (not useful for this first mission, but must be read).
            Console.Error.WriteLine(line);
            inputs = line.Split(' ');
            int        XI = int.Parse(inputs[0]);
            int        YI = int.Parse(inputs[1]);
            LINK_POINT entryPoint;
            switch (inputs[2])
            {
            case "TOP": entryPoint = LINK_POINT.TOP; break;

            case "LEFT": entryPoint = LINK_POINT.LEFT; break;

            case "RIGHT": entryPoint = LINK_POINT.RIGHT; break;

            default: throw new Exception("Unexpected entry point type \"" + inputs[2] + "\"!");
            }

            Room       currentRoom = rooms[XI, YI];
            LINK_POINT exitPoint   = currentRoom.Follow(entryPoint);
            Console.Error.WriteLine("Exiting room through " + exitPoint);

            int XO = XI;
            int YO = YI;
            switch (exitPoint)
            {
            case LINK_POINT.LEFT: XO--; break;

            case LINK_POINT.RIGHT: XO++; break;

            case LINK_POINT.BOTTOM: YO++; break;

            default: throw new Exception("Unsupported exit point!");                            // Can't ever go up!
            }
            Console.Error.WriteLine("New room is (" + XO + ", " + YO + ")");

            // One line containing the X Y coordinates of the room in which you believe Indy will be on the next turn.
            Console.WriteLine(XO.ToString() + " " + YO.ToString());
        }
    }
}