players now wont go to a dead-end if someone's nearby
This commit is contained in:
parent
a6a0fa7d1a
commit
60788b784d
45
again.ml
45
again.ml
|
@ -1,8 +1,8 @@
|
||||||
(*
|
(*
|
||||||
TODO :
|
TODO :
|
||||||
- deal with double bombing (DONE)
|
- deal with double bombing (DONE)
|
||||||
- well shit ==> dash (DONE (needs dash to be fixed tho))
|
- well shit ==> dash
|
||||||
- deeper analysis on pathfinfing
|
- deeper analysis on pathfinfing (~DONE)
|
||||||
*)
|
*)
|
||||||
(* ---------------------------------------------------------------------------------------------------------------------------------------------------- *)
|
(* ---------------------------------------------------------------------------------------------------------------------------------------------------- *)
|
||||||
(* ---------------------------------------------------------------------------------------------------------------------------------------------------- *)
|
(* ---------------------------------------------------------------------------------------------------------------------------------------------------- *)
|
||||||
|
@ -93,7 +93,7 @@ exception ReturnBool of bool ;;
|
||||||
|
|
||||||
(* ---------------------------------------------------------------------------------------------------------------------------------------------------- *)
|
(* ---------------------------------------------------------------------------------------------------------------------------------------------------- *)
|
||||||
(* ---------------------------------------------------------------------------------------------------------------------------------------------------- *)
|
(* ---------------------------------------------------------------------------------------------------------------------------------------------------- *)
|
||||||
let order = [|(1, 0); (-1, 0); (0, 1); (0, -1)|] ;;
|
let order = [|(-1, 0); (0, 1); (1, 0); (0, -1)|] ;;
|
||||||
|
|
||||||
let current_status = ref BlowUpCrates ;;
|
let current_status = ref BlowUpCrates ;;
|
||||||
let action = ref 0 ;;
|
let action = ref 0 ;;
|
||||||
|
@ -475,29 +475,24 @@ let simulate_bomb_deconstruct (dgs : danger_map) (bx : int) (by : int) (bsize :
|
||||||
(* ---------------------------------------------------------------------------------------------------------------------------------------------------- *)
|
(* ---------------------------------------------------------------------------------------------------------------------------------------------------- *)
|
||||||
(* ---------------------------------------------------------------------------------------------------------------------------------------------------- *)
|
(* ---------------------------------------------------------------------------------------------------------------------------------------------------- *)
|
||||||
|
|
||||||
let exists_opt f (arr : 'a array) =
|
|
||||||
if Array.length arr = 0 then
|
|
||||||
false
|
|
||||||
else
|
|
||||||
Array.exists f arr ;;
|
|
||||||
|
|
||||||
let amt_free_adj_spaces (gd : game_data) (x : int) (y : int) =
|
let amt_free_adj_spaces (gd : game_data) (x : int) (y : int) =
|
||||||
let lines = Array.length gd.laby
|
let lines = Array.length gd.laby
|
||||||
and cols = Array.length gd.laby.(0) in
|
and cols = Array.length gd.laby.(0) in
|
||||||
Array.fold_left
|
Array.fold_left
|
||||||
(fun acc (ox, oy) ->
|
(fun acc (ox, oy) ->
|
||||||
if (is_valid (x+ox) (y+oy) lines cols && gd.laby.(x+ox).(y+oy) <> 1 && gd.laby.(x+ox).(y+oy) <> 2) then acc+1 else acc
|
if (is_valid (x+ox) (y+oy) lines cols && gd.laby.(x+ox).(y+oy) <> 1 && gd.laby.(x+ox).(y+oy) <> 2 && not (Array.fold_left (fun acc (b : bomb) -> acc || (b.xy.x = x && b.xy.y = y)) false gd.bombs)) then acc+1 else acc
|
||||||
)
|
)
|
||||||
0
|
0
|
||||||
order ;;
|
order ;;
|
||||||
|
|
||||||
let max_depth = 4 ;;
|
let max_depth = 4 ;;
|
||||||
let is_player_nearby (gd : game_data) =
|
let is_player_nearby (gd : game_data) =
|
||||||
|
let pid = gd.player_id in
|
||||||
let lines = Array.length gd.laby
|
let lines = Array.length gd.laby
|
||||||
and cols = Array.length gd.laby.(0) in
|
and cols = Array.length gd.laby.(0) in
|
||||||
(* DFS to find whether or not there are nearby players *)
|
(* DFS to find whether or not there are nearby players *)
|
||||||
let visited = Hashtbl.create 40 in
|
let visited = Hashtbl.create 40 in
|
||||||
Hashtbl.add visited ((gd.players.(gd.player_id).xy.x), (gd.players.(gd.player_id).xy.y)) 1 ;
|
Hashtbl.add visited ((gd.players.(pid).xy.x), (gd.players.(pid).xy.y)) 1 ;
|
||||||
let rec dfs x y depth =
|
let rec dfs x y depth =
|
||||||
if Hashtbl.find_opt visited (x, y) = None && depth <= max_depth && (is_valid x y lines cols && gd.laby.(x).(y) <> 1 && gd.laby.(x).(y) <> 2) then begin
|
if Hashtbl.find_opt visited (x, y) = None && depth <= max_depth && (is_valid x y lines cols && gd.laby.(x).(y) <> 1 && gd.laby.(x).(y) <> 2) then begin
|
||||||
Hashtbl.add visited (x, y) 1;
|
Hashtbl.add visited (x, y) 1;
|
||||||
|
@ -511,10 +506,13 @@ let is_player_nearby (gd : game_data) =
|
||||||
end
|
end
|
||||||
in
|
in
|
||||||
try
|
try
|
||||||
dfs (gd.players.(gd.player_id).xy.x +1) (gd.players.(gd.player_id).xy.y) 0;
|
(* if another player is stacked *)
|
||||||
dfs (gd.players.(gd.player_id).xy.x -1) (gd.players.(gd.player_id).xy.y) 0;
|
if Array.fold_left (fun acc (p : player) -> acc || (p.id <> pid && p.xy.x = gd.players.(pid).xy.x && p.xy.y = gd.players.(pid).xy.y)) false gd.players then
|
||||||
dfs (gd.players.(gd.player_id).xy.x) (gd.players.(gd.player_id).xy.y +1) 0;
|
raise (ReturnBool true) ;
|
||||||
dfs (gd.players.(gd.player_id).xy.x) (gd.players.(gd.player_id).xy.y -1) 0;
|
dfs (gd.players.(pid).xy.x +1) (gd.players.(pid).xy.y) 0;
|
||||||
|
dfs (gd.players.(pid).xy.x -1) (gd.players.(pid).xy.y) 0;
|
||||||
|
dfs (gd.players.(pid).xy.x) (gd.players.(pid).xy.y +1) 0;
|
||||||
|
dfs (gd.players.(pid).xy.x) (gd.players.(pid).xy.y -1) 0;
|
||||||
false
|
false
|
||||||
with
|
with
|
||||||
| ReturnBool b -> b ;;
|
| ReturnBool b -> b ;;
|
||||||
|
@ -530,7 +528,7 @@ let is_dead_end (gd : game_data) (xstart : int) (ystart : int) (xban : int) (yba
|
||||||
let rec aux x y =
|
let rec aux x y =
|
||||||
if Hashtbl.find_opt visited (x, y) = None then begin
|
if Hashtbl.find_opt visited (x, y) = None then begin
|
||||||
Hashtbl.add visited (x, y) 1;
|
Hashtbl.add visited (x, y) 1;
|
||||||
if (is_valid x y lines cols && gd.laby.(x).(y) <> 1 && gd.laby.(x).(y) <> 2) then begin
|
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
|
match (amt_free_adj_spaces gd x y) with
|
||||||
| 0 -> failwith "wtf john"
|
| 0 -> failwith "wtf john"
|
||||||
| 1 | 2 -> for dir = 0 to 3 do
|
| 1 | 2 -> for dir = 0 to 3 do
|
||||||
|
@ -645,7 +643,7 @@ let sees_a_crate (gd : game_data) (dgs : danger_map) (x : int) (y : int) =
|
||||||
with
|
with
|
||||||
| ReturnBool b -> b ;;
|
| ReturnBool b -> b ;;
|
||||||
|
|
||||||
let bfs_for_crate (gd : game_data) (dgs : danger_map) (x0 : int) (y0 : int) (stime : float) (searchCrate : bool) (searchBonus : bool) (minDist : int) (ignorePlayers : bool) (maxDist : int) =
|
let bfs_for_crate (gd : game_data) (dgs : danger_map) (x0 : int) (y0 : int) (stime : float) (searchCrate : bool) (searchBonus : bool) (placedBomb : bool) (minDist : int) (ignorePlayers : bool) (maxDist : int) =
|
||||||
let lines = Array.length gd.laby
|
let lines = Array.length gd.laby
|
||||||
and cols = Array.length gd.laby.(0) in
|
and cols = Array.length gd.laby.(0) in
|
||||||
|
|
||||||
|
@ -673,9 +671,10 @@ let bfs_for_crate (gd : game_data) (dgs : danger_map) (x0 : int) (y0 : int) (sti
|
||||||
not (Array.fold_left (fun acc (b : bomb) -> acc || (b.xy.x = x && b.xy.y = y)) false gd.bombs)
|
not (Array.fold_left (fun acc (b : bomb) -> acc || (b.xy.x = x && b.xy.y = y)) false gd.bombs)
|
||||||
then begin (* is not lethal *)
|
then begin (* is not lethal *)
|
||||||
if
|
if
|
||||||
(ct >= stime +. (float_of_int minDist) *. interval) &&
|
(ct >= stime +. (float_of_int minDist) *. interval) && (* not too deep *)
|
||||||
(is_empty_lst dgs.explosionTimes.(x).(y)) && (* safe *)
|
(is_empty_lst dgs.explosionTimes.(x).(y)) && (* safe *)
|
||||||
(*(not searchCrate || 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 (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 searchCrate || (sees_a_crate gd dgs x y && not dgs.explodedCrates.(x).(y))) && (* sees a crate *)
|
(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 *)
|
(not searchBonus || dgs.bonusMap.(x).(y)) (* is a bonus *)
|
||||||
then begin
|
then begin
|
||||||
|
@ -700,7 +699,7 @@ let move_crate (gd : game_data) (dgs : danger_map) =
|
||||||
let cxi = gd.players.(pid).xy.x
|
let cxi = gd.players.(pid).xy.x
|
||||||
and cyi = gd.players.(pid).xy.y in
|
and cyi = gd.players.(pid).xy.y in
|
||||||
try
|
try
|
||||||
let bonusres = bfs_for_crate gd dgs cxi cyi gd.dt false true 0 false 7 in
|
let bonusres = bfs_for_crate gd dgs cxi cyi gd.dt false true false 0 false 7 in
|
||||||
if bonusres <> 4 then begin
|
if bonusres <> 4 then begin
|
||||||
if logg then Printf.fprintf stderr "bonus spotted\n" ;
|
if logg then Printf.fprintf stderr "bonus spotted\n" ;
|
||||||
raise (ReturnInt bonusres) ;
|
raise (ReturnInt bonusres) ;
|
||||||
|
@ -709,7 +708,7 @@ let move_crate (gd : game_data) (dgs : danger_map) =
|
||||||
if gd.players.(pid).nbomb_atonce > 0 then begin
|
if gd.players.(pid).nbomb_atonce > 0 then begin
|
||||||
if logg then Printf.fprintf stderr "trying...\n" ;
|
if logg then Printf.fprintf stderr "trying...\n" ;
|
||||||
let saved = simulate_bomb_deconstruct dgs cxi cyi gd.players.(pid).bomb_radius (gd.dt +. 5.5) in
|
let saved = simulate_bomb_deconstruct dgs cxi cyi gd.players.(pid).bomb_radius (gd.dt +. 5.5) in
|
||||||
let result = bfs_for_crate gd dgs cxi cyi gd.dt false false 1 false 80 in
|
let result = bfs_for_crate gd dgs cxi cyi gd.dt false false true 1 false 80 in
|
||||||
if result <> 4 then begin
|
if result <> 4 then begin
|
||||||
action := 1 ;
|
action := 1 ;
|
||||||
raise (ReturnInt result) ;
|
raise (ReturnInt result) ;
|
||||||
|
@ -721,12 +720,12 @@ let move_crate (gd : game_data) (dgs : danger_map) =
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
if logg then Printf.fprintf stderr "searching...\n" ;
|
if logg then Printf.fprintf stderr "searching...\n" ;
|
||||||
let rescr = bfs_for_crate gd dgs cxi cyi gd.dt true false 0 false 80 in
|
let rescr = bfs_for_crate gd dgs cxi cyi gd.dt true false false 0 false 80 in
|
||||||
if rescr <> 4 then
|
if rescr <> 4 then
|
||||||
rescr
|
rescr
|
||||||
else begin
|
else begin
|
||||||
if logg then Printf.fprintf stderr "searching 2...\n" ;
|
if logg then Printf.fprintf stderr "searching 2...\n" ;
|
||||||
let rescr2 = bfs_for_crate gd dgs cxi cyi gd.dt false false 0 false 80 in
|
let rescr2 = bfs_for_crate gd dgs cxi cyi gd.dt false false false 0 false 80 in
|
||||||
rescr2
|
rescr2
|
||||||
end
|
end
|
||||||
with
|
with
|
||||||
|
|
41
entrees.txt
41
entrees.txt
|
@ -1,25 +1,26 @@
|
||||||
142.0
|
164.23000000000036
|
||||||
3
|
3
|
||||||
13 21
|
13 21
|
||||||
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
|
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
|
||||||
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1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
|
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
|
||||||
2
|
4
|
||||||
3 7 1 144.5
|
7 8 3 165.48950000000036
|
||||||
9 11 4 144.80000000000047
|
3 11 2 166.5
|
||||||
|
1 13 3 167.44000000000028
|
||||||
|
9 9 3 168.7700000000004
|
||||||
3
|
3
|
||||||
11 10 0 1 3 4 3 1
|
11 9 0 4 0 3 2 2
|
||||||
8 13 1 1 1 1 2 2
|
3 15 2 0 1 2 1 4
|
||||||
2 5 3 0 1 1 2 1
|
4 9 3 2 2 2 2 1
|
||||||
1
|
0
|
||||||
7 12 4
|
|
||||||
|
|
Loading…
Reference in New Issue