export class ArenaGroom { constructor(arenaCnx, arenaStorage, debug = false) { this.cnx = arenaCnx this.arenaStorage = arenaStorage this.debug = debug } agentHashKey(agentId) { return(this.arenaStorage.agentHashKey.replace(/\[UID\]/g, agentId)) } async clearArena() { const ids = await this.cnx.redisSmembers(this.arenaStorage.agentsIndexKey) for(const id of ids) { await this.cnx.redisDel(this.agentHashKey(id)) } await this.cnx.redisDel(this.arenaStorage.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.arenaStorage.agentsIndexKey, agent.id) } if(this.debug) console.log(`[Maestro] Groomed ${agents.length} agent(s) into arena store`) } }