Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (* need check is out before *)
- let is_ball_in_view move b = let ballPos = position_of_ball b in
- let x = Position.proj_x ballPos and y = Position.proj_y ballPos and movePos = move.movePos in
- let mX = Position.proj_x movePos and mY = Position.proj_y movePos in
- match move.moveDir with
- | Up -> x = mX && y > mY
- | Down -> x = mX && y < mY
- | Right -> y = mY && x > mX
- | Left -> y = mY && x < mX
- | None -> failwith "is_ball_in_view None found"
- (* was about to make a graph size linearity but can be constant 8) *)
- let is_a_ball_in_view g move = List.exists (is_ball_in_view move) (get_balls g)
- let is_move_correct g move =
- let nextPos = next move in
- is_ball g move.movePos && not (is_ball g nextPos) && is_a_ball_in_view g {movePos = nextPos; moveDir = move.moveDir}
- let is_move_correct_dir g b dir = is_move_correct g (make_move b dir)
- (* the following function isn't interesting because it just gives a boolean while we are waiting a direction instead *)
- let is_move_correct g b =
- 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
- let get_move_correct g b =
- if is_move_correct_dir g b Up then Up
- else
- (
- if is_move_correct_dir g b Down then Down
- else
- (
- if is_move_correct_dir g b Left then Left
- else
- (
- if is_move_correct_dir g b Right then Right
- else None
- )
- )
- )
- (* how to simplify ? *)
- (* 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 *)
- let moves g =
- let rec aux ballList acc =
- match ballList with
- | t::q ->
- let eDir = get_move_correct g t in
- (if eDir <> None then (aux q ((make_move t eDir)::acc)) else aux q acc)
- | _ -> acc
- in aux (get_balls g) []
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement