import { deepMerge } from '../utils/DeepMerge' ; import { DeepPartial } from '../utils/DeepPartial' ; import { deepCopy } from '../utils/DeepCopy' ; import { Match } from '../Match' ; import { MatchEngine } from '../MatchEngine' ; import { Logger } from '../Logger' ; ignore import EngineOptions = MatchEngine . EngineOptions ; ignore import Command = MatchEngine . Command ; class classdesc Abstract class detailing a Design to be used as the platform that holds match lifecycle logic for
 * updating and manipulating ongoing matches
 *
 * Refer to  Match class and the  Agent for exposed fields available for user's use when making your own
 * Design
 *
 * The important functions to implement are  initialize ,  update , and  getResults export abstract class Design { /** The current design options */ protected designOptions : DesignOptions ; /** Logger */ public log = new Logger ( ) ; param name param designOptions constructor ( public name , designOptions = { } ) { this . designOptions = deepCopy ( DefaultDesignOptions ) ; deepMerge ( this . designOptions , designOptions ) ; this . log . detail ( `Design + MatchEngine Options` , this . designOptions ) ; this . log . level = Logger . LEVEL . INFO ; this . log . system ( `Initialized Design: ` + this . name ) ; } param level setLogLevel ( level ) { this . log . level = level ; } /**
     * Get the design options associated with this `Design`
     */ getDesignOptions ( ) { return this . designOptions ; } see Agent for what properties and methods related to agents are exposed to the user for use.
     *  see Match for what properties and methods are exposed to the user for use e.g match.send() and match.state
     *
     *  param match - The  Match to initialize state with
     *  returns abstract initialize ( match ) ; /**
     * Abstract function required to update match state with commands from Agents and send commands to Agents
     * along with returning the current match status. Returning  Match . Status . RUNNING indicates the match is not done yet.
     * Returning  Match . Status . FINISHED indicates the match is over.
     *
     *  see Match - This function is used by the match to update the match state and move forward a time step
     *  see Agent for what properties and methods related to agents are exposed to the user for use.
     *  see Match . Status for different statuses you can return.
     *
     *  param match param commands - The  MatchEngine . Command array used to update the state in a Match.
     *                   Each element has two keys, command and agentID. agentID is the id of the agent that outputted
     *                   that string in command
     *  returns A promise that resolves with the current  Match . Status at the end of this time step. Can also
     * directly just return the match status
      abstract update ( match , commands ) ; /**
     * Abstract function required to get the result of a  Match .
     *
     *  see Match - This function is used by the match to update the results stored in the match and return
     * results
     *
     *  see Tournament - This function is used to return results from a match and then is fed into a resultHandler
     * for a particular rankingSystem and tournament type.
     *
     *  param match param config returns abstract getResults ( match ) ; /**
     * Creates a Design class wrapper around a custom design written without the use of Dimensions framework
     */ public static createCustom ( name , overrideOptions ) { return new CustomDesign ( name , overrideOptions ) ; } } /**
 * This class is meant for wrapping around existing designs built without the use of Dimensions framework
 *
 * This is created so a user provided non-dimension framework based design can be used within the Dimensions framework
 * and leverage other features such as tournament running, an API for viewing relevant data, and automatic, scalable
 * competition running
 */ class CustomDesign extends Design { constructor ( name , overrideOptions ) { overrideOptions . active = true ; super ( name , { override : overrideOptions , } ) ; } /**
     * Initializer. Declares any relevant state fields
     */ async initialize ( match ) { match . state = { matchOutput : [ ] , } ; match . results = [ ] ; return ; } /**
     * Empty function, not used
     */ async update ( ) { return ; } /**
     * Returns the results stored.  MatchEngine . runCustom should automatically populate match.results for us and so
     * we just return itt.
     *  param match async getResults ( match ) { return match . results ; } } /**
 * Design options. Allows for the setting of engine options and override options.
 */ export interface DesignOptions { /**
     * The default engine options to use for all matches created using this design. Engine options impact how the engine
     * works at the I/O level and dictates how your engine prohibits and enables an  Agent in a  Match to
     * communicate and send commands and receive commands.
     *
     * This overrides the default engine options from the  MatchEngine class, and is overided by tournament
     * level, and then match level configs.
      engineOptions ? : EngineOptions ; /**
     * Override configurations if a user wants to run matches with a non-dimensions based design and run their own design
     * This is what allows users to write competition designs in their own programming language and utilize Dimensions
     * features such as tournament running, database plugins, scalability, and much more automation.
     */ override : Design . OverrideOptions ; } /**
 * Default Design Options
 */ export const DefaultDesignOptions = { override : { active : false , command : 'echo NO COMMAND PROVIDED' , conclude_command : 'D_MATCH_FINISHED' , arguments : [ ] , timeout : 1000 * 60 * 10 , resultHandler : null , } , } ; export namespace Design { /**
     * The override options interface
     * This is used to provide configurations for a custom  Design outside the scope and infrastructure of
     * Dimensions
      export interface OverrideOptions { default default active : boolean ; example example default command : string ; /**
         * An array of arguments to pass in to the script command
         * NOTE, there are a few special strings when put into this array, will be populated with dynamic data.
         *
         * See  MatchEngine . DynamicDataStrings for what is available and what they do
         *
         *  example arguments : Array < string | MatchEngine . DynamicDataStrings > ; default conclude_command : string ; default timeout : number ; /**
         * The result handler to handle results returned by the command provided in the  OverrideOptions .
         *
         * If the result handler returns an object with the key `replayFile`, Dimensions will recognize the string
         * in that key as the replay file location.
         *
         * If a  Storage plugin is used, the replay file is uploaded and the local fle is deleted
          resultHandler : ( results : Array < string > ) => any ; } }