12345678910111213141516171819202122232425262728293031323334353637383940414243444546(* Claude Code
*
* Copyright (C) 2026 Yoann Padioleau
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public License
* (LGPL) as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
*)(* See Sense.mli *)type'vtarget={visible:bool;audible:bool;position:'voption;age:int;seen_for:int}letunknown:'vtarget={visible=false;audible=false;position=None;age=0;seen_for=0}letupdate?(sight=Float.infinity)?(hearing=0.)~(distance:float)~(clear:bool)~(position:'v)(t:'vtarget):'vtarget=letvisible=clear&&distance<=sightin{visible;audible=distance<=hearing;position=(ifvisiblethenSomepositionelset.position);age=(ifvisiblethen0elset.age+1);seen_for=(ifvisiblethent.seen_for+1else0);}letlost(t:'vtarget):bool=(nott.visible)&&t.position=Noneletforget~(after:int)(t:'vtarget):'vtarget=if(nott.visible)&&t.age>afterthen{twithposition=None}elsetletnearest(targets:(float*'vtarget)list):'vtargetoption=List.filter(fun(_,t)->t.visible)targets|>List.sort(fun(a,_)(b,_)->compareab)|>function|(_,t)::_->Somet|[]->Noneletfocus(targets:(float*'vtarget)list):'vtargetoption=matchnearesttargetswith|Somet->Somet|None->(List.filter(fun(_,t)->t.position<>None)targets|>List.sort(fun(_,a)(_,b)->comparea.ageb.age)|>function|(_,t)::_->Somet|[]->None)