Ejemplo n.º 1
0
        private static void CompileNode(GoGame game, SGFTree tree)
        {
            var singleBranch = true;

            while (singleBranch)
            {
                if (IsMoveNode(tree))
                {
                    var node = new GoMoveNode(game.CurrentNode,
                                              FindStone(tree),
                                              game.MoveNumber % BoardStorageStepConfiguration == 0);

                    game.AddNode(node);
                }
                else
                {
                    GoSetupNode node;
                    if (game.CurrentNode is GoRootNode && useRoot)
                    {
                        node = game.CurrentNode as GoRootNode;
                    }
                    else
                    {
                        node = new GoSetupNode(game.CurrentNode);
                    }

                    foreach (var property in tree.Properties)
                    {
                        var name = property.Name.ToUpper();
                        switch (name)
                        {
                        case "AB":
                        case "AW":
                            foreach (var stone in CompilePointValues(property.Value))
                            {
                                stone.IsBlack = name == "AB";
                                node.AddStone(stone);
                            }
                            break;

                        case "AE":
                            foreach (var stone in CompilePointValues(property.Value))
                            {
                                node.RemoveStone(stone);
                            }
                            break;

                        case "PL":
                            node.SetPlayer(property.Value.StartsWith("B"));
                            break;
                        }
                    }
                    if (!(game.CurrentNode is GoRootNode && useRoot))
                    {
                        game.AddNode(node);
                    }
                    else
                    {
                        useRoot = false;
                    }
                }
                CompileProperties(game.CurrentNode, tree);

                if (tree.ChildNodes.Count == 1)
                {
                    tree = tree.ChildNodes[0];
                }
                else
                {
                    singleBranch = false;
                }
            }

            var move = game.MoveNumber;

            foreach (var branch in tree.ChildNodes)
            {
                CompileNode(game, branch);
                game.ToMove(move);
            }
        }