public bool expandNode(UCBNode n) { List<Point> kouho = nextMove(n.board); if (kouho.Count == 0) { UCBNode c = new UCBNode(); c.board = new Board(n.board); Info.GameState s=c.board.play(Point.Pass); if (s == Info.GameState.END_GAME) { return false; } c.parent = n; n.children.Add(c); return true; } foreach (Point p in kouho) { UCBNode c = new UCBNode(); c.board = new Board(n.board); c.board.play(p); c.parent = n; n.children.Add(c); } return true; }
public UCBNode() { win = 0; iteration = 0; parent = null; children = new List<UCBNode>(); }
public Point play(Board board) { List<Point> kouho = nextMove(board); if(kouho.Count==0) { return Point.Pass; }else if(kouho.Count==1) { return kouho[0]; } root = new UCBNode(); root.board = new Board(board); expandNode(root); for(int i=0;i< iteration;++i) { List<UCBNode> list = new List<UCBNode>(); UCBNode n = root; while(n!= null) { list.Add(n); n = n.maxUCB(root.iteration); } Board tmp = list.Last().board; bool black_win = onePlayOut(tmp); foreach (UCBNode j in list) { if(j.board.turn==1 && black_win) { j.win++; } if(j.board.turn==0 && (!black_win)) { j.win++; } j.iteration++; } if(list.Last().iteration >= 20) { expandNode(list.Last()); } } UCBNode m=root.children[0]; int win = -1; foreach(UCBNode i in root.children) { if(i.win > win) { m = i; win = i.win; } } return m.board.points.Last(); }