override protected void MainThread() { Node2048 n = new Node2048().GetRandomChild(false); PrintLine(n.ToString()); while (!n.IsTerminal(true)) { IEnumerable<Node> moves = n.Children(true); Node2048 best = (Node2048)moves.First(); int record = 0; foreach (var move in moves) { int empty = (n.EmptyTiles() <= 1) ? 2 : n.EmptyTiles(); int depth = Math.Max(1, Math.Min(MAX_DEPTH, (int)(4 * Math.Log(5, empty)))); depth = 5; int score = new AlphaBeta(true).Iterate(move, depth, int.MinValue, int.MaxValue, true); if (score > record) { best = (Node2048)move; record = score; } } n = best; PrintLine(n.ToString()); //ReadLine(); n = n.GetRandomChild(false); PrintLine(n.ToString()); //ReadLine(); } PrintLine("Done"); while (true) PrintLine(ReadLine()); }
private Node2048 Clone() { Node2048 n = new Node2048(); for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; ++j) { n.board[i, j] = board[i, j]; } } return n; }