Puzzle 15



  • Hallo!

    Kann mir bitte bitte jemand helfen ein Puzzle Programm zu programmieren. Man soll ein Matrix Feld [4][4] erstellen ( also Ziffer 1-15). Der Benutzer muss manuell die Ziffern schieben können (also durch die Tastatureingabe).

    // number_puzzle.c
    // Write a number puzzle program by completing the TO DOs
    // TO DO, optional: created an automatic, intelligent puzzle solver, which solves the puzzle without user intervention.

    #include <stdio.h>

    int main()
    {
    int puzzle[4][4];
    char key; // This holds the current key entered by the player.
    char sorted=0; // This flag marks, if the field is sorted.
    int i, j;

    // Initialize the puzzle, such that the numbers 1 to 15 are randomly distributed in the array.
    // In addition -1 should mark the empty field.

    while(!sorted) {

    /* Output /
    for(i=0; i<4; i++) {
    for(j=0; j<4; j++) {
    printf("%4d ", puzzle[i][j]);
    }
    printf("\n");
    }
    /* TO DO 2: Create a more fancy output, e.g. by creating frames around the numbers
    (Use a special character e.g. a block rather than '
    ')
    (Also, mark the empty field rather than showing -1)

    *********************
    * 1 * 2 * 3 * 4 *
    *********************
    * 5 * 6 * 7 * 8 *
    *********************
    * 9 * 10 * 11 * 12 *
    *********************
    * 13 * 14 * 15 ******
    *********************
    */

    printf("move into direction?");
    key=getch();
    // TO DO 1: get keystroke and move pieces accordingly (if keystroke is valid)

    // TO DO 3: Check, if puzzle is in correct order -> set sorted=1
    }
    }

    Wenn mir jemand helfen könnte, wäre wirklich super, da ich dieses Programm schon am Mo abgeben soll!!!

    Vorab vielen Dank!



  • Fang schon mal mit TO DO 3 an. Dann kann das noch was bis Montag werden.



  • Danke schön, das wäre wirklich seeehr hilfreich von dir!!!



  • Lilly_BN schrieb:

    Danke schön, das wäre wirklich seeehr hilfreich von dir!!!

    Das hast du wohl falsch verstanden. DirkB hat die Anweisung auf dich und nicht auf sich selbst bezogen!



  • Ich hatte bei der Antwort von Lilly_BN Ironie detektiert. Der Detektor war wohl zu fein eingestellt.


Anmelden zum Antworten