added double bombing support, dash usage when cornered and changed some numbers

This commit is contained in:
Alexandre 2024-11-12 22:04:43 +01:00
parent 1f47adad37
commit 6b980deeef
10 changed files with 94 additions and 57 deletions

View File

@ -1,26 +1,29 @@
205.50000000000065
107.60000000000014
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 6 3 3 3 4 4 4 4 6 6 6 6 6 6 4 6 5 6 6 1
1 6 1 3 1 6 1 6 1 4 1 6 1 6 1 4 1 5 1 5 1
1 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 4 6 5 1
1 6 1 3 1 6 1 6 1 4 1 6 1 6 1 4 1 4 1 5 1
1 6 6 6 6 6 6 6 6 4 6 6 4 6 4 4 4 4 4 4 1
1 6 1 6 1 6 1 6 1 3 1 6 1 6 1 4 1 4 1 4 1
1 6 6 6 6 6 6 4 4 4 4 6 4 4 4 4 4 4 4 4 1
1 6 1 6 1 6 1 6 1 3 1 6 1 6 1 4 1 4 1 4 1
1 6 6 6 6 3 3 3 4 3 3 6 3 3 3 4 4 4 4 4 1
1 6 1 6 1 6 1 6 1 3 1 6 1 3 1 3 1 4 1 4 1
1 6 6 6 3 6 3 3 3 3 3 3 3 3 3 3 3 4 3 4 1
1 3 3 3 3 3 3 0 2 0 2 2 2 2 2 2 5 5 5 5 1
1 3 1 3 1 3 1 2 1 2 1 0 1 2 1 2 1 5 1 5 1
1 3 3 3 3 3 3 3 0 2 2 2 2 2 0 5 5 5 5 5 1
1 3 1 3 1 3 1 2 1 2 1 2 1 0 1 5 1 5 1 5 1
1 3 3 3 3 3 0 2 2 2 2 2 2 0 5 5 5 5 5 5 1
1 0 1 3 1 3 1 2 1 2 1 0 1 2 1 5 1 4 1 5 1
1 6 6 6 6 6 0 2 2 2 2 2 2 0 2 0 0 4 4 4 1
1 6 1 3 1 6 1 0 1 2 1 2 1 2 1 0 1 4 1 5 1
1 6 6 3 6 6 0 2 2 2 2 2 0 0 0 4 4 4 4 4 1
1 6 1 6 1 6 1 0 1 2 1 2 1 2 1 4 1 4 1 4 1
1 6 6 6 6 6 6 0 2 2 2 2 2 2 0 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
5
7 17 3 108.35799999999998
11 15 2 109.5
11 6 2 109.50000000000011
3 6 3 109.64919999999982
10 7 2 112.20000000000013
4
5 9 5 206.50000000000063
5 18 2 207.00000000000085
7 10 5 209.20000000000064
11 15 4 209.69300000000123
3
11 17 1 3 2 4 1 3
3 19 2 1 2 2 1 3
8 9 3 1 4 5 4 3
0
1 7 0 4 3 3 0 0
8 15 1 0 2 2 3 1
9 17 2 3 3 3 0 2
10 7 3 1 2 2 3 0
1
5 13 1

BIN
main

Binary file not shown.

BIN
main.cmi

Binary file not shown.

BIN
main.cmo

Binary file not shown.

95
main.ml
View File

@ -1,4 +1,10 @@
(*#! /home/alexandre/.opam/myswitch/bin/ocaml *)
(*
TODO :
- deal with double bombing (DONE)
- well shit ==> dash (DONE (needs dash to be fixed tho))
- deeper analysis on pathfinfing
*)
(* ---------------------------------------------------------------------------------------------------------------------------------------------------- *)
(* ---------------------------------------------------------------------------------------------------------------------------------------------------- *)
@ -103,6 +109,8 @@ exception ReturnBool of bool ;;
let current_status = ref BlowUpCrates ;;
let action = ref 0 ;;
let dash_left = ref 0 ;;
let equal_pt (p1 : pt) (p2 : pt) =
p1.x = p2.x && p1.y = p2.y ;;
@ -194,21 +202,32 @@ let rec ln_b b = function
let get_meta_info (pid : int) =
let ptr = open_in ("main_"^(string_of_int pid)^".sav") in
match (int_of_string (input_line ptr)) with
let fct0 () = match (int_of_string (input_line ptr)) with
| 0 -> current_status := EscapeDeath
| 1 -> current_status := BlowUpCrates
| 2 -> current_status := ClaimLand
| 3 -> current_status := KillPlayers
| _ -> current_status := EscapeDeath ;
close_in ptr ;;
| _ -> current_status := EscapeDeath
in
fct0 () ;
try
let resu = int_of_string (input_line ptr) in
dash_left := resu -1;
close_in ptr
with
| End_of_file -> close_in ptr ;;
let set_meta_info (pid : int) =
let ptr = open_out ("main_"^(string_of_int pid)^".sav") in
match !current_status with
let fct0 () = match !current_status with
| EscapeDeath -> Printf.fprintf ptr "0"
| BlowUpCrates -> Printf.fprintf ptr "1"
| ClaimLand -> Printf.fprintf ptr "2"
| KillPlayers -> Printf.fprintf ptr "3" ;
| KillPlayers -> Printf.fprintf ptr "3"
in
fct0 () ;
if !dash_left > 0 then
Printf.fprintf ptr "\n%d" !dash_left ;
close_out ptr ;;
(* ---------------------------------------------------------------------------------------------------------------------------------------------------- *)
@ -329,21 +348,6 @@ let evaluate_dangers (gd : game_data) =
done
done ;
(* add players *)
for p = 0 to gd.nplayers -1 do
if p <> gd.player_id then begin
let player_dgr = (Danger (gd.dt +. 5.5)) in
for d = 0 to 3 do
for o = 0 to gd.players.(p).bomb_radius do
let nx = gd.players.(p).xy.x + o*(fst order.(d))
and ny = gd.players.(p).xy.y + o*(snd order.(d)) in
if is_valid nx ny lines cols then
res.(nx).(ny) <- danger_priority res.(nx).(ny) player_dgr ;
done
done
end
done;
(* add bonuses *)
for b = 0 to gd.nboosts -1 do
res.(gd.boosts.(b).xy.x).(gd.boosts.(b).xy.y) <- danger_priority (res.(gd.boosts.(b).xy.x).(gd.boosts.(b).xy.y)) Bonus
@ -365,12 +369,12 @@ let evaluate_dangers (gd : game_data) =
(* add bomb tiles *)
let exploded = Hashtbl.create 12 in
for b = 0 to gd.nbombs -1 do
let dgr = warn_level gd.bombs.(b) gd.dt in
let halt = ref false in
let bx = gd.bombs.(b).xy.x
and by = gd.bombs.(b).xy.y in
let dgr = danger_priority (warn_level gd.bombs.(b) gd.dt) (res.(bx).(by)) in (* be careful of chained bombs *)
let halt = ref false in
for dir = 0 to 3 do
for w = 0 to gd.bombs.(b).size do
let cx = bx + w*(fst order.(dir))
@ -392,6 +396,21 @@ let evaluate_dangers (gd : game_data) =
done
done;
(* add players *)
for p = 0 to gd.nplayers -1 do
if p <> gd.player_id then begin
let player_dgr = danger_priority (Danger (gd.dt +. 5.5)) (res.(gd.players.(p).xy.x).(gd.players.(p).xy.y)) in
for d = 0 to 3 do
for o = 0 to gd.players.(p).bomb_radius do
let nx = gd.players.(p).xy.x + o*(fst order.(d))
and ny = gd.players.(p).xy.y + o*(snd order.(d)) in
if is_valid nx ny lines cols then
res.(nx).(ny) <- danger_priority res.(nx).(ny) player_dgr ;
done
done
end
done;
res ;;
(* ---------------------------------------------------------------------------------------------------------------------------------------------------- *)
@ -588,7 +607,7 @@ let move_explore (gd: game_data) (dgs : danger array array) =
let (cxi, cyi) = (gd.players.(pid).xy.x, gd.players.(pid).xy.y) in
let move_with_caution (exit : bool) =
let res = has_a_safe_path_origin_2 cxi cyi lines cols gd.dt interval gd dgs [|Bonus|] [||] [|Blocked|] [||] 5 in
let res = has_a_safe_path_origin_2 cxi cyi lines cols gd.dt interval gd dgs [|Bonus|] [||] [|Blocked|] [||] 7 in
if res <> 4 then begin
if debug_all then Printf.fprintf stderr "[crates] success 1/2!\n" ;
res
@ -612,9 +631,10 @@ let move_explore (gd: game_data) (dgs : danger array array) =
(* simulate the placement of a bomb, and test if that stills allows safe escape *)
let bomb_hash = Hashtbl.create (4 * (bsize +1)) in
let saved_dgs = Hashtbl.create (4 * (bsize +1)) in
let bomb_dgr = (danger_priority (Danger (gd.dt +. 5.5)) dgs.(bx).(by)) in
for dir = 0 to 3 do
for w = 0 to bsize do
Hashtbl.add bomb_hash (bx + w*(fst order.(dir)), by + w*(snd order.(dir))) (Danger (gd.dt +. 5.5)) ;
Hashtbl.add bomb_hash (bx + w*(fst order.(dir)), by + w*(snd order.(dir))) bomb_dgr ;
done
done;
Hashtbl.iter
@ -713,9 +733,10 @@ let move_claim (gd : game_data) (dgs : danger array array) (gns : int array arra
let bomb_hash = Hashtbl.create (4 * (bsize +1)) in
let saved_dgs = Hashtbl.create (4 * (bsize +1)) in
let bomb_dgr = danger_priority (Danger (gd.dt +. 5.5)) (dgs.(gd.players.(pid).xy.x).(gd.players.(pid).xy.y)) in
for dir = 0 to 3 do
for w = 0 to bsize do
Hashtbl.add bomb_hash (cxi + w*(fst order.(dir)), cyi + w*(snd order.(dir))) (Danger (gd.dt +. 5.5)) ;
Hashtbl.add bomb_hash (cxi + w*(fst order.(dir)), cyi + w*(snd order.(dir))) bomb_dgr ;
done
done;
Hashtbl.iter
@ -769,7 +790,7 @@ let move_safe (gd : game_data) (dgs : danger array array) (gns : int array array
try
(* 0. if you're standing on a safe tile, switch mode *)
let (cx, cy) = (gd.players.(pid).xy.x, gd.players.(pid).xy.y) in
if dgs.(cx).(cy) = Safe then begin
if (!dash_left = 0) && dgs.(cx).(cy) = Safe then begin
if contains_crate gd then begin
current_status := BlowUpCrates ;
raise (ReturnInt (move_explore gd dgs)) ;
@ -782,15 +803,27 @@ let move_safe (gd : game_data) (dgs : danger array array) (gns : int array array
(*let result = has_a_safe_path (cx) (cy) gd.dt in*)
let result = has_a_safe_path_origin_2 cx cy lines cols gd.dt interval gd dgs [|Bonus|] [||] [|Blocked|] [||] 20 in
if result <> 4 then result else begin
let result2 = has_a_safe_path_origin_2 cx cy lines cols gd.dt interval gd dgs [|Safe|] [||] [|Blocked|] [||] 80 in
if result2 <> 4 then result2
if (!dash_left = 0) && result <> 4 then
result
else begin
let result2 = has_a_safe_path_origin_2 cx cy lines cols gd.dt interval gd dgs [|Safe|] [||] [|Blocked|] [||] 80 in
if (!dash_left = 0) && result2 <> 4 then
result2
else begin
(* you're probably dead if the code reaches here, unless... *)
if (!dash_left > 0) || gd.players.(pid).ndash > 0 then begin
Printf.fprintf stderr "*teleports*\n" ;
if (!dash_left = 0) then
action := 2 ;
dash_left := 3 ;
has_a_safe_path_origin_2 cx cy lines cols (gd.dt -. interval *. float_of_int (!dash_left)) interval gd dgs [|Safe|] [||] [|Blocked|] [||] 80
end
else begin
(* you're probably dead if the code reaches here... *)
Printf.fprintf stderr "well shit\n" ;
4
end
end
end
with
| ReturnInt k -> k ;;

View File

@ -1 +1 @@
0
1

View File

@ -1 +1 @@
0
1

View File

@ -1 +1 @@
2
1

View File

@ -1 +1 @@
0
1

View File

@ -0,0 +1 @@
2 2