export class ArenaGroom { constructor(arenaCnx, storage, debug = false) { this.cnx = arenaCnx this.storage = storage this.debug = debug } agentHashKey(agentId) { return(this.storage.agentHashKey.replace(/\[UID\]/g, agentId)) } async clearArena() { const ids = await this.cnx.redisSmembers(this.storage.agentsIndexKey) for(const id of ids) { await this.cnx.redisDel(this.agentHashKey(id)) } await this.cnx.redisDel(this.storage.agentsIndexKey) if(this.debug) console.log(`[Maestro] Cleared arena store (${ids.length} agent(s))`) } async seedAgents(agents) { for(const agent of agents) { const key = this.agentHashKey(agent.id) await this.cnx.redisHset(key, 'position', agent.position) await this.cnx.redisHset(key, 'vector', agent.vector) await this.cnx.redisSadd(this.storage.agentsIndexKey, agent.id) } if(this.debug) console.log(`[Maestro] Groomed ${agents.length} agent(s) into arena store`) } }