Advertisement
Guest User

Untitled

a guest
Jan 13th, 2012
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. //----------------------------------------------
  2. //Java:
  3. //Onko tässä jonkinlainen kaikkien eläinten yhteinen tanssikuvio:
  4.  
  5. int direction = random.nextInt( 8 ); //arvotaan luku alle 8
  6. for( int i = 0; i < 4; i++, direction++ ) { //lisätään arvottua lukua luupissa neljä kertaa
  7. switch( direction % 8 ) { // Esim. east jälkeen tulee aina north-east?
  8.  
  9. //...
  10. Location currLocation = location; //temp-lokaatio
  11. location = newLocation; //uusi sijoitetaan olemassaolevaan
  12. if( maze.moveTo( this,currLocation,newLocation ) ) { //tehdään jotain
  13. location = newLocation; //ja tässä uudestaan
  14. break;
  15. }
  16. else {
  17. // If movement fails
  18. location = currLocation; //tai takas vanhaan
  19. }
  20. }
  21.  
  22. //----------------------------------------------
  23. //F#
  24.  
  25. // LINQ-listakäsittely:
  26.  
  27. let elossaHiiret = System.Linq.Enumerable.Except(hiirikoordinaatit, kissakoordinaatit) |> Seq.toList
  28.  
  29. // ja lisäksi F#:lla on kovin tehokkaat listojenkäsittelyfunktiot itsestään, esim:
  30.  
  31. let rooms = Array2D.init 10 10 (fun i j -> [i; j])
  32.  
  33. //----------------------------------------------
  34. //Java
  35.  
  36. //Tämähän on perus table-lookup:
  37.  
  38. rooms = new HashMap<Location,Room>( );
  39. for( int x = 0; x < width; x++ )
  40. for( int y = 0; y < height; y++ )
  41. rooms.put( new Location( x,y ),new Room( new Location( x,y ) ) );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement