Advertisement
OedipusPrime

Untitled

Sep 13th, 2013
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 1.59 KB | None | 0 0
  1.     let pacManVisible options lineOfSight =
  2.         let creaturesInDirection (directionVector: (TileContent * Creature list) list ) = directionVector |> List.collect snd
  3.         let containsPacMan (creatures: Creature list) = match List.tryFind (fun c -> match c with
  4.                                                                                      | int -> true
  5.                                                                                      | _ -> false) creatures with
  6.                                                         | Some value -> true
  7.                                                         | None -> false
  8.  
  9.         if(Set.contains Up options && lineOfSight.Up |> creaturesInDirection |> containsPacMan) then Some Up
  10.         else if(Set.contains Left options && lineOfSight.Left |> creaturesInDirection |> containsPacMan) then Some Left
  11.         else if(Set.contains Down options && lineOfSight.Down |> creaturesInDirection |> containsPacMan) then Some Down
  12.         else if(Set.contains Right options && lineOfSight.Right |> creaturesInDirection |> containsPacMan) then Some Right
  13.         else None
  14.  
  15.     let decision (current: Move) (lineOfSight: Sight) (choices: Move Set) =
  16.         let restricted =
  17.             choices
  18.             |> Set.filter (fun c -> not (c = backwards current))
  19.         let options = if (restricted |> Set.count > 0)
  20.                       then restricted
  21.                       else choices
  22.         let pacDirection = pacManVisible options lineOfSight
  23.         match pacDirection with
  24.               | Some move -> move
  25.               | None -> randomMove options
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement