Volver al índice

src/main/java/ar/com/companeros/runtime/DecisionProgress.java

package ar.com.companeros.runtime;

import ar.com.companeros.decision.ObservationSnapshot;
import java.util.TreeMap;

/** El éxito de inspect no equivale a avanzar: comparar consecuencias observables. */
public final class DecisionProgress {
    private String previous = "";
    private int unchanged;

    // Ignorar reloj, redacción del objetivo y resultados repetidos de la misma inspección.
    public int observe(ObservationSnapshot state) {
        String current = state.worldId() + ":" + state.dimension() + ":" + state.x() + ":" + state.y() + ":" + state.z()
            + ":" + state.health() + ":" + state.hunger() + ":" + new TreeMap<>(state.inventory())
            + ":" + state.observations().stream().filter(value -> value.startsWith("visible_block=")
                || value.startsWith("hazard=") || value.startsWith("floor_support=")
                || value.startsWith("visible_safe_step=") || value.startsWith("hostile=")).sorted().toList();
        unchanged = current.equals(previous) ? unchanged + 1 : 0;
        previous = current;
        return unchanged;
    }
}