improvments

This commit is contained in:
Alexandre 2024-12-04 09:01:14 +01:00
parent 4169e93b65
commit c4b42c2a89
14 changed files with 71 additions and 70 deletions

BIN
again

Binary file not shown.

BIN
again.cmi

Binary file not shown.

BIN
again.cmx

Binary file not shown.

View File

@ -17,6 +17,7 @@ let logg = true ;;
(* ---------------------------------------------------------------------------------------------------------------------------------------------------- *) (* ---------------------------------------------------------------------------------------------------------------------------------------------------- *)
let fodder = ref 0 ;; let fodder = ref 0 ;;
let bodder = ref false ;;
type pt = { type pt = {
x : int ; x : int ;
y : int ; y : int ;
@ -448,30 +449,8 @@ let generate_gain_map (gd : game_data) =
(* ---------------------------------------------------------------------------------------------------------------------------------------------------- *) (* ---------------------------------------------------------------------------------------------------------------------------------------------------- *)
(* ---------------------------------------------------------------------------------------------------------------------------------------------------- *) (* ---------------------------------------------------------------------------------------------------------------------------------------------------- *)
let simulate_bomb (dgs : danger_map) (b : bomb) =
let saved_data = Hashtbl.create 30 in
let bx = b.xy.x
and by = b.xy.y in
let bsize = b.size
and dtime = min (b.det_time) (List.fold_left min (32760.) dgs.explosionTimes.(bx).(by)) in
let lines = Array.length dgs.explosionTimes
and cols = Array.length dgs.explosionTimes.(0) in
for dir = 0 to 3 do
for w = 0 to bsize do
if (w > 0 || dir = 0) then begin
let nx = bx + w * (fst order.(dir))
and ny = by + w * (snd order.(dir)) in
if is_valid nx ny lines cols then begin
Hashtbl.add saved_data (nx, ny) dtime ;
dgs.explosionTimes.(nx).(ny) <- (dtime)::(dgs.explosionTimes.(nx).(ny))
end
end
done;
done;
saved_data ;;
let simulate_bomb_deconstruct (gd : game_data) (dgs : danger_map) (bx : int) (by : int) (bsize : int) (dtime0 : float) = let simulate_bomb_deconstruct (gd : game_data) (dgs : danger_map) (bx : int) (by : int) (bsize : int) (dtime0 : float) =
let saved_data = Hashtbl.create 30 in let saved_data = Hashtbl.create 40 in
let dtime = min dtime0 (List.fold_left min (32760.) dgs.explosionTimes.(bx).(by)) in let dtime = min dtime0 (List.fold_left min (32760.) dgs.explosionTimes.(bx).(by)) in
let lines = Array.length dgs.explosionTimes let lines = Array.length dgs.explosionTimes
and cols = Array.length dgs.explosionTimes.(0) in and cols = Array.length dgs.explosionTimes.(0) in
@ -643,7 +622,7 @@ let generate_dead_end_map (gd : game_data) =
(not (Array.fold_left (fun acc (p : player) -> acc || (p.xy.x = x && p.xy.y = y && p.id <> pid)) false gd.players))*) (not (Array.fold_left (fun acc (p : player) -> acc || (p.xy.x = x && p.xy.y = y && p.id <> pid)) false gd.players))*)
then begin then begin
Hashtbl.add visit_mem (x, y) 1; Hashtbl.add visit_mem (x, y) 1;
if res.(x).(y) = 0 && not (x = gd.players.(pid).xy.x && y = gd.players.(pid).xy.y) then if res.(x).(y) = 0(* && not (x = gd.players.(pid).xy.x && y = gd.players.(pid).xy.y) *)then
raise (ReturnInt d) ; raise (ReturnInt d) ;
for dir = 0 to 3 do for dir = 0 to 3 do
Queue.add (x + fst (order.(dir)), y + snd (order.(dir)), d+1) q Queue.add (x + fst (order.(dir)), y + snd (order.(dir)), d+1) q
@ -692,7 +671,7 @@ let is_dead (dgs : danger_map) (x : int) (y : int) (t : float) (dt : float) =
let is_dead_2 (dgs : danger_map) (x : int) (y : int) (t : float) (dt : float) = let is_dead_2 (dgs : danger_map) (x : int) (y : int) (t : float) (dt : float) =
(List.fold_left (List.fold_left
(fun acc curtime -> (fun acc curtime ->
acc || (t > curtime && t < curtime +. dt) acc || (t >= curtime && t <= curtime +. dt)
) )
false false
dgs.explosionTimes.(x).(y) dgs.explosionTimes.(x).(y)
@ -822,7 +801,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 ?return_x:(retx=fodder) ?return_y:(rety=fodder) (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 bfs_for_crate ?return_x:(retx=fodder) ?return_y:(rety=fodder) ?return_ok:(retfl=bodder) (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
@ -832,11 +811,12 @@ let bfs_for_crate ?return_x:(retx=fodder) ?return_y:(rety=fodder) (gd : game_dat
let pid = gd.player_id in let pid = gd.player_id in
let needs_gtfo = not (is_empty_lst dgs.explosionTimes.(x0).(y0)) in let needs_gtfo = not (is_empty_lst dgs.explosionTimes.(x0).(y0)) in
let nearest_player = min_dist_with_dash gd gd.players.(pid).xy.x gd.players.(pid).xy.y in (*let nearest_player = min_dist_with_dash gd gd.players.(pid).xy.x gd.players.(pid).xy.y in*)
let nearest_player = min_dist_from_player gd gd.players.(pid).xy.x gd.players.(pid).xy.y in
let undead_end_tiles = generate_dead_end_map gd in let undead_end_tiles = generate_dead_end_map gd in
if gd.player_id = 2 then begin if gd.player_id = 4 then begin
for l = 0 to Array.length undead_end_tiles -1 do for l = 0 to Array.length undead_end_tiles -1 do
for c = 0 to Array.length undead_end_tiles.(l) -1 do for c = 0 to Array.length undead_end_tiles.(l) -1 do
if undead_end_tiles.(l).(c) >= 727 then if undead_end_tiles.(l).(c) >= 727 then
@ -870,11 +850,11 @@ let bfs_for_crate ?return_x:(retx=fodder) ?return_y:(rety=fodder) (gd : game_dat
then begin (* is not lethal *) then begin (* is not lethal *)
if false && ct <= stime +. 3. *. interval then begin if false && ct <= stime +. 3. *. interval then begin
Printf.fprintf stderr "(at %d %d) %b %b %b %b %b\n" x y Printf.fprintf stderr "(at %d %d) %b %b %b %b %b\n" x y
(ct >= stime +. (float_of_int minDist) *. interval) (* not too deep *) (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 *)
(needs_gtfo || undead_end_tiles.(x).(y) * 2 <= nearest_player) (* is not going to be an ez kill *) (needs_gtfo || undead_end_tiles.(x).(y) * 2 <= nearest_player) (* is not going to be an ez kill *)
(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 *)
end; end;
if if
(ct >= stime +. (float_of_int minDist) *. interval) && (* not too deep *) (ct >= stime +. (float_of_int minDist) *. interval) && (* not too deep *)
@ -897,9 +877,12 @@ let bfs_for_crate ?return_x:(retx=fodder) ?return_y:(rety=fodder) (gd : game_dat
end end
end end
done; done;
retfl := false ;
4 ; 4 ;
with with
| ReturnInt k -> k ;; | ReturnInt k ->
retfl := true ;
k ;;
let move_crate (gd : game_data) (dgs : danger_map) = let move_crate (gd : game_data) (dgs : danger_map) =
let pid = gd.player_id in let pid = gd.player_id in
@ -963,9 +946,10 @@ let move_crate (gd : game_data) (dgs : danger_map) =
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 false 0 false 80 in let success = ref false in
let rescr2 = bfs_for_crate ~return_ok:success gd dgs cxi cyi gd.dt false false false 0 false 80 in
if logg then Printf.fprintf stderr "searching 2 Done...\n" ; if logg then Printf.fprintf stderr "searching 2 Done...\n" ;
if rescr2 <> 4 then if !success then
rescr2 rescr2
else begin else begin
if logg then Printf.fprintf stderr "Needs dash lmao\n"; if logg then Printf.fprintf stderr "Needs dash lmao\n";
@ -1044,7 +1028,7 @@ let gain_map = generate_gain_map game_map ;;
(*Printf.fprintf stderr "\n" ;; (*Printf.fprintf stderr "\n" ;;
print_dangers danger_data ;;*) print_dangers danger_data ;;*)
get_meta_info game_map.player_id ;; (*get_meta_info game_map.player_id ;;*)
(*Printf.fprintf stderr "\n" ;; (*Printf.fprintf stderr "\n" ;;
print_dangers danger_data ;;*) print_dangers danger_data ;;*)
let direction = ref 4 ;; let direction = ref 4 ;;
@ -1061,9 +1045,9 @@ else begin
end ;; end ;;
Printf.printf "%d %d" !direction !action ; Printf.printf "%d %d" !direction !action ;
if logg then Printf.fprintf stderr "[player %d] %d %d (at time %f)\n" game_map.player_id !direction !action game_map.dt; if 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 ;; (*set_meta_info game_map.player_id ;;*)
let __end = Unix.gettimeofday() ;; let __end = Unix.gettimeofday() ;;
if logg then Printf.fprintf stderr "Time : %f\n" (__end -. __start) ;; if logg then Printf.fprintf stderr "Time : %f\n" (__end -. __start) ;;

BIN
again.o

Binary file not shown.

BIN
audio/Night of Knights.mp3 Normal file

Binary file not shown.

Binary file not shown.

View File

@ -1,29 +1,27 @@
93.0 10.0
2 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
1 3 3 3 0 2 2 2 2 2 2 0 2 2 2 2 0 5 5 5 1 1 3 0 0 2 2 2 2 2 2 2 0 2 0 2 2 2 2 0 5 1
1 3 1 0 1 2 1 2 1 2 1 0 1 2 1 2 1 0 1 5 1 1 3 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 5 1
1 3 3 0 2 2 2 2 2 2 2 2 0 0 2 2 0 5 5 5 1 1 0 0 2 0 2 2 0 2 2 2 2 0 2 2 2 2 2 2 0 1
1 3 1 2 1 2 1 2 1 2 1 2 1 0 1 2 1 0 1 5 1 1 0 1 2 1 2 1 2 1 0 1 2 1 2 1 2 1 2 1 2 1
1 3 0 2 0 0 0 2 2 2 2 2 0 2 2 2 0 5 4 5 1 1 2 2 2 0 2 2 2 0 0 2 2 2 2 2 0 2 2 2 2 1
1 3 1 0 1 6 1 2 1 2 1 2 1 2 1 0 1 5 1 5 1 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 0 1 2 1 2 1
1 6 6 6 6 6 2 0 2 0 2 2 0 2 2 5 5 5 5 5 1 1 2 2 2 2 0 2 2 2 2 0 2 0 2 2 2 0 2 2 2 1
1 3 1 6 1 6 1 2 1 2 1 2 1 2 1 2 1 5 1 4 1 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 0 1 2 1 2 1
1 6 6 6 6 6 6 0 2 2 0 2 0 2 0 5 5 4 5 5 1 1 0 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 0 1
1 6 1 6 1 6 1 2 1 0 1 2 1 2 1 2 1 4 1 4 1 1 6 1 0 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 4 1
1 6 6 6 6 6 6 0 2 2 2 2 2 2 5 5 5 5 5 4 1 1 6 0 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 0 4 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
2 4
11 19 2 94.5 1 3 1 12.5
9 18 2 97.5 11 18 1 12.5
2 1 18 1 12.5
9 17 1 0 1 1 1 2 11 2 1 12.5
9 19 2 0 0 2 0 0 4
6 3 1 0 0 0 1 0 0
1 4 0 9 19 1 0 0 1 0 1
9 7 0 3 19 2 0 1 1 0 0
11 7 3 9 1 3 0 0 1 0 0
6 3 0 0
5 5 3
4 17 3

View File

@ -62,6 +62,8 @@ from copy import deepcopy
import subprocess import subprocess
from tkinter import * from tkinter import *
import os import os
from playsound import playsound
from threading import Thread
def attente(vitesse): def attente(vitesse):
return TEMPS_BASE * 0.9**vitesse return TEMPS_BASE * 0.9**vitesse
@ -413,6 +415,8 @@ def execute_evenement(evenements, evenement, plateau, plateauCouleur, bombes, jo
return return
elif plateau[i][j]==PLATEAU_BOIS: elif plateau[i][j]==PLATEAU_BOIS:
# Bois : destructible, on détruit # Bois : destructible, on détruit
'''CTS[CTPTR].start()
CTPTR = (CTPTR+1)%12'''
casse(plateau, powerups, i,j) casse(plateau, powerups, i,j)
return return
else: else:
@ -461,6 +465,23 @@ Y_STEP_CLAIMS = 40
X_LARGEUR_EMPIRES = 60 X_LARGEUR_EMPIRES = 60
Y_LARGEUR_EMPIRES = 180 Y_LARGEUR_EMPIRES = 180
'''
CT1= Thread(target=play_planks)
CT2= Thread(target=play_planks)
CT3= Thread(target=play_planks)
CT4= Thread(target=play_planks)
CT5= Thread(target=play_planks)
CT6= Thread(target=play_planks)
CT7= Thread(target=play_planks)
CT8= Thread(target=play_planks)
CT9= Thread(target=play_planks)
CT10= Thread(target=play_planks)
CT11= Thread(target=play_planks)
CT12= Thread(target=play_planks)
CTS=[CT1, CT2, CT3, CT4, CT5, CT6, CT7, CT8, CT9, CT10, CT11, CT12]
CTPTR=0
'''
def decision(programme, indiceJoueur, plateau, plateauCouleur, bombes, joueurs, powerups, instant): def decision(programme, indiceJoueur, plateau, plateauCouleur, bombes, joueurs, powerups, instant):
with open("entrees.txt", "w") as entrees: with open("entrees.txt", "w") as entrees:
print(instant, file=entrees) print(instant, file=entrees)
@ -543,6 +564,8 @@ def simulation(strategies):
fenetre.mainloop() fenetre.mainloop()
return return
def play_planks():
playsound('./audio/wood-effect-254997.mp3')
#simulation(["./again"]) #simulation(["./again"])
#simulation(["./again", "./again"]) #simulation(["./again", "./again"])
simulation(["./again", "./again", "./again", "./again"]) simulation(["./again", "./again", "./again", "./again"])

View File

@ -1 +0,0 @@
1

View File

@ -1 +0,0 @@
1

View File

@ -1 +0,0 @@
1

View File

@ -1 +0,0 @@
1

View File

@ -1 +1 @@
0 0 4 0