예제 #1
0
 public TurnInfo FieldAssess(GameModel terget, IgnitionResultAppraise ira)
 {
     TurnInfo result = new TurnInfo();
     MainField field = terget.Main;
     terget.CopyTo(gmCache);
     for (int x = 0; x < W; x++)
     {
         int top, bottom, maxNum;
         bottom = field.GetEarthPoint(x);
         top = bottom - 0;
         maxNum = S / 2;
         if (field.GetEarthPoint(x - 1) >= bottom || field.GetEarthPoint(x + 1) >= bottom)
         {
             //bottom++;
             //if (bottom >= field.Height) bottom = field.Height - 1;
             //maxNum = S;
         }
         for (int y = top; y <= bottom; y++)
         {
             for (int n = 1; n <= maxNum; n++)
             {
                 TurnInfo now = gmCache.IgnitionPointForwardStep(n, x, y);
                 terget.CopyTo(gmCache, now.ChangeRect);
                 ira(ref result, now);
             }
         }
     }
     return result;
 }
예제 #2
0
 protected SearchStorage(GameModel gm, int nowLevel, long boaderScore)
 {
     GMC = new GameModelCache(nowLevel, gm);
     NowLevel = nowLevel;
     BoaderScore = boaderScore;
     MinimaxScore = long.MinValue;
     CallCount = 0;
     resultInfo = new TurnInfo();
 }
예제 #3
0
 private void LoadedHandler(object sender, RoutedEventArgs e)
 {
     StringReader sr = GenerateInput.SmallGenerate(new Random(0), 100);
     gm = GameModel.ReadGameModel(sr);
     //ai = new TestAI(gm);
     //ai = new TargetAI(gm, 3, false);
     ai = new IgnitionAI(gm, 2, true);
     //ai = new FireAI(gm, 2, false);
     //ai = new SwitchingAI(gm, 2, 10);
     CompositionTarget.Rendering += RenderingHandler;
 }
예제 #4
0
 public IgnitionPointAssess(GameModel gm)
 {
     W = gm.Main.Width;
     H = gm.Main.Height;
     S = gm.Setting.S;
     T = gm.Setting.T;
     gmCache = gm.Clone();
     lightScoreCache = new long[S + 1];
     sumCache1 = new int[S];
     sumCache2 = new int[S];
 }
예제 #5
0
 public GameModelCache(int maxLevel, GameModel gm)
 {
     Level = 0;
     cache = new GameModel[maxLevel + 1];
     change = new Rect[maxLevel + 1];
     for (int i = 0; i <= maxLevel; i++)
     {
         cache[i] = gm.Clone();
     }
     NextLevel();
 }
예제 #6
0
 public void CopyTo(GameModel to, Rect rect)
 {
     to.Turn = Turn;
     to.Score = Score;
     to.RawScore = RawScore;
     to.ExtraScore = ExtraScore;
     to.FireCount = FireCount;
     to.MaxChain = MaxChain;
     to.MaxSameErase = MaxSameErase;
     Main.CopyTo(to.Main, rect);
 }
예제 #7
0
 public IgnitionAI(GameModel gm, int maxLevel, bool parallel = true)
     : base(gm, maxLevel, parallel)
 {
     W = gm.Setting.W;
     H = gm.Setting.H;
     T = gm.Setting.T;
     P3 = gm.Setting.P * 3;
     FieldArea = W * H;
     int a = (FieldArea - P3) / 2;
     targetErase = a + P3;
     targetChain = a / 3;
 }
예제 #8
0
 public TurnInfo NextControl(GameModel gm, out int cx, out int cr)
 {
     TurnInfo turnInfo;
     if (gm.Turn < 500)
     {
         turnInfo = fire.NextControl(gm, out cx, out cr);
     }
     else
     {
         turnInfo = standard.NextControl(gm, out cx, out cr);
     }
     return turnInfo;
 }
예제 #9
0
 public BranchAndBoundIDDFS(GameModel gm, int maxLevel, bool parallel)
 {
     this.maxLevel = maxLevel;
     this.parallel = parallel;
     W = gm.Setting.W;
     T = gm.Setting.T;
     rankBoader = new int[maxLevel + 1];
     rootNode = new AppraisalTree();
     int rank = (W + T - 1) * 4 - 1;
     for (int i = 1; i <= maxLevel; i++)
     {
         if (rank < 1) rank = 1;
         rankBoader[i] = rank;
         rank /= 1;
     }
 }
예제 #10
0
파일: Program.cs 프로젝트: B-head/CodeVS2.1
 public static GameAI SerectAI(GameModel gm)
 {
     if (gm.Setting.W == 10)
     {
         return new SwitchingAI(gm, 2, 4);
     }
     else if (gm.Setting.W == 15)
     {
         return new SwitchingAI(gm, 2, 4);
     }
     else if (gm.Setting.W == 20)
     {
         return new SwitchingAI(gm, 2, 4);
     }
     else
     {
         throw new ApplicationException();
     }
 }
예제 #11
0
 public IgnitionStorage(GameModel gm, int nowLevel, long boaderScore)
     : base(gm, nowLevel, boaderScore)
 {
     ipa = new IgnitionPointAssess(gm);
 }
예제 #12
0
파일: FireAI.cs 프로젝트: B-head/CodeVS2.1
 public FireAI(GameModel gm, int maxLevel, bool parallel = true)
     : base(gm, maxLevel, parallel)
 {
     Th = gm.Setting.Th;
 }
예제 #13
0
 public SwitchingAI(GameModel gm, int maxLevel1, int maxLevel2)
 {
     fire = new FireAI(gm, maxLevel1);
     standard = new IgnitionAI(gm, maxLevel2);
 }
예제 #14
0
 public void CopyTo(GameModel to)
 {
     Rect rect = new Rect() { Left = 0, Top = 0, Right = Main.Width - 1, Bottom = Main.Height - 1 };
     CopyTo(to, rect);
 }
예제 #15
0
파일: Utility.cs 프로젝트: B-head/CodeVS2.1
 public TestAI(GameModel gm)
 {
     X = gm.Setting.W - gm.Setting.T + 1;
     random = new Random(1);
 }
예제 #16
0
 protected override SearchStorage CreateLocalStorage(GameModel gm, int nowLevel, long boaderScore)
 {
     return new IgnitionStorage(gm, nowLevel, boaderScore);
 }
예제 #17
0
 public TurnInfo NextControl(GameModel gm, out int cx, out int cr)
 {
     long callCount = 0, boaderScore = 0;
     int nowLevel = 0, ci = 0;
     TurnInfo turnInfo = new TurnInfo();
     try
     {
         while (!MaxToControl(out ci, boaderScore) && nowLevel++ < maxLevel)
         {
             if (!parallel)
             {
                 SearchStorage ss = CreateLocalStorage(gm, nowLevel, boaderScore);
                 turnInfo = SearchNode(rootNode, 0, ss);
                 boaderScore = ss.MinimaxScore;
                 callCount = ss.CallCount;
             }
             else
             {
                 long minScore = long.MaxValue;
                 long minimaxScore = 0;
                 SpinLock sl = new SpinLock();
                 if (!rootNode.IsExistChild())
                 {
                     rootNode.GenerateChild(W, T);
                 }
                 ParallelLoopResult plr = Parallel.For<SearchStorage>(0, rootNode.Length,
                     () => CreateLocalStorage(gm, nowLevel, boaderScore),
                     (index, state, local) =>
                     {
                         local.MinimaxScore = long.MinValue;
                         local.CallCount = 0;
                         Debug.Assert(local.GMC.Level == 1);
                         local.resultInfo = AppraiseNode(rootNode[index], 1, 0, local);
                         return local;
                     },
                     (local) =>
                     {
                         bool lockTaken = false;
                         while (!lockTaken) sl.Enter(ref lockTaken);
                         if (turnInfo.AppraisalScore < local.resultInfo.AppraisalScore)
                         {
                             turnInfo = local.resultInfo;
                         }
                         if (local.resultInfo.AppraisalScore >= local.BoaderScore)
                         {
                             minScore = Math.Min(minScore, local.resultInfo.AppraisalScore);
                         }
                         minimaxScore = Math.Max(minimaxScore, local.MinimaxScore);
                         callCount += local.CallCount;
                         sl.Exit();
                     }
                 );
                 Debug.Assert(plr.IsCompleted);
                 if (minScore < long.MaxValue)
                 {
                     boaderScore = Math.Max(minimaxScore, minScore);
                 }
                 else
                 {
                     boaderScore = minimaxScore;
                 }
             }
             Trace.TraceInformation("Turn {0}, Level {1}, CallCount {2}, BoaderScore {3}, {4}, {5}",
                 gm.Turn + 1, nowLevel, callCount, boaderScore, turnInfo.ToString(), rootNode.ToString());
         }
     }
     catch (OutOfMemoryException e)
     {
         Trace.TraceWarning("{0}", e.ToString());
     }
     if (ci != -1)
     {
         rootNode = rootNode[ci];
         cx = rootNode.CX;
         cr = rootNode.CR;
     }
     else
     {
         rootNode = new AppraisalTree();
         cx = 0; cr = 0;
     }
     return turnInfo;
 }
예제 #18
0
 protected abstract TurnInfo AppraiseFunction(GameModel current, SearchStorage ss);
예제 #19
0
 protected abstract SearchStorage CreateLocalStorage(GameModel gm, int nowLevel, long boaderScore);
예제 #20
0
 protected override TurnInfo AppraiseFunction(GameModel current, SearchStorage ss)
 {
     IgnitionStorage ign = (IgnitionStorage)ss;
     return ign.ipa.FieldAssess(current, ResultAppraise);
 }
예제 #21
0
파일: Utility.cs 프로젝트: B-head/CodeVS2.1
 public TurnInfo NextControl(GameModel gm, out int cx, out int cr)
 {
     cx = random.Next(X);
     cr = random.Next(4);
     return new TurnInfo();
 }