Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //----------------------------------------------
- //Java:
- //Onko tässä jonkinlainen kaikkien eläinten yhteinen tanssikuvio:
- int direction = random.nextInt( 8 ); //arvotaan luku alle 8
- for( int i = 0; i < 4; i++, direction++ ) { //lisätään arvottua lukua luupissa neljä kertaa
- switch( direction % 8 ) { // Esim. east jälkeen tulee aina north-east?
- //...
- Location currLocation = location; //temp-lokaatio
- location = newLocation; //uusi sijoitetaan olemassaolevaan
- if( maze.moveTo( this,currLocation,newLocation ) ) { //tehdään jotain
- location = newLocation; //ja tässä uudestaan
- break;
- }
- else {
- // If movement fails
- location = currLocation; //tai takas vanhaan
- }
- }
- //----------------------------------------------
- //F#
- // LINQ-listakäsittely:
- let elossaHiiret = System.Linq.Enumerable.Except(hiirikoordinaatit, kissakoordinaatit) |> Seq.toList
- // ja lisäksi F#:lla on kovin tehokkaat listojenkäsittelyfunktiot itsestään, esim:
- let rooms = Array2D.init 10 10 (fun i j -> [i; j])
- //----------------------------------------------
- //Java
- //Tämähän on perus table-lookup:
- rooms = new HashMap<Location,Room>( );
- for( int x = 0; x < width; x++ )
- for( int y = 0; y < height; y++ )
- rooms.put( new Location( x,y ),new Room( new Location( x,y ) ) );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement