#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Oracle physique vs graphe NavMesh : distinguer l'isolation RÉELLE (l'ennemi ne peut physiquement pas y aller) des liens manquants (le graphe rate une route physiquement praticable : marche / chute par bord / saut <=3 lignes). """ import sys sys.path.insert(0, "tools/sim") from collections import deque from navmesh_connectivity import load_segments, generate_map, NavMeshSim, standable def physical_reachable(sim, start, max_jump_up=3, max_jump_dx=2): """BFS généreux : marche, chute (bord -> plancher en dessous, dérive ±1 col), saut (montée <= max_jump_up lignes, décalage <= max_jump_dx colonnes).""" W, H = sim.W, sim.H seen = {start} q = deque([start]) while q: (i, j) = q.popleft() # marche : voisins debout même ligne for d in (-1, 1): n = (i + d, j) if 0 <= n[0] < W and n in seen or not (0 <= n[0] < W): continue if standable(sim, *n): seen.add(n) q.append(n) # chute : marcher hors du bord -> plancher le plus bas sous les colonnes i, i±1 for d in (0, 1, -1): c = i + d if not (0 <= c < W): continue # il faut du vide devant au niveau de la tête et du corps (marcher hors bord) if not sim.coll(c, j): # descend la colonne c jusqu'au prochain sol r = j + 1 while r < H - 1 and not sim.coll(c, r): r += 1 # atterrit sur (c, r-1) si debout cand = (c, r - 1) if standable(sim, *cand) and cand not in seen: seen.add(cand) q.append(cand) # saut : montée <= max_jump_up, décalage <= max_jump_dx for dc in range(-max_jump_dx, max_jump_dx + 1): for up in range(1, max_jump_up + 1): n = (i + dc, j - up) if not (0 <= n[0] < W and n[1] >= 1): continue if n in seen: continue if standable(sim, *n): # trajectoire : pas de mur dans la colonne de départ au niveau du corps/tête if sim.coll(i, j - 1) or sim.coll(i, j - up): continue seen.add(n) q.append(n) return seen def main(): n_seeds = int(sys.argv[1]) if len(sys.argv) > 1 else 6 segs = load_segments() tot = {"phys_ok": 0, "nav_ok": 0, "nav_rate_mais_phys_ok": 0, "isolation_reelle": 0} exemples = [] for k in range(n_seeds): seed = 1_000_000 + k * 7919 solid, _, _ = generate_map(seed, segs) sim = NavMeshSim(solid) sim.init((20.0, 20.0), fix_notch=True, fix_left_bound=True) stand = [(i, j) for i in range(sim.W) for j in range(sim.H) if standable(sim, i, j)] # échantillon de couples quasi-verticaux (ennemi au-dessus, 1..15 lignes) import random rnd = random.Random(seed) pairs = [] for _ in range(400): (ei, ej) = stand[rnd.randrange(len(stand))] (pi, pj) = stand[rnd.randrange(len(stand))] if 1 <= pj - ej <= 15 and abs(pi - ei) <= 10: pairs.append(((ei, ej), (pi, pj))) for (e, p) in pairs: en, pn = sim.nav[e[0]][e[1]], sim.nav[p[0]][p[1]] nav_ok = len(sim.get_path(en, pn)) > 0 phys = physical_reachable(sim, e) phys_ok = p in phys if nav_ok: tot["nav_ok"] += 1 tot["phys_ok"] += 1 elif phys_ok: tot["nav_rate_mais_phys_ok"] += 1 if len(exemples) < 6: exemples.append((seed, e, p)) else: tot["isolation_reelle"] += 1 tot["phys_ok"] += 0 s = sum(tot.values()) print("couples testés : %d" % s) print(" nav OK : %d (%.1f%%)" % (tot["nav_ok"], 100.0 * tot["nav_ok"] / s)) print(" nav ÉCHOUÉ mais PHYSIQUEMENT possible : %d (%.1f%%) <- liens manquants" % (tot["nav_rate_mais_phys_ok"], 100.0 * tot["nav_rate_mais_phys_ok"] / s)) print(" isolation réelle (physiquement absent): %d (%.1f%%)" % (tot["isolation_reelle"], 100.0 * tot["isolation_reelle"] / s)) print("exemples de liens manquants :") for (seed, e, p) in exemples: print(" seed=%d ennemi=%s joueur=%s" % (seed, e, p)) if __name__ == "__main__": main()