Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Mar 11th, 2012  |  syntax: None  |  size: 1.66 KB  |  hits: 14  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. /**
  2.    * metodo para o robot explorar o mundo.
  3.    */
  4.       public void mapWorld( )
  5.       {
  6.       // definir dados
  7.          int avenues,
  8.             streets;
  9.          int x, y;
  10.          int beepers = 0;
  11.       // obter o tamanho do mundo
  12.          avenues = World.numberOfAvenues( );
  13.          streets = World.numberOfStreets( );
  14.       // informar o tamanho do mundo
  15.          IO.println ( "World is "
  16.             + avenues + "x" + streets );
  17.       // repetir para todas as posicoes no mundo
  18.          for ( x=0; x<avenues-1; x=x+1 )
  19.          {
  20.             for ( y=0; y<streets-1; y=y+1 )
  21.             {
  22.             // mover para a proxima posicao
  23.                move( );
  24.                
  25.             // se proximo a um marcador
  26.                if ( nextToABeeper( ) )
  27.                {
  28.                // encontrado mais um marcador
  29.                   beepers = beepers + 1;
  30.                 //se proximo a um marcador
  31.                   if ( nextToABeeper( ) )
  32.                   {
  33.                   // informar marcador nesta posicao
  34.                      IO.println ( "Beeper at ("+x+","+y+")" );
  35.                   } // end if  
  36.                } // end if
  37.             } // end for (y)
  38.             if ( x % 2 == 0 )
  39.             {
  40.                turnLeft( );
  41.                move( );
  42.                turnLeft( );
  43.             }
  44.             else
  45.             {
  46.                turnRight( );
  47.                move( );
  48.                turnRight( );
  49.             } // end if
  50.          } // end for (x)
  51.       // informar quantos marcadores encontrados
  52.          IO.println ( "Found " + beepers );
  53.       } // end mapWorld( )