示例#1
0
        public static Path GetBestPath(Board b, Options o)
        {
            Path bestPath = new Path();
            object pathLock = new Object();

            Parallel.For(0, b.Height, i =>
            {
                //for (int i = 0; i < b.Height; i++)
                Parallel.For(0, b.Width, j =>
                {
                    //for (int j = 0; j < b.Width; j++)
                    var curPath = GetBestPathFrom(b, o, i, j);
                    lock (pathLock)
                    {
                        if (curPath.Score > bestPath.Score)
                            bestPath = curPath;
                    }
                    var c = b.GetBoardsAfterPath(curPath.Start.Item1, curPath.Start.Item2, curPath.Actions);
                    var curPath2 = GetBestPathFrom(c.Item1, o, curPath.Current.Item1, curPath.Current.Item2);
                    var actions = new List<int[]>(curPath.Actions);
                    actions.AddRange(curPath2.Actions);
                    curPath2.Actions = actions;
                    lock (pathLock)
                    {
                        if (curPath2.Score > bestPath.Score)
                            curPath = bestPath = new Path
                            {
                                Start = curPath.Start,
                                Current = curPath2.Current,
                                Depth = curPath.Depth + curPath2.Depth,
                                Score = curPath2.Score,
                                Actions = curPath2.Actions
                            };
                    }
                });
            });

            var cc = b.GetBoardsAfterPath(bestPath.Start.Item1, bestPath.Start.Item2, bestPath.Actions);
            var bestPath2 = GetBestPathFrom(cc.Item1, o, bestPath.Current.Item1, bestPath.Current.Item2);
            var actions2 = new List<int[]>(bestPath.Actions);
            actions2.AddRange(bestPath2.Actions);
            bestPath2.Actions = actions2;
            lock (pathLock)
            {
                if (bestPath2.Score > bestPath.Score)
                    bestPath = new Path
                    {
                        Start = bestPath.Start,
                        Current = bestPath2.Current,
                        Depth = bestPath.Depth + bestPath2.Depth,
                        Score = bestPath2.Score,
                        Actions = bestPath2.Actions
                    };
            }
            return bestPath;
        }
示例#2
0
 public void Configure(IApplicationBuilder app)
 {
     app.UseMvc();
     return;
     app.Run(async (context) =>
     {
         try {
             Board b = new Board(4, 4);
             Array vals = Enum.GetValues(typeof(Orb));
             for (int i = 0; i < b.Height; i++)
                 for (int j = 0; j < b.Width; j++)
                 {
                     b.Orbs[i, j] = (i + j) % 2 == 0 ? Orb.Red : Orb.Blue;
                     b.Orbs[i, j] = (Orb) vals.GetValue(1 + (i + j) % 5);
                 }
             var p = DfsSolver.GetBestPath(b);
             var b2 = b.GetBoardsAfterPath(p.Start.Item1, p.Start.Item2, p.Actions);
             Board opt = SAASSolver.GetOptimalBoards(b, SAASSolver.Options.Default, BoardScorer.Options.Horus).First();
             var b3 = new Board(opt);
             b3.GetCombos(false);
             var p2 = SAASSolver.GetBestPath(b, SAASSolver.Options.Default, BoardScorer.Options.Horus);
             var b4 = b.GetBoardsAfterPath(p2.Start.Item1, p2.Start.Item2, p2.Actions);
             //await context.Response.WriteAsync(JsonConvert.SerializeObject(p));
             //return;
             await context.Response.WriteAsync(""
                 //+ JsonConvert.SerializeObject(p)
                 //+ "\n\n\n"
                 //+ JsonConvert.SerializeObject(b)
                 //+ "\n\n\n"
                 //+ JsonConvert.SerializeObject(b2)
                 + b.ToString()
                 + b2.Item1.ToString()
                 + b2.Item2.ToString()
                 + "\n\n"
                 + b2.Item1.Score(BoardScorer.Options.Horus)
                 + "\n\nSAAS optimal:"
                 + opt.ToString()
                 + b3.ToString()
                 + "\n\n"
                 + opt.Score(BoardScorer.Options.Horus)
                 + "\n\n"
                 + JsonConvert.SerializeObject(p2)
                 + b4.Item1.ToString()
                 + b4.Item2.ToString()
             );
         }
         catch (Exception ex)
         {
             await context.Response.WriteAsync(ex.ToString());
         }
     });
 }