diff --git a/again b/again index d61c94f..ec8f960 100755 Binary files a/again and b/again differ diff --git a/again.cmi b/again.cmi index e86252e..532f6de 100644 Binary files a/again.cmi and b/again.cmi differ diff --git a/again.cmo b/again.cmo index 553a8bc..6f80752 100644 Binary files a/again.cmo and b/again.cmo differ diff --git a/again.ml b/again.ml index 4ae34a5..907e722 100644 --- a/again.ml +++ b/again.ml @@ -1,8 +1,8 @@ (* TODO : - deal with double bombing (DONE) -- well shit ==> dash (DONE (needs dash to be fixed tho)) -- deeper analysis on pathfinfing +- well shit ==> dash +- 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 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 lines = Array.length gd.laby and cols = Array.length gd.laby.(0) in Array.fold_left (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 order ;; let max_depth = 4 ;; let is_player_nearby (gd : game_data) = + let pid = gd.player_id in let lines = Array.length gd.laby 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 ((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 = 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; @@ -511,10 +506,13 @@ let is_player_nearby (gd : game_data) = end in try - dfs (gd.players.(gd.player_id).xy.x +1) (gd.players.(gd.player_id).xy.y) 0; - dfs (gd.players.(gd.player_id).xy.x -1) (gd.players.(gd.player_id).xy.y) 0; - dfs (gd.players.(gd.player_id).xy.x) (gd.players.(gd.player_id).xy.y +1) 0; - dfs (gd.players.(gd.player_id).xy.x) (gd.players.(gd.player_id).xy.y -1) 0; + (* 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 ;; @@ -530,7 +528,7 @@ let is_dead_end (gd : game_data) (xstart : int) (ystart : int) (xban : int) (yba 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) 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 | 0 -> failwith "wtf john" | 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 | 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 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) then begin (* is not lethal *) 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 *) - (*(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 searchBonus || dgs.bonusMap.(x).(y)) (* is a bonus *) then begin @@ -700,7 +699,7 @@ let move_crate (gd : game_data) (dgs : danger_map) = let cxi = gd.players.(pid).xy.x and cyi = gd.players.(pid).xy.y in 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 logg then Printf.fprintf stderr "bonus spotted\n" ; 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 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 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 action := 1 ; raise (ReturnInt result) ; @@ -721,12 +720,12 @@ let move_crate (gd : game_data) (dgs : danger_map) = end; end; 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 rescr else begin 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 end with diff --git a/entrees.txt b/entrees.txt index aba0b51..a0eaadb 100644 --- a/entrees.txt +++ b/entrees.txt @@ -1,25 +1,26 @@ -142.0 +164.23000000000036 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 0 0 6 0 2 2 2 2 2 2 2 0 2 0 5 5 5 1 -1 3 1 3 1 6 1 2 1 2 1 2 1 2 1 0 1 5 1 5 1 -1 3 3 3 3 6 6 0 2 2 2 0 2 2 0 5 5 5 5 5 1 -1 3 1 3 1 6 1 2 1 2 1 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