experimental add for pathfinding
This commit is contained in:
parent
832384634e
commit
24eebff64a
42
again.ml
42
again.ml
|
@ -2,8 +2,8 @@
|
|||
TODO :
|
||||
- deal with double bombing (DONE)
|
||||
- well shit ==> dash
|
||||
- deeper analysis on pathfinfing (~DONE)
|
||||
- correct fatal bug on player death
|
||||
- deeper analysis on pathfinfing (1/2)
|
||||
- correct fatal bug on player death (DONE)
|
||||
*)
|
||||
(* ---------------------------------------------------------------------------------------------------------------------------------------------------- *)
|
||||
(* ---------------------------------------------------------------------------------------------------------------------------------------------------- *)
|
||||
|
@ -493,6 +493,7 @@ let amt_free_adj_spaces (gd : game_data) (x : int) (y : int) =
|
|||
order ;;
|
||||
|
||||
let max_depth = 4 ;;
|
||||
let max_spacing = 3 ;;
|
||||
let is_player_nearby (gd : game_data) =
|
||||
let pid = gd.player_id in
|
||||
let lines = Array.length gd.laby
|
||||
|
@ -552,6 +553,38 @@ let is_dead_end (gd : game_data) (xstart : int) (ystart : int) (xban : int) (yba
|
|||
| ReturnBool b -> b
|
||||
end ;;
|
||||
|
||||
let has_multiple_escapes (gd : game_data) (xstart : int) (ystart : int) (xban : int) (yban : int) =
|
||||
if not (is_player_nearby gd) then
|
||||
false (* if no one is nearby, it's safe to go there (hopefully) *)
|
||||
else begin
|
||||
let n_34 = ref 0 in
|
||||
let lines = Array.length gd.laby
|
||||
and cols = Array.length gd.laby.(0) in
|
||||
let visited = Hashtbl.create 50 in
|
||||
Hashtbl.add visited (xban, yban) 1 ;
|
||||
let rec aux x y =
|
||||
if Hashtbl.find_opt visited (x, y) = None then begin
|
||||
Hashtbl.add visited (x, y) 1;
|
||||
if (is_valid x y lines cols && gd.laby.(x).(y) <> 1 && gd.laby.(x).(y) <> 2 && not (Array.fold_left (fun acc (b : bomb) -> acc || (b.xy.x = x && b.xy.y = y)) false gd.bombs)) then begin
|
||||
match (amt_free_adj_spaces gd x y) with
|
||||
| 0 -> failwith "wtf john"
|
||||
| 1 | 2 -> for dir = 0 to 3 do
|
||||
aux (x + fst order.(dir)) (y + snd order.(dir))
|
||||
done
|
||||
| _ -> if !n_34 >= 1 then raise (ReturnBool false) else incr n_34
|
||||
end
|
||||
end
|
||||
in
|
||||
try
|
||||
aux xstart ystart;
|
||||
true ;
|
||||
with
|
||||
| ReturnBool b -> b
|
||||
end ;;
|
||||
|
||||
let advanced_pathfind (gd : game_data) (xstart : int) (ystart : int) (xban : int) (yban : int) =
|
||||
(is_dead_end gd xstart ystart xban yban) && (has_multiple_escapes gd xstart ystart xban yban) ;;
|
||||
|
||||
let reverse_simulate_bomb (dgs : danger_map) (save : (int * int, float) Hashtbl.t) =
|
||||
Hashtbl.iter
|
||||
(fun (x, y) dt ->
|
||||
|
@ -681,7 +714,7 @@ let bfs_for_crate (gd : game_data) (dgs : danger_map) (x0 : int) (y0 : int) (sti
|
|||
(ct >= stime +. (float_of_int minDist) *. interval) && (* not too deep *)
|
||||
(is_empty_lst dgs.explosionTimes.(x).(y)) && (* safe *)
|
||||
(not (is_player_nearby gd && amt_free_adj_spaces gd x y = 1)) && (* is not a dead-end (==> ez kill) *)
|
||||
(not placedBomb || direction = 4 || not (is_dead_end gd (gd.players.(pid).xy.x + fst order.(direction)) (gd.players.(pid).xy.y + snd order.(direction)) gd.players.(pid).xy.x gd.players.(pid).xy.y)) &&
|
||||
(not placedBomb || direction = 4 || not (advanced_pathfind gd (gd.players.(pid).xy.x + fst order.(direction)) (gd.players.(pid).xy.y + snd order.(direction)) gd.players.(pid).xy.x gd.players.(pid).xy.y)) &&
|
||||
(not searchCrate || (sees_a_crate gd dgs x y && not dgs.explodedCrates.(x).(y))) && (* sees a crate *)
|
||||
(not searchBonus || dgs.bonusMap.(x).(y)) (* is a bonus *)
|
||||
then begin
|
||||
|
@ -746,6 +779,7 @@ let move_crate (gd : game_data) (dgs : danger_map) =
|
|||
(* ---------------------------------------------------------------------------------------------------------------------------------------------------- *)
|
||||
(* ---------------------------------------------------------------------------------------------------------------------------------------------------- *)
|
||||
|
||||
let __start = Unix.gettimeofday() ;;
|
||||
let game_map = parse_input "entrees.txt" ;;
|
||||
if debug_all then print_game_data game_map ;;
|
||||
let danger_data = build_danger_map game_map ;;
|
||||
|
@ -764,4 +798,6 @@ Printf.printf "%d %d" direction !action ;
|
|||
if true || logg then Printf.fprintf stderr "[player %d] %d %d (at time %f)\n" game_map.player_id direction !action game_map.dt;
|
||||
|
||||
set_meta_info game_map.player_id ;;
|
||||
let __end = Unix.gettimeofday() ;;
|
||||
Printf.fprintf stderr "Time : %f\n" (__end -. __start) ;;
|
||||
|
||||
|
|
42
entrees.txt
42
entrees.txt
|
@ -1,24 +1,26 @@
|
|||
168.2180000000007
|
||||
2
|
||||
150.01600000000056
|
||||
3
|
||||
13 21
|
||||
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
|
||||
1 3 3 3 3 3 3 3 0 0 5 5 5 5 5 5 5 5 5 5 1
|
||||
1 3 1 3 1 3 1 0 1 0 1 0 1 5 1 5 1 5 1 5 1
|
||||
1 3 3 3 3 3 3 6 3 5 0 5 5 6 5 5 5 5 5 5 1
|
||||
1 3 1 3 1 3 1 6 1 5 1 5 1 6 1 4 1 5 1 5 1
|
||||
1 3 3 3 6 3 5 6 5 5 5 5 5 6 5 4 5 5 5 4 1
|
||||
1 3 1 3 1 6 1 6 1 5 1 5 1 6 1 4 1 4 1 4 1
|
||||
1 3 3 3 3 3 3 6 3 5 6 6 6 6 6 6 6 6 4 4 1
|
||||
1 3 1 3 1 6 1 6 1 5 1 5 1 6 1 6 1 4 1 4 1
|
||||
1 3 6 3 6 6 4 6 4 4 4 4 4 6 6 6 4 4 4 4 1
|
||||
1 3 1 3 1 6 1 6 1 4 1 5 1 6 1 6 1 4 1 4 1
|
||||
1 6 6 6 6 6 6 6 6 6 6 6 6 5 5 6 6 6 6 6 1
|
||||
1 3 3 3 6 6 6 6 6 0 0 5 5 5 5 5 5 5 5 5 1
|
||||
1 3 1 3 1 3 1 6 1 0 1 5 1 5 1 5 1 5 1 5 1
|
||||
1 3 3 3 3 3 3 6 6 4 6 6 5 5 5 5 5 5 5 5 1
|
||||
1 3 1 3 1 3 1 3 1 4 1 5 1 2 1 0 1 5 1 0 1
|
||||
1 3 3 3 3 3 6 6 6 4 2 0 2 2 2 2 2 0 2 2 1
|
||||
1 0 1 3 1 3 1 3 1 4 1 0 1 2 1 0 1 2 1 2 1
|
||||
1 2 6 3 3 3 3 3 3 4 0 0 2 0 0 4 0 0 0 2 1
|
||||
1 0 1 6 1 3 1 3 1 4 1 4 1 4 1 4 1 4 1 2 1
|
||||
1 6 0 6 6 6 6 4 4 4 4 4 4 4 4 4 4 4 0 0 1
|
||||
1 6 1 0 1 3 1 6 1 0 1 0 1 4 1 4 1 4 1 4 1
|
||||
1 6 6 6 3 3 0 0 2 2 0 4 4 4 4 4 4 4 4 4 1
|
||||
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
|
||||
1
|
||||
3 9 4 169.63600000000093
|
||||
2
|
||||
4 17 2 150.60000000000025
|
||||
9 13 3 151.16750000000042
|
||||
4
|
||||
1 8 0 2 3 3 2 3
|
||||
5 10 1 1 4 3 2 1
|
||||
5 10 2 3 3 3 3 4
|
||||
5 10 3 3 2 4 2 2
|
||||
0
|
||||
7 17 0 1 6 1 2 1
|
||||
8 15 1 4 5 3 1 2
|
||||
3 19 2 2 0 2 1 3
|
||||
4 9 3 3 1 3 1 2
|
||||
1
|
||||
11 10 3
|
||||
|
|
2
execZ.sh
2
execZ.sh
|
@ -1,2 +1,2 @@
|
|||
ocamlc again.ml -o again
|
||||
ocamlfind ocamlopt -linkpkg -package unix again.ml -o again
|
||||
./again
|
|
@ -1 +1 @@
|
|||
4 0
|
||||
2 0
|
Loading…
Reference in New Issue