Exemple #1
0
    public static long solve(RectangularDungeon d)
    {
        // TODO: implementar algoritmo para determinar la cantidad total de
        //       habitaciones existentes en el calabozo tipo matrix rectangular
        // Valor: 4 puntos
        // Restriccion: la cantidad de movimientos de tu solucion no debe
        //              exceder 4 veces el de mi solucion; ver ejemplo en Main
        //              para comparar tus resultados contra los mios

        // Ejemplo de interaccion:
        // d.GoThruDoor(Direction.SOUTH);


        int width  = 1;
        int height = 1;

        while (d.GoThruDoor(Direction.EAST))
        {
            ;
        }
        while (d.GoThruDoor(Direction.WEST))
        {
            width++;
        }

        while (d.GoThruDoor(Direction.NORTH))
        {
            ;
        }

        while (d.GoThruDoor(Direction.SOUTH))
        {
            height++;
        }


        return(height * width);
    }
    public static void Main(string[] args)
    {
        Console.WriteLine("====================");
        Console.WriteLine("Rectangular Dungeons");
        Console.WriteLine("====================");
        for (int id = 1; id <= 10; id++)
        {
            RectangularDungeon d = new RectangularDungeon(id, 20, 20);
            long yourAnswer      = solve(d);
            Console.WriteLine("Dungeon # {0,3} |  yourAnswer: {1,4}" +
                              "  correct: {2,3}  numberOfMoves: {3,5}",
                              id, yourAnswer,
                              d.AnswerMatches(yourAnswer) ? "Yes" : "No",
                              d.NumberOfMoves);
        }
        Console.WriteLine();

        Console.WriteLine("===============");
        Console.WriteLine("Jagged Dungeons");
        Console.WriteLine("===============");
        for (int id = 1; id <= 10; id++)
        {
            JaggedDungeon d          = new JaggedDungeon(id, 20, 20);
            long          yourAnswer = solve(d);
            Console.WriteLine("Dungeon # {0,3} |  yourAnswer: {1,4}" +
                              "  correct: {2,3}  numberOfMoves: {3,5}",
                              id, yourAnswer,
                              d.AnswerMatches(yourAnswer) ? "Yes" : "No",
                              d.NumberOfMoves);
        }
        Console.WriteLine();

        Console.Read();

        /*
         * Output de mi solucion:
         *
         * ====================
         * Rectangular Dungeons
         * ====================
         * Dungeon #   1 |  yourAnswer:  221  correct: Yes  numberOfMoves:    39
         * Dungeon #   2 |  yourAnswer:  160  correct: Yes  numberOfMoves:    42
         * Dungeon #   3 |  yourAnswer:  128  correct: Yes  numberOfMoves:    32
         * Dungeon #   4 |  yourAnswer:   96  correct: Yes  numberOfMoves:    22
         * Dungeon #   5 |  yourAnswer:   48  correct: Yes  numberOfMoves:    28
         * Dungeon #   6 |  yourAnswer:   15  correct: Yes  numberOfMoves:    18
         * Dungeon #   7 |  yourAnswer:  270  correct: Yes  numberOfMoves:    62
         * Dungeon #   8 |  yourAnswer:  240  correct: Yes  numberOfMoves:    50
         * Dungeon #   9 |  yourAnswer:  210  correct: Yes  numberOfMoves:    39
         * Dungeon #  10 |  yourAnswer:  154  correct: Yes  numberOfMoves:    40
         *
         * ===============
         * Jagged Dungeons
         * ===============
         * Dungeon #   1 |  yourAnswer:  139  correct: Yes  numberOfMoves:   276
         * Dungeon #   2 |  yourAnswer:   78  correct: Yes  numberOfMoves:   165
         * Dungeon #   3 |  yourAnswer:   25  correct: Yes  numberOfMoves:    59
         * Dungeon #   4 |  yourAnswer:  143  correct: Yes  numberOfMoves:   281
         * Dungeon #   5 |  yourAnswer:   93  correct: Yes  numberOfMoves:   179
         * Dungeon #   6 |  yourAnswer:  110  correct: Yes  numberOfMoves:   214
         * Dungeon #   7 |  yourAnswer:   61  correct: Yes  numberOfMoves:   117
         * Dungeon #   8 |  yourAnswer:   17  correct: Yes  numberOfMoves:    33
         * Dungeon #   9 |  yourAnswer:  157  correct: Yes  numberOfMoves:   306
         * Dungeon #  10 |  yourAnswer:  113  correct: Yes  numberOfMoves:   224
         *
         */
    }
    public static long solve(RectangularDungeon d)
    {
        int habitacion  = 0;
        int habitacion2 = 0;
        int movimiento  = 0;
        int reset       = 0;


        // Obtener Altura
        for (bool movNorte = true; movNorte == true;)
        {
            movNorte = d.GoThruDoor(Direction.NORTH);
            if (movNorte == true)
            {
                habitacion += 1;
            }
        }

        habitacion = habitacion + 1;


        // Obtener Altura
        for (bool movSur = true; movSur == true;)
        {
            movSur = d.GoThruDoor(Direction.SOUTH);
            if (movSur == true)
            {
                habitacion2 += 1;
            }
        }
        habitacion2 = habitacion2 + 1;


        if (habitacion2 >= habitacion)
        {
            movimiento = habitacion2;
        }
        else
        {
            movimiento = habitacion;
        }

        habitacion  = 0;
        habitacion2 = 0;

        for (bool movEste = true; movEste == true;)
        {
            movEste = d.GoThruDoor(Direction.EAST);
            if (movEste == true)
            {
                habitacion += 1;
            }
        }
        habitacion = habitacion + 1;

        for (bool movOeste = true; movOeste == true;)
        {
            movOeste = d.GoThruDoor(Direction.WEST);
            if (movOeste == true)
            {
                habitacion2 += 1;
            }
        }
        habitacion2 = habitacion2 + 1;

        if (habitacion2 >= habitacion)
        {
            reset      = movimiento;
            movimiento = movimiento * habitacion2;

            if (movimiento == 0)
            {
                movimiento = habitacion2;
            }
            if (movimiento == 0)
            {
                movimiento = reset;
            }
        }
        else
        {
            movimiento = movimiento * habitacion;
        }



        // TODO: implementar algoritmo para determinar la cantidad total de
        //       habitaciones existentes en el calabozo tipo matrix rectangular
        // Valor: 4 puntos
        // Restriccion: la cantidad de movimientos de tu solucion no debe
        //              exceder 4 veces el de mi solucion; ver ejemplo en Main
        //              para comparar tus resultados contra los mios

        // Ejemplo de interaccion:
        // d.GoThruDoor(Direction.SOUTH);

        return(movimiento);
    }