public Point(Board b,int px,int py) { board = b; x = px; y = py; color = Color.nul; }
double FAB(Board board, int d, double a, double b, out Point point) { double current = Constant.lose; List<Point> list = SortPossiblePoint(GetPossiblePoint(board)); if (d == 0) { point = list[0]; return point.Evaluate; } point = list[0]; foreach (Point p in list) { p.PurePlay(); Point bestPoint; double v = -1 * FAB(board, d - 1, -1 * b, -1 * a, out bestPoint); p.UnPurePlay(); if (v > current) { current = v; if (v > a) { a = v; point = p; } if (v >= b) break; } } return current; }
double AB(Board board, int d,double a,double b,out Point point) { List<Point> list = SortPossiblePoint(GetPossiblePoint(board)); if(d ==0) { point=list[0]; return point.Evaluate; } point = list[0]; foreach (Point p in list) { p.PurePlay(); Point bestPoint; double v = -1 * AB(board, d - 1, -1 * b, -1 * a, out bestPoint); p.UnPurePlay(); if(v>a) { a = v; point = p; } if (v >= b) return b; //break; } return a; }
// static readonly double lose =-10000; // static readonly double win = 10000; public override Point GetBestPoint(Board b) { DateTime start = DateTime.Now; int d=0; Point point = null; while(TimeLeft (start,30)) // 30秒。 { AB(b, d, Constant .lose , Constant.win, out point); d++; } return point; }
public override Point GetBestPoint(Board b) { Thread.Sleep(1000); while(b.reds .Count +b.blacks.Count <b.size *b.size ) { Random r = new Random(DateTime.Now.Millisecond); int x = r.Next(b.size ); int y = r.Next(b.size ); Point p = b[x, y]; if (p.color == Color.nul) return p; } return null; }
/// <summary> /// 在当前局面下寻找可行点。 /// </summary> /// <param name="b"></param> /// <returns></returns> public HashSet<Point> GetPossiblePoint(Board b) { HashSet<Point> points = new HashSet<Point>(); if(b.blacks.Count + b.reds.Count == 0) { Point p = new Point(b, 8, 8); points.Add(p); } else { foreach (Point p in b.blacks) { HashSet<Point> neighbors = p.GetNeighbors(); foreach(Point p2 in neighbors) { if (!points.Contains(p2)) { points.Add(p2); } } } foreach (Point p in b.reds) { HashSet<Point> neighbors = p.GetNeighbors(); foreach (Point p2 in neighbors) { if (!points.Contains(p2)) { points.Add(p2); } } } } return points; }
void init() { int boardLengh = Math.Min(this.Width, this.Height); int margine = boardLengh / (size-2); margine+=20; int cellLength = (boardLengh - 2 * margine) / (size+1); board = new Board(15, g,margine,cellLength); }
public override Point GetBestPoint(Board b) { throw new NotImplementedException(); }
/// <summary> /// 在当前局面下寻找可行点。 /// </summary> /// <param name="b"></param> /// <returns></returns> public HashSet<Point> GetPossiblePoint(Board b) { return null; }
public abstract Point GetBestPoint(Board b);