Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //----------------------------------------
- //Java:
- Location l = location;
- int x = l.x;
- int y = l.y;
- switch( direction % 8 ) {
- case 0 :
- // North
- y = l.y > 0 ? l.y - 1 : l.y;
- break;
- case 1 :
- // South
- y = l.y < ( maze.getHeight( ) - 1 ) ? l.y + 1 : l.y;
- break;
- case 2 :
- // West
- x = l.x > 0 ? l.x - 1 : l.x;
- break;
- case 3 :
- // East
- x = l.x < ( maze.getWidth( ) - 1 ) ? l.x + 1 : l.x;
- break;
- case 4 :
- // North-east
- x = l.x < ( maze.getWidth( ) - 1 ) ? l.x + 1 : l.x;
- y = l.y < ( maze.getHeight( ) - 1 ) ? l.y + 1 : l.y;
- break;
- case 5 :
- // North-west
- x = l.x > 0 ? l.x - 1 : 0;
- y = l.y < ( maze.getHeight( ) - 1 ) ? l.y + 1 : l.y;
- break;
- case 6 :
- // South-west
- x = l.x > 0 ? l.x - 1 : l.x;
- y = l.y > 0 ? l.y - 1 : l.y;
- break;
- case 7 :
- // South-east
- x = l.x < ( maze.getWidth( ) - 1 ) ? l.x + 1 : l.x;
- y = l.y > 0 ? l.y - 1 : l.y;
- break;
- default :
- throw new RuntimeException( "This is a bug" );
- }
- Location newLocation = new Location( x,y );
- //----------------------------------------
- //F#:
- let l = location
- let newLocation =
- match direction % 8 with
- | 0 -> (fst l), (snd l)-1 //North
- | 1 -> (fst l), (snd l)+1 //South
- | 2 -> (fst l)-1, (snd l) //West
- | 3 -> (fst l)+1, (snd l) //East
- | 4 -> (fst l)+1, (snd l)-1 //North-East
- | 5 -> (fst l)-1, (snd l)-1 //North-West
- | 6 -> (fst l)+1, (snd l)+1 //South-East
- | 7 -> (fst l)-1, (snd l)+1 //South-West
- | _ -> failwith("This is a bug")
- //----------------------------------------
- //
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement