A PHP Error was encountered

Severity: 8192

Message: strpos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior

Filename: database/DB_driver.php

Line Number: 1876

A PHP Error was encountered

Severity: 8192

Message: strpos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior

Filename: database/DB_driver.php

Line Number: 1876

A PHP Error was encountered

Severity: 8192

Message: strpos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior

Filename: database/DB_driver.php

Line Number: 1876

A PHP Error was encountered

Severity: 8192

Message: strpos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior

Filename: database/DB_driver.php

Line Number: 1876

A PHP Error was encountered

Severity: 8192

Message: strpos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior

Filename: database/DB_driver.php

Line Number: 1876

A PHP Error was encountered

Severity: 8192

Message: strpos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior

Filename: database/DB_driver.php

Line Number: 1876

A PHP Error was encountered

Severity: 8192

Message: strpos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior

Filename: database/DB_driver.php

Line Number: 1876

A PHP Error was encountered

Severity: 8192

Message: strpos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior

Filename: database/DB_driver.php

Line Number: 1876

A PHP Error was encountered

Severity: 8192

Message: strpos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior

Filename: database/DB_driver.php

Line Number: 1876

A PHP Error was encountered

Severity: 8192

Message: strpos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior

Filename: database/DB_driver.php

Line Number: 1876

A PHP Error was encountered

Severity: 8192

Message: Function create_function() is deprecated

Filename: geshi/geshi.php

Line Number: 4751

A PHP Error was encountered

Severity: 8192

Message: strpos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior

Filename: database/DB_driver.php

Line Number: 1876

A PHP Error was encountered

Severity: 8192

Message: strpos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior

Filename: database/DB_driver.php

Line Number: 1876

A PHP Error was encountered

Severity: 8192

Message: strpos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior

Filename: database/DB_driver.php

Line Number: 1876

A PHP Error was encountered

Severity: 8192

Message: strpos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior

Filename: database/DB_driver.php

Line Number: 1876

A PHP Error was encountered

Severity: 8192

Message: strpos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior

Filename: database/DB_driver.php

Line Number: 1876

Robo6 - mcpaste

Robo6

Von Mc, 9 Jahre vorher, geschrieben in C++, aufgerufen 1'437 mal.
URL https://mcpaste.de/view/1f267a97 Einbetten
Paste herunterladen oder Rohtext anzeigen
  1. #include <windows.h>
  2. #include <stdio.h>
  3. #include <queue>
  4.  
  5. /*
  6.  *  In der Cell Strucktur werden Ergebnisse aus dem Algorithmus gespeichert
  7.  */
  8. struct Cell
  9. {
  10.     bool bMarked;   // Zeigt an, ob das Feld schon besucht wurde ( ture = besucht )
  11.     int  nLastX;    // Die X Koordinate des vorherigen Feldes ( -1 = kein vorheriges Feld )
  12.     int  nLastY;    // Die Y Koordinate des vorherigen Feldes
  13.  
  14.         Cell(){
  15.                 this->bMarked = false;
  16.                 this->nLastX = -1;
  17.                 this->nLastY = -1;
  18.         }
  19. };
  20.  
  21. /*
  22.  *  Die Coordinate Strucktur dient der
  23.  */
  24. struct Coordinate
  25. {
  26.     int x, y;
  27. };
  28.  
  29. // Uninteressant
  30. bool operator<(const Coordinate c1, const Coordinate c2) {
  31.     return false;
  32. }
  33.  
  34. // Uninteressant
  35. bool operator==(const Coordinate c1, const Coordinate c2) {
  36.     return false;
  37. }
  38.  
  39. /*
  40.  *  In dieser Tabelle steht die Reihenfolge in der die Umliegenden
  41.  *  Felder abgearbeitet werden sollen
  42.  */
  43. const int DirTable[8][2] = {
  44. {  0, -1},  // oben
  45. {  1,  0},  // rechts
  46. {  0,  1},  // unten
  47. { -1, 0},  // links
  48. {  1, -1},  // rechts-oben
  49. {  1,  1},  // rechts-unten
  50. { -1,  1},  // links-unten
  51. { -1, -1} };// links-oben
  52.  
  53.  
  54. // Globale Variablen
  55. int heigth;  // Hoehe des Konfigurationsraums
  56. int width;   // Breite des Konfigurationsraums
  57.  
  58. BYTE **cspace;  // cspace[i][j] gibt die "Farbe" des Konfigurationsraums an
  59.                 // Die Farben selbst sind in der Funktion SaveAsBitmap als
  60.                 // Palette definiert. z.B. 1 = Weiss, 2 = Rot, usw. ( siehe unten)
  61.  
  62. Cell **aCells;  // In diesem 2D Feld werden die Ergebisse des Algorithmus abgelegt
  63.  
  64. // Funktionsprototypen:
  65. bool LoadFromBitmap( char *szFile, BYTE ***array, int *width, int *heigth );
  66. bool SaveAsBitmap( char *szFile, BYTE **array, int width, int heigth );
  67. bool FindPath( int nStartX, int nStartY, int nGoalX, int nGoalY );
  68. void ClearCells();
  69.  
  70. /*
  71.  *  main
  72.  */
  73. int main()
  74. {
  75.     int x, y;
  76.  
  77.     // Laden des Konfigurationsraums
  78.     if( !LoadFromBitmap( "cspace.bmp", &cspace, &width, &heigth ) )
  79.         return -1;
  80.  
  81.     // Zellenarray allokieren ( dynamisch auf dem Heap )
  82.     aCells = new Cell*[heigth];
  83.     for( y=0; y<heigth; y++ )
  84.         aCells[y] = new Cell[width];
  85.  
  86.     // Startposition
  87.     int nStartX = 100;
  88.     int nStartY = 300;
  89.  
  90.     // Zielposition
  91.     int nGoalX = 340;
  92.     int nGoalY = 20;
  93.  
  94.     DWORD dwStart = GetTickCount();
  95.  
  96.     // Pfad suchen
  97.     bool bFound = FindPath( nStartX, nStartY, nGoalX, nGoalY );
  98.  
  99.     DWORD dwElapsed = GetTickCount() - dwStart;
  100.     printf( "Die Suche dauerete: %d ms\nErgebnis:\n", dwElapsed );
  101.  
  102.     // �berpr�fen ob ein Pfad gefunden wurde
  103.     if( bFound )
  104.     {
  105.         printf( "Pfad gefunden in %d ms.\n", dwElapsed );
  106.  
  107.         // Den Pfad vom Ziel zum Start zur�ckgehen und den Pfad markieren
  108.         x = nGoalX;
  109.         y = nGoalY;
  110.         while( aCells[y][x].nLastX != -1 )  // Bei -1 sind wir am Start
  111.         {
  112.             cspace[y][x] = 255;         // Schwarzes Pixel setzen
  113.             Cell cell = aCells[y][x];
  114.             x = cell.nLastX;
  115.             y = cell.nLastY;
  116.         }
  117.  
  118.         // Bild ausgeben, so das man den Pfad sehen kann
  119.         SaveAsBitmap( "csp_path.bmp", cspace, width, heigth );
  120.     }
  121.     else
  122.     {
  123.         printf( "Keinen Pfad gefunden!\n" );
  124.     }
  125.  
  126.     // Cleanup
  127.     for( y=0; y<heigth; y++ )   // Alle Cells vom Heap l�schen
  128.         delete [] aCells[y];
  129.     delete [] aCells;
  130.         system("pause");
  131.     return 0;
  132. }
  133.  
  134. /*
  135.  *  FindPath - Breadth-First (Breitensuche)
  136.  *  Algorithmus zum finden eines Pfades vom Start zum Endpunkt ( goal )
  137.  */
  138. bool FindPath( int nStartX, int nStartY, int nGoalX, int nGoalY )
  139. {
  140.     printf( "Suche Pfad von %d/%d nach %d/%d\n", nStartX, nStartY, nGoalX, nGoalY );
  141.  
  142.     //  ToDo: Zellen initialiseren...
  143.  
  144.     // Queue erzeugen ( aus der STL - Standard Template Library - kommt mit C++ )
  145.     std::queue<Coordinate> queue;
  146.  
  147.     // Startzelle:
  148.     Coordinate c;
  149.     c.x = nStartX;
  150.     c.y = nStartY;
  151.  
  152.     //  Folgende Zeilen demonstrieren die Manipulation von Queues ( Warteschlange )
  153.     //  Einfach auskommentieren und testen
  154.  
  155. /*  printf("Queue leer ? : %d\n", queue.empty());   // Am Anfang ist die Queue leer
  156.     queue.push( c );                                // Element in die Queue anstellen
  157.     printf("Queue leer ? : %d\n", queue.empty());   // Jetzt sollte die Queue nicht mehr leer sein
  158.  
  159.     printf( "Elemente in Queue: %d\n", queue.size() );  // Anzahl Elemente in der Queue
  160.  
  161.     Coordinate test = queue.front();           // front() gibt das forderste Element in der Queue zur�ck,
  162.     printf("x: %d, y: %d\n", test.x, test.y ); // jedoch wird da Element dadurch nicht entfernt!
  163.  
  164.     queue.pop();    // Entfernt das erste Element aus der Queue
  165.  
  166.     printf("Queue leer ? : %d\n", queue.empty()); // Nun sollte die Queue wieder leer sein
  167. */
  168.  
  169.     //  ToDo: Ihr  Algorithmus
  170.     //  ....
  171.  
  172.         queue.push(c);
  173.         aCells[c.y][c.x].bMarked = true;
  174.     while( !queue.empty() ) // Solange bis keine Elemente mehr in der Queue sind
  175.     {
  176.                 Coordinate currentCell = queue.front();
  177.                 queue.pop();
  178.                 if (currentCell.x == nGoalX && currentCell.y == nGoalY){
  179.                         return true;
  180.                 }
  181.                 else{
  182.                         for (unsigned int i = 0; i < 8; i++){
  183.                                 Coordinate newCell = currentCell;
  184.                                 newCell.x += DirTable[i][1];            // Offset auf die Base Adress rechnen, um zur umliegenden Zelle zu kommen
  185.                                 newCell.y += DirTable[i][0];
  186.  
  187.                                 int nX = newCell.x;
  188.                                 int nY = newCell.y;
  189.                                 if ((nX < heigth && nY < width) && (nX && nY)){ // Die Zelle liegt noch im Konfigurationsraum
  190.                                         if (!aCells[nY][nX].bMarked){   // Wenn die Zelle noch nicht markiert ist
  191.                                                 if (!cspace[nY][nX]){           // Und keine Kollision stattfindet...
  192.                                                         aCells[nY][nX].bMarked = true;  // aktuelle Zelle als vorg�nger setzten
  193.                                                         aCells[nY][nX].nLastX = currentCell.x;
  194.                                                         aCells[nY][nX].nLastY = currentCell.y;
  195.                                                         queue.push(newCell);
  196.                                                 }
  197.                                         }
  198.                                 }
  199.                         }
  200.                 }
  201.     }
  202.  
  203.     return false;   // Default Return
  204. }
  205.  
  206.  
  207. /*
  208.  *  ClearCells()
  209.  *  Setzt alle Zellen auf die Initialwerte zur�ck
  210.  */
  211. void ClearCells()
  212. {
  213.     // Zellen zur�cksetzen
  214.     for( int y=0; y<heigth; y++)
  215.     {
  216.         for( int x=0; x<width; x++)
  217.         {
  218.             aCells[y][x].bMarked = false;   // Nicht besucht
  219.             aCells[y][x].nLastX = -1;       // Keine vorherige Zelle
  220.             aCells[y][x].nLastY = -1;
  221.         }
  222.     }
  223. }
  224.  
  225. /*
  226.  *  LoadFromBitmap
  227.  *  L�d ein Konfigurationsraum aus einem Bitmap
  228.  *  Dabei muss das Bild 8 Bit/Pixel haben
  229.  */
  230. bool LoadFromBitmap( char *szFile, BYTE ***array, int *width, int *heigth )
  231. {
  232.     int x, y;
  233.  
  234.     FILE *pFile;
  235.     if ( fopen_s(&pFile, szFile, "rb") )
  236.     {
  237.         printf( "Konnte Datei '%s' nicht oeffnen.\n", szFile );
  238.         return false;
  239.     }
  240.  
  241.     BITMAPFILEHEADER bmpFileHeader;
  242.     BITMAPINFOHEADER bmpInfoHeader;
  243.  
  244.     fread( &bmpFileHeader, sizeof( BITMAPFILEHEADER ), 1, pFile );
  245.     fread( &bmpInfoHeader, sizeof( BITMAPINFOHEADER ), 1, pFile );
  246.  
  247.     // Breite und H�he kopieren
  248.     int w = (*width)  = bmpInfoHeader.biWidth;
  249.     int h = (*heigth) = bmpInfoHeader.biHeight;
  250.  
  251.     // Speicher allokieren ( dynamisch auf dem heap )
  252.     (*array) = new BYTE*[h];
  253.     for( y=0; y<h; y++ )
  254.         (*array)[y] = new BYTE[w];
  255.  
  256.     // Zum Anfang der Bits springen
  257.     fseek( pFile, bmpFileHeader.bfOffBits, SEEK_SET );
  258.  
  259.     int n =0;
  260.     for( y=h-1; y>=0; y-- )
  261.     {
  262.         for( x=0; x<w; x++ )
  263.         {
  264.             if( feof( pFile) )  // Nicht gut
  265.                 break;
  266.  
  267.             BYTE c;
  268.             fread( &c, 1, sizeof(BYTE), pFile );
  269.             (*array)[y][x] = c;
  270.             n++;
  271.         }
  272.     }
  273.  
  274.     fclose(pFile);
  275.  
  276.     return true;
  277. }
  278.  
  279. /*
  280.  *  SaveAsBitmap
  281.  *  Speichert den Konfigurationsraum als Bitmap.
  282.  *  Parameter:
  283.  *  szFile  -   Dateiname
  284.  *  array   -   Das 2D Array mit dem Konfigurationsraum
  285.  *  width   -   Breite des Konfigurationsraum
  286.  *  height  -   H�he des Konfigrationsraum
  287.  */
  288. bool SaveAsBitmap( char *szFile, BYTE **array, int width, int heigth )
  289. {
  290.     BITMAPFILEHEADER bmpFileHeader;
  291.     bmpFileHeader.bfType = *((int*)("BM"));     // Muss BM sein
  292.     bmpFileHeader.bfSize = 0;           // Gr��e der Bitmap Datei
  293.     bmpFileHeader.bfReserved1 = 0;      // Muss 0 sein
  294.     bmpFileHeader.bfReserved2 = 0;      // Muss 0 sein
  295.     bmpFileHeader.bfOffBits = 0;        // Offset, in Bytes, zwischen BITMAPFILEHEADE und den Bits
  296.  
  297.  
  298.     BITMAPINFOHEADER bmpInfoHeader;
  299.     bmpInfoHeader.biSize = sizeof( BITMAPINFOHEADER );
  300.     bmpInfoHeader.biWidth = width;
  301.     bmpInfoHeader.biHeight = heigth;
  302.     bmpInfoHeader.biPlanes = 1;
  303.     bmpInfoHeader.biBitCount = 8;
  304.     bmpInfoHeader.biCompression = BI_RGB;
  305.     bmpInfoHeader.biSizeImage = width * heigth * 1;
  306.     bmpInfoHeader.biXPelsPerMeter = 2834;
  307.     bmpInfoHeader.biYPelsPerMeter = 2834;
  308.     bmpInfoHeader.biClrUsed = 256;
  309.     bmpInfoHeader.biClrImportant = 256;
  310.  
  311.     FILE *pFile;
  312.     if ( fopen_s( &pFile, szFile, "wb" ) )
  313.     {
  314.         printf( "Konnte Datei '%s' nicht erzeugen.\n", szFile );
  315.         return false;
  316.     }
  317.  
  318.     fwrite( &bmpFileHeader, sizeof( BITMAPFILEHEADER ), 1, pFile );
  319.     fwrite( &bmpInfoHeader, sizeof( BITMAPINFOHEADER ), 1, pFile );
  320.  
  321.     // Farbpalette zum Bild hinzuf�gen
  322.     static RGBQUAD colortable[] =
  323.     {
  324.         { 255, 255, 255, 0},
  325.  
  326.         { 255,   0,   0, 0},    // Rot
  327.         {   0, 255,   0, 0},    // Gr�n
  328.         {   0,   0, 255, 0},    // Blau
  329.  
  330.         { 255, 255,   0, 0},    // Gelb
  331.         { 255,   0, 255, 0},    // Magenta
  332.         {   0, 255, 255, 0},    // Cyan
  333.  
  334.         { 255, 128,   0, 0},    // Oragne
  335.         { 255,   0, 128, 0},    // Weinrot
  336.         {   0, 255, 128, 0},    // Hell Gr�n
  337.         { 128, 255,   0, 0}     // Gift Gr�n
  338.  
  339.         // Wenn die Farben nicht reichen, hier neue hinzuf�gen
  340.     };
  341.  
  342.     int nCol = sizeof(colortable) / sizeof(RGBQUAD);
  343.     fwrite( colortable, sizeof(RGBQUAD), sizeof(colortable), pFile );
  344.  
  345.     // Alle restlichen Farben auf Schwarz setzen
  346.     for( int i=nCol; i<256; i++ )
  347.     {
  348.         RGBQUAD  rgb;
  349.         rgb.rgbRed   = 0;
  350.         rgb.rgbGreen = 0;
  351.         rgb.rgbBlue  = 0;
  352.         rgb.rgbReserved = 0;
  353.         fwrite( &rgb, sizeof( RGBQUAD), 1, pFile );
  354.     }
  355.  
  356.     // Bits schreiben
  357.     bmpFileHeader.bfOffBits = ftell( pFile );
  358.     for( int y=heigth-1; y>=0; y-- )
  359.     {
  360.         for( int x=0; x<width; x++ )
  361.         {
  362.             putc( array[y][x], pFile );
  363.         }
  364.     }
  365.  
  366.     bmpFileHeader.bfSize = ftell( pFile );
  367.  
  368.     // File Header nochmal mit neuen Werten �berschreiben
  369.     fseek( pFile, 0L, SEEK_SET );
  370.     fwrite( &bmpFileHeader, sizeof( BITMAPFILEHEADER ), 1, pFile );
  371.  
  372.     fclose(pFile);
  373.  
  374.     return true;
  375. }

Antwort auf "Robo6"

Hier kannst Du auf den Paste von oben antworten

A PHP Error was encountered

Severity: 8192

Message: strpos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior

Filename: database/DB_driver.php

Line Number: 1876