当前位置: 首页>>代码示例>>C#>>正文


C# Search.MinimaxDecision方法代码示例

本文整理汇总了C#中Search.MinimaxDecision方法的典型用法代码示例。如果您正苦于以下问题:C# Search.MinimaxDecision方法的具体用法?C# Search.MinimaxDecision怎么用?C# Search.MinimaxDecision使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Search的用法示例。


在下文中一共展示了Search.MinimaxDecision方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

 public static void Main(string[] args)
 {
     // TODO allow this to be configured as command line options
     // TODO put new commands in to change these settings during play
     // TODO allow player to choose which player he/she is
     var state = new AmazonState();
     var search = new Search<AmazonState, AmazonAction, int, byte, AmazonPlayer>(1000000);
     search.Builder = new AmazonBuilder();
     search.Cutoff = new AmazonCutoffTest(30 * 1000);
     search.EvalFunc = new AmazonEvaluationFunction();
     search.SuccessorFunc = new AmazonSuccessorFunction();
     search.MaxExplorations = 100;
     Console.WriteLine("Welcome to the Game of the Amazons!");
     Console.WriteLine("Program by Paul Moore: github.com/paulmoore/SimpleAI");
     Console.WriteLine("If you are stuck, try 'help'");
     Console.WriteLine(state);
     Console.WriteLine("You are player WHITE");
     Console.WriteLine("Your turn");
     while (true) {
         Console.Write("amazons> ");
         string input = Console.ReadLine();
         if (input == null) {
             break;
         }
         input = input.Trim().ToLower();
         string[] cmd = input.Split(new string[]{" ", " \t"}, StringSplitOptions.RemoveEmptyEntries);
         if (cmd.Length == 0) {
             continue;
         }
         if (cmd[0] == "quit") {
             break;
         } else if (cmd[0] == "help") {
             Console.WriteLine("Help menu:");
             Console.WriteLine("  help");
             Console.WriteLine();
             Console.WriteLine("Quitting:");
             Console.WriteLine("  quit");
             Console.WriteLine();
             Console.WriteLine("Making a move (ith row, jth column):");
             Console.WriteLine("  move i1 j1 i2 j2 ar ac");
         } else if (cmd[0] == "move") {
             try {
                 int i1 = int.Parse(cmd[1]);
                 int j1 = char.Parse(cmd[2]) - 'a';
                 int i2 = int.Parse(cmd[3]);
                 int j2 = char.Parse(cmd[4]) - 'a';
                 int ar = int.Parse(cmd[5]);
                 int ac = char.Parse(cmd[6]) - 'a';
                 AmazonAction move = new AmazonAction();
                 move.role = AmazonPlayer.WHITE;
                 move.qr = (sbyte)(i1 - 1);
                 move.qc = (sbyte)j1;
                 move.qfr = (sbyte)(i2 - 1);
                 move.qfc = (sbyte)j2;
                 move.ar = (sbyte)(ar - 1);
                 move.ac = (sbyte)ac;
                 Console.WriteLine("You want to make this move: {0}", move);
                 string errmsg = AmazonMoveValidator.Validate(state, move);
                 if (errmsg == null) {
                     state.ApplyAction(move);
                     Console.WriteLine(state);
                 } else {
                     Console.WriteLine("That move is invalid: {0}", errmsg);
                     continue;
                 }
             } catch {
                 Console.WriteLine("Usage: move i1 j1 i2 j2 ar ac");
                 continue;
             }
             try {
                 Console.WriteLine("My turn");
                 Console.WriteLine("I am thinking...");
                 AmazonAction decision = search.MinimaxDecision(state, AmazonPlayer.BLACK, AmazonPlayer.WHITE);
                 Console.WriteLine(string.Format("I made this decision: {0}", decision));
                 state.ApplyAction(decision);
                 Console.WriteLine(state);
                 Console.WriteLine("Your turn");
             } catch (Exception e) {
                 Console.WriteLine("The AI encountered an exception, the program will now close");
                 Console.WriteLine(e);
                 Console.WriteLine(e.StackTrace);
                 break;
             }
             GC.Collect();
             GC.WaitForPendingFinalizers();
         } else {
             Console.WriteLine("Unknown command: {0}", cmd[0]);
         }
     }
     Console.WriteLine("Bye!");
 }
开发者ID:paulmoore,项目名称:SimpleAI,代码行数:91,代码来源:AmazonGame.cs


注:本文中的Search.MinimaxDecision方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。