コード例 #1
0
        /// <summary>
        /// Loads the AI for the chess player. If the AI is already loaded, it will just return.
        /// </summary>
        /// <param name="player"></param>
        void LoadAI(ChessPlayer player)
        {
            if (player.IsHuman)
            {
                // Player is a human, so we don't need to load an AI.
                return;
            }
            else if (player.AI != null)
            {
                // AI has already been loaded, so return
                return;
            }

            AI tmpAI = null;

            foreach (AI t in DllLoader.AvailableAIs)
            {
                if (t.ShortName == player.AIName)
                {
                    tmpAI = t;
                    break;
                }
            }
            System.Reflection.Assembly assem = System.Reflection.Assembly.LoadFile(tmpAI.FileName);
            IChessAI ai = (IChessAI)assem.CreateInstance(tmpAI.FullName);

            player.AI = ai;
        }
コード例 #2
0
        static void LoadAIsFromFile(string filename)
        {
            try
            {
                System.Reflection.Assembly assem = System.Reflection.Assembly.LoadFile(filename);
                System.Type[] types = assem.GetTypes();

                foreach (System.Type type in types)
                {
                    System.Type[] interfaces = type.GetInterfaces();

                    foreach (System.Type inter in interfaces)
                    {
                        if (inter == typeof(UvsChess.IChessAI))
                        {
                            IChessAI ai  = (IChessAI)assem.CreateInstance(type.FullName);
                            AI       tmp = new AI(ai.Name);
                            tmp.FileName = filename;
                            tmp.FullName = type.FullName;
                            _availableais.Add(tmp);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Log("Chess->MainForm->LoadAI: " + ex.Message);
            }
        }
コード例 #3
0
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='gameXml'>
 /// </param>
 /// <param name='timeLimitInSecs'>
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task <string> PostByGamexmlAndTimelimitinsecsAsync(this IChessAI operations, StringAux gameXml, int timeLimitInSecs, CancellationToken cancellationToken = default(CancellationToken))
 {
     using (var _result = await operations.PostByGamexmlAndTimelimitinsecsWithHttpMessagesAsync(gameXml, timeLimitInSecs, null, cancellationToken).ConfigureAwait(false))
     {
         return(_result.Body);
     }
 }
コード例 #4
0
        public ChessAI(string aiName)
        {
            List <string> aiNames = new List <string>();

            foreach (var dllFilePath in Directory.GetFiles(Environment.CurrentDirectory, "*.dll"))
            {
                var asm = Assembly.LoadFrom(dllFilePath);

                foreach (var type in asm.GetTypes())
                {
                    if (type.GetInterfaces().Contains(typeof(IChessAI)))
                    {
                        var fwai = (IChessAI)Activator.CreateInstance(type);
                        aiNames.Add(fwai.Name);
                        if (fwai.Name.Equals(aiName))
                        {
                            ai = fwai;
                            break;
                        }
                    }
                }
            }

            if (ai == null)
            {
                throw new Exception($"Could not find AI {aiName}. Here's a list of the available ai's:\n{string.Join("\n", aiNames)}");
            }
        }
コード例 #5
0
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='gameXml'>
 /// </param>
 /// <param name='timeLimitInSecs'>
 /// </param>
 public static string PostByGamexmlAndTimelimitinsecs(this IChessAI operations, StringAux gameXml, int timeLimitInSecs)
 {
     return(Task.Factory.StartNew(s => ((IChessAI)s).PostByGamexmlAndTimelimitinsecsAsync(gameXml, timeLimitInSecs), operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult());
 }