vendredi 9 juillet 2010

test

 

#light

namespace ViLogo

 
module World =

   
open System

   
type World =
        {
            pos : (float * float)
            angle : float
            penDown : bool
        }
   
with 
       
static member init = {pos = (0.0, 0.0); angle = Math.PI/2.0; penDown = true}

   
type Command = 
        |Forward
of float
        |Turn
of float
        |Zero
        |Angle
of float
        |Pos
of (float * float)
        |Erase
        |PenDown
of bool

   
type CommandResult = int

   
let executeCommand command world = 
       
match command with
        |Forward d
->   let x = fst world.pos + d * Math.Cos(world.angle)
                       
let y = snd world.pos + d * Math.Sin(world.angle)
                        None, {world
with pos = (x,y)}
        |Turn a
->  None, {world with angle = world.angle + a*Math.PI/180.0}
        |Zero
-> None, World.init
        |Angle a
->  None, {world with angle = a*Math.PI/180.0}
        |Pos (x, y)
-> None, {world with pos = (x,y)}
        |Erase
-> None, world
        |PenDown b
-> None, {world with penDown = b}

        

Aucun commentaire: