some balance changes to pathfinding
This commit is contained in:
parent
50a354ea94
commit
b6727d2eb9
51
again.ml
51
again.ml
|
@ -2,8 +2,9 @@
|
||||||
TODO :
|
TODO :
|
||||||
- deal with double bombing (DONE)
|
- deal with double bombing (DONE)
|
||||||
- well shit ==> dash
|
- well shit ==> dash
|
||||||
- deeper analysis on pathfinfing (1/2)
|
- deeper analysis on pathfinfing (n-1/n)
|
||||||
- correct fatal bug on player death (DONE)
|
- correct fatal bug on player death (DONE)
|
||||||
|
- solve when player is on a bomb on an intersection
|
||||||
*)
|
*)
|
||||||
(* ---------------------------------------------------------------------------------------------------------------------------------------------------- *)
|
(* ---------------------------------------------------------------------------------------------------------------------------------------------------- *)
|
||||||
(* ---------------------------------------------------------------------------------------------------------------------------------------------------- *)
|
(* ---------------------------------------------------------------------------------------------------------------------------------------------------- *)
|
||||||
|
@ -498,7 +499,7 @@ let tile_distance (gd : game_data) (x0 : int) (y0 : int) (end_x : int) (end_y :
|
||||||
try
|
try
|
||||||
while not (Queue.is_empty q) do
|
while not (Queue.is_empty q) do
|
||||||
let (x, y, depth) = Queue.pop q in
|
let (x, y, depth) = Queue.pop q in
|
||||||
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
|
if 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 then begin (* has not been visited yet *)
|
if Hashtbl.find_opt visited (x, y) = None then begin (* has not been visited yet *)
|
||||||
Hashtbl.add visited (x, y) 1 ;
|
Hashtbl.add visited (x, y) 1 ;
|
||||||
if (x = end_x && y = end_y) then begin
|
if (x = end_x && y = end_y) then begin
|
||||||
|
@ -541,52 +542,18 @@ let amt_free_adj_spaces (gd : game_data) (x : int) (y : int) =
|
||||||
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 && not (Array.fold_left (fun acc (b : bomb) -> acc || (b.xy.x = x+ox && b.xy.y = y+oy)) false gd.bombs)) then acc+1 else acc
|
if not (ox = 0 && oy = 0) && (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+ox && b.xy.y = y+oy)) false gd.bombs)) then acc+1 else acc
|
||||||
)
|
)
|
||||||
0
|
0
|
||||||
order ;;
|
order ;;
|
||||||
|
|
||||||
let max_depth = 12345 ;;
|
let max_depth = 12345 ;;
|
||||||
let is_player_nearby (gd : game_data) (x0 : int) (y0 : int) (detect_dist : int) =
|
let is_player_nearby (gd : game_data) (x0 : int) (y0 : int) (detect_dist : int) =
|
||||||
let pid = gd.player_id in
|
let mind = min_dist_from_player gd x0 y0 in
|
||||||
let lines = Array.length gd.laby
|
(mind <= detect_dist) ;;
|
||||||
and cols = Array.length gd.laby.(0) in
|
|
||||||
(* DFS to find whether or not there are nearby players *)
|
|
||||||
let visited = Hashtbl.create 40 in
|
|
||||||
Hashtbl.add visited (x0, y0) 1 ;
|
|
||||||
let rec dfs x y depth =
|
|
||||||
if
|
|
||||||
(Hashtbl.find_opt visited (x, y) = None) &&
|
|
||||||
(depth <= detect_dist) &&
|
|
||||||
(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
|
|
||||||
Hashtbl.add visited (x, y) 1;
|
|
||||||
if Array.exists (fun (p : player) -> p.xy.x = x && p.xy.y = y && p.id <> gd.player_id) gd.players then begin
|
|
||||||
raise (ReturnBool true)
|
|
||||||
end
|
|
||||||
else begin
|
|
||||||
for dir = 0 to 3 do
|
|
||||||
dfs (x + fst order.(dir)) (y + snd order.(dir)) (depth+1)
|
|
||||||
done
|
|
||||||
end
|
|
||||||
end
|
|
||||||
in
|
|
||||||
try
|
|
||||||
(* if another player is stacked *)
|
|
||||||
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
|
|
||||||
raise (ReturnBool true) ;
|
|
||||||
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
|
|
||||||
with
|
|
||||||
| ReturnBool b -> b ;;
|
|
||||||
|
|
||||||
let is_dead_end (gd : game_data) (xstart : int) (ystart : int) (xban : int) (yban : int) =
|
let is_dead_end (gd : game_data) (xstart : int) (ystart : int) (xban : int) (yban : int) =
|
||||||
if not (is_player_nearby gd gd.players.(gd.player_id).xy.x gd.players.(gd.player_id).xy.y max_depth) then
|
if not (is_player_nearby gd gd.players.(gd.player_id).xy.x gd.players.(gd.player_id).xy.y 3) then
|
||||||
false (* if no one is nearby, it's safe to go there (hopefully) *)
|
false (* if no one is nearby, it's safe to go there (hopefully) *)
|
||||||
else begin
|
else begin
|
||||||
let lines = Array.length gd.laby
|
let lines = Array.length gd.laby
|
||||||
|
@ -732,7 +699,7 @@ let goto_tile (gd : game_data) (dgs : danger_map) (x0 : int) (y0 : int) (end_x :
|
||||||
raise (ReturnInt direction)
|
raise (ReturnInt direction)
|
||||||
end;
|
end;
|
||||||
(*Queue.add (x, y, ct +. interval, direction) q ;*)
|
(*Queue.add (x, y, ct +. interval, direction) q ;*)
|
||||||
if not (x0 == x && y0 == y) then begin
|
if not (is_player_nearby gd x y 3 && amt_free_adj_spaces gd (gd.players.(pid).xy.x + fst order.(direction)) (gd.players.(pid).xy.y + snd order.(direction)) = 1) && not (x0 == x && y0 == y) then begin
|
||||||
for dir = 0 to 3 do
|
for dir = 0 to 3 do
|
||||||
Queue.add (x + (fst order.(dir)), y + (snd order.(dir)), ct +. interval, direction) q ;
|
Queue.add (x + (fst order.(dir)), y + (snd order.(dir)), ct +. interval, direction) q ;
|
||||||
done;
|
done;
|
||||||
|
@ -846,7 +813,7 @@ let bfs_for_crate (gd : game_data) (dgs : danger_map) (x0 : int) (y0 : int) (sti
|
||||||
raise (ReturnInt direction)
|
raise (ReturnInt direction)
|
||||||
end;
|
end;
|
||||||
(*Queue.add (x, y, ct +. interval, direction, polar+1) q ;*)
|
(*Queue.add (x, y, ct +. interval, direction, polar+1) q ;*)
|
||||||
if not (x0 == x && y0 == y) then begin
|
if not (x0 == x && y0 == y) && (not (is_player_nearby gd x y 3 && amt_free_adj_spaces gd (gd.players.(pid).xy.x + fst order.(direction)) (gd.players.(pid).xy.y + snd order.(direction)) = 1)) then begin
|
||||||
for dir = 0 to 3 do
|
for dir = 0 to 3 do
|
||||||
Queue.add (x + (fst order.(dir)), y + (snd order.(dir)), ct +. interval, direction, polar) q ;
|
Queue.add (x + (fst order.(dir)), y + (snd order.(dir)), ct +. interval, direction, polar) q ;
|
||||||
done;
|
done;
|
||||||
|
|
40
entrees.txt
40
entrees.txt
|
@ -1,26 +1,26 @@
|
||||||
187.24208499999915
|
183.6000000000002
|
||||||
2
|
0
|
||||||
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
|
||||||
1 3 3 3 3 3 3 6 3 3 3 3 0 0 0 0 5 5 5 5 1
|
1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 1 1 1 1 1 1 1 1 1 1 1 1 1 1
|
||||||
3
|
3
|
||||||
5 1 3 189.5
|
8 9 3 186.5850000000011
|
||||||
7 4 6 190.30000000000013
|
2 7 2 187.30000000000018
|
||||||
6 3 2 192.5
|
9 10 3 188.04300000000111
|
||||||
4
|
4
|
||||||
7 1 0 0 2 3 1 1
|
1 8 0 1 1 2 1 4
|
||||||
5 3 1 0 0 2 1 3
|
9 8 1 3 1 3 1 1
|
||||||
6 3 2 6 1 2 2 2
|
9 8 2 1 4 2 2 0
|
||||||
7 5 3 1 0 6 1 1
|
9 11 3 1 4 2 0 2
|
||||||
0
|
0
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
0 0
|
1 1
|
Loading…
Reference in New Issue