Advertisement
Benjamin_Loison

Flint

Oct 24th, 2020
4,644
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
OCaml 1.99 KB | None | 0 0
  1. (* need check is out before *)
  2. let is_ball_in_view move b = let ballPos = position_of_ball b in
  3.     let x = Position.proj_x ballPos and y = Position.proj_y ballPos and movePos = move.movePos in
  4.     let mX = Position.proj_x movePos and mY = Position.proj_y movePos in
  5.     match move.moveDir with
  6.     | Up -> x = mX && y > mY
  7.     | Down -> x = mX && y < mY
  8.     | Right -> y = mY && x > mX
  9.     | Left -> y = mY && x < mX
  10.     | None -> failwith "is_ball_in_view None found"
  11.  
  12. (* was about to make a graph size linearity but can be constant 8) *)
  13. let is_a_ball_in_view g move = List.exists (is_ball_in_view move) (get_balls g)
  14.  
  15. let is_move_correct g move =
  16.     let nextPos = next move in
  17.     is_ball g move.movePos && not (is_ball g nextPos) && is_a_ball_in_view g {movePos = nextPos; moveDir = move.moveDir}
  18.  
  19. let is_move_correct_dir g b dir = is_move_correct g (make_move b dir)
  20.  
  21. (* the following function isn't interesting because it just gives a boolean while we are waiting a direction instead *)
  22. let is_move_correct g b =
  23.     is_move_correct_dir g b Up || is_move_correct_dir g b Down || is_move_correct_dir g b Left || is_move_correct_dir g b Right
  24.  
  25. let get_move_correct g b =
  26.     if is_move_correct_dir g b Up then Up
  27.     else
  28.     (
  29.         if is_move_correct_dir g b Down then Down
  30.         else
  31.         (
  32.             if is_move_correct_dir g b Left then Left
  33.             else
  34.             (
  35.                 if is_move_correct_dir g b Right then Right
  36.                 else None
  37.             )
  38.         )
  39.     )
  40.     (* how to simplify ? *)
  41.  
  42. (* ok on veut de la récursivité mais l'impératif du balayage de matrice s'impose là... - euh en fait en balayant directement sur les boules c'est plus efficace *)
  43. let moves g =
  44.     let rec aux ballList acc =
  45.         match ballList with
  46.         | t::q ->
  47.                 let eDir = get_move_correct g t in
  48.                     (if eDir <> None then (aux q ((make_move t eDir)::acc)) else aux q acc)
  49.         | _ -> acc
  50.     in aux (get_balls g) []
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement