Durchsuchen der Umgebung II

 [Vorherige Seite]  [Inhaltsverzeichnis]  [Nächste Seite]  [Nächstes Kapitel]

/*
 * sucht nach einem Nachbarfeld zu [zeile][spalte] mit
 * der Belegung `feldtyp';
 * falls erfolgreich (Return-Wert TRUE),
 * wird in x und y die Nachbarposition abgelegt
 */
int suche(int zeile, int spalte, char feldtyp, int *x, int *y)
{  int anzahl;    /* Anzahl der Moeglichkeiten */
   int i;
   int nx[RICHTUNGEN], ny[RICHTUNGEN];  /* Nachbarfelder */

   anzahl = 0;
   anzahl += teste(zeile-1, spalte  , feldtyp, nx, ny, anzahl);
   anzahl += teste(zeile  , spalte-1, feldtyp, nx, ny, anzahl);
   anzahl += teste(zeile  , spalte+1, feldtyp, nx, ny, anzahl);
   anzahl += teste(zeile+1, spalte  , feldtyp, nx, ny, anzahl);

   if (anzahl) {
      i = random(0, anzahl-1);
      * x = nx[i];
      * y = ny[i];
      return TRUE;
   } else
      return FALSE;
}

*suche geht alle Nachbarfelder durch und sucht ein passendes per Zufall aus.
 
*Bei Mißerfolg wird FALSE zurückgeliefert.
 

 [Vorherige Seite]  [Inhaltsverzeichnis]  [Nächste Seite]  [Nächstes Kapitel]
Copyright © 1998 Andreas Borchert, in HTML konvertiert am 01.12.1998