示例#1
0
 private void addUnique(ICache <string, GoNode> childNodes, string name, GoNode childNode)
 {
     if (!childNodes.Contains(name))
     {
         childNodes.Add(name, childNode);
     }
 }
示例#2
0
 public GoMoveNode(GoNode parentNode, Stone stone, bool makeBoard) : base(parentNode, makeBoard)
 {
     if (board != null)
     {
         board.Place(stone);
     }
     Stone = stone;
 }
示例#3
0
 private static void RenderShadow(this GoGame goGame, GameRenderer renderer, GoNode node)
 {
     if ((node != goGame.currentNode) && (node is GoMoveNode))
     {
         var nodeStone = (node as GoMoveNode).Stone;
         renderer.DrawShadow(nodeStone.X, nodeStone.Y, nodeStone.IsBlack);
     }
 }
示例#4
0
        public AnimatedLink InsertLink(GoNode from, GoNode to, string relation, int userFlag = 0, Object userObj = null)
        {
            AnimatedLink link = new AnimatedLink();

            link.UserFlags  = userFlag;
            link.UserObject = userObj;
            link.FromPort   = from.Ports.ToList()[1];
            link.ToPort     = to.Ports.ToList()[0];
            (link.MidLabel as GoText).Text = relation;
            goView.Document.LinksLayer.Add(link);
            return(link);
        }
示例#5
0
        public GoNode InsertNode(PointF pt, GoNode node, int userFlag = 0, Object userObj = null)
        {
            GoDocument doc = goView.Document;

            doc.StartTransaction();
            node.UserFlags  = userFlag;
            node.UserObject = userObj;
            node.Location   = pt;
            doc.Add(node);
            doc.FinishTransaction("Insert node finished");
            return(node);
        }
示例#6
0
        private void BuildGoSetupNode(GoNode node)
        {
            var      currentNode = node as GoSetupNode;
            BitPlane stones;
            var      currentBoard = currentNode.BoardCopy;
            Board    lastBoard    = null;

            if (currentNode.ParentNode != null)
            {
                lastBoard = currentNode.ParentNode.BoardCopy;
            }


            if (lastBoard == null)
            {
                stones = currentBoard.Black;
            }
            else
            {
                stones =
                    currentBoard.Black - lastBoard.Black;
            }
            if (!stones.Empty())
            {
                DecompilePlaneValue("AB", stones);
            }
            if (lastBoard == null)
            {
                stones = currentBoard.White;
            }
            else
            {
                stones =
                    currentBoard.White - lastBoard.White;
            }
            if (!stones.Empty())
            {
                DecompilePlaneValue("AW", stones);
            }
            if (lastBoard != null)
            {
                stones = (lastBoard.White - currentBoard.White).And(
                    lastBoard.Black - currentBoard.Black);
                if (!stones.Empty())
                {
                    DecompilePlaneValue("AE", stones);
                }
            }
            if (currentNode.BlackToPlay.HasValue)
            {
                b.p("PL", currentNode.BlackToPlay.Value ? "B" : "W");
            }
        }
示例#7
0
            public bool IsRightVariant(GoNode node)
            {
                while (node.ChildNodes.Count == 1)
                {
                    node = node.ChildNodes[0];
                }

                if (!node.HasChildren)
                {
                    return
                        (node.Comment != null &&
                         node.Comment.IndexOf("RIGHT") >= 0);
                }
                else
                {
                    return(node.ChildNodes.Exists(IsRightVariant));
                }
            }
示例#8
0
        private static void CompileProperties(GoNode node, SGFTree tree)
        {
            foreach (var property in tree.Properties)
            {
                var name = property.Name.ToUpper();
                switch (name)
                {
                case "C":
                    node.Comment += AntiUnixRegex.Replace(property.Value, "\r\n");
                    break;

                case "LB":
                    node.EnsureMarkup();
                    node.Markup.Labels.Add(CompileLabelValue(property.Value));
                    break;

                case "SQ":
                case "CR":
                case "TR":
                case "MA":
                case "SL":
                    node.EnsureMarkup();
                    var mark =
                        name == "SQ"
                                ? MarkType.Square
                                : name == "CR"
                                    ? MarkType.Circle
                                    : name == "TR"
                                        ? MarkType.Triangle
                                        : name == "MA"
                                            ? MarkType.Mark
                                            : MarkType.Selected;

                    foreach (var stone in CompilePointValues(property.Value))
                    {
                        node.Markup.Marks.Add(new Mark(stone.X, stone.Y, mark));
                    }
                    break;
                }
            }
        }
示例#9
0
        private void BuildMarkup(GoNode node)
        {
            foreach (var label in node.Markup.Labels)
            {
                b.Compose("LB", DecompilePointValue(label.X, label.Y), label.Text);
            }

            foreach (var mark in node.Markup.Marks)
            {
                var    coord         = DecompilePointValue(mark.X, mark.Y);
                string markTypeToken = "SQ";
                switch (mark.MarkType)
                {
                case MarkType.Square:
                    markTypeToken = "SQ";
                    break;

                case MarkType.Circle:
                    markTypeToken = "CR";
                    break;

                case MarkType.Triangle:
                    markTypeToken = "TR";
                    break;

                case MarkType.Mark:
                    markTypeToken = "MA";
                    break;

                case MarkType.Selected:
                    markTypeToken = "SL";
                    break;
                }
                b.p(markTypeToken, coord);
            }
        }
示例#10
0
        private static void SaveNode(TextWriter writer, GoNode goNode)
        {
            var node = goNode;

            while (node != null)
            {
                if (!(node is GoRootNode))
                {
                    writer.Write(";");
                }
                if (node is GoMoveNode)
                {
                    var currentNode = node as GoMoveNode;
                    writer.Write(DecompilePointValue(currentNode.Stone));
                }
                else if (node is GoSetupNode)
                {
                    var      currentNode = node as GoSetupNode;
                    var      builder     = new StringBuilder();
                    BitPlane stones;
                    var      currentBoard = currentNode.BoardCopy;
                    Board    lastBoard    = null;
                    if (currentNode.ParentNode != null)
                    {
                        lastBoard = currentNode.ParentNode.BoardCopy;
                    }


                    if (lastBoard == null)
                    {
                        stones = currentBoard.Black;
                    }
                    else
                    {
                        stones =
                            currentBoard.Black - lastBoard.Black;
                    }
                    if (!stones.Empty())
                    {
                        builder.Append("AB" + DecompilePlaneValue(stones));
                    }
                    if (lastBoard == null)
                    {
                        stones = currentBoard.White;
                    }
                    else
                    {
                        stones =
                            currentBoard.White - lastBoard.White;
                    }
                    if (!stones.Empty())
                    {
                        builder.Append("AW" + DecompilePlaneValue(stones));
                    }
                    if (lastBoard != null)
                    {
                        stones = (lastBoard.White - currentBoard.White).And(
                            lastBoard.Black - currentBoard.Black);
                        if (!stones.Empty())
                        {
                            builder.Append("AE" + DecompilePlaneValue(stones));
                        }
                    }
                    if (currentNode.BlackToPlay.HasValue)
                    {
                        builder.Append("PL[");
                        builder.Append(
                            currentNode.BlackToPlay.Value ? "B" : "W");
                        builder.Append("]");
                    }
                    var move = builder.ToString();
                    if (move != string.Empty)
                    {
                        writer.Write(move);
                    }
                }

                if (node.Comment != null)
                {
                    var comment =
                        node.Comment.Replace("]", "\\]").Replace("\\", "\\\\");
                    writer.Write("C[" + comment + "]");
                }
                if (node.Markup != null)
                {
                    var builder = new StringBuilder();
                    if (node.Markup.Labels.Count > 0)
                    {
                        builder.Append("LB");
                        foreach (var label in node.Markup.Labels)
                        {
                            builder.Append("[");
                            builder.Append(DecompilePointValue(label.X, label.Y));
                            builder.Append(":");
                            builder.Append(label.Text);
                            builder.Append("]");
                        }
                    }
                    if (node.Markup.Marks.Count > 0)
                    {
                        foreach (var mark in node.Markup.Marks)
                        {
                            switch (mark.MarkType)
                            {
                            case MarkType.Square:
                                builder.Append("SQ[");
                                break;

                            case MarkType.Circle:
                                builder.Append("CR[");
                                break;

                            case MarkType.Triangle:
                                builder.Append("TR[");
                                break;

                            case MarkType.Mark:
                                builder.Append("MA[");
                                break;

                            case MarkType.Selected:
                                builder.Append("SL[");
                                break;
                            }
                            builder.Append(DecompilePointValue(mark.X, mark.Y));
                            builder.Append("]");
                        }
                    }
                    writer.Write(builder.ToString());
                }

                if (node.ChildNodes.Count == 1)
                {
                    node = node.ChildNodes[0];
                }
                else
                {
                    foreach (var child in node.ChildNodes)
                    {
                        writer.Write('(');
                        SaveNode(writer, child);
                        writer.Write(')');
                    }
                    node = null;
                }
            }
        }
示例#11
0
        private GoNode AddShape([NotNull] IShape shape)
        {
            GoNode result = null;

            GraphGroup parent = null;

            if (shape.Identity is IGroupElement child)
            {
                _groups.TryGetValue(child.ParentId, out parent);
            }

            if (shape is IEntityShape entityShape)
            {
                var node = new GraphEntity(entityShape, _dpiState);
                if (_actions != null)
                {
                    node.SetContextAwareActions(_actions);
                }
                node.SelectedShape       += OnSelectedShape;
                node.SelectedThreatEvent += OnSelectedThreatEvent;
                node.OpenDiagram         += OnOpenDiagram;
                if (parent == null)
                {
                    _graph.Doc.Add(node);
                }
                else
                {
                    parent.Add(node);
                }
                _entities.Add(shape.AssociatedId, node);

                node.Validate();

                result = node;
            }
            else if (shape is IGroupShape groupShape)
            {
                var group = new GraphGroup(groupShape, _dpiState);
                if (_actions != null)
                {
                    group.SetContextAwareActions(_actions);
                }
                group.SelectedShape += OnSelectedShape;
                if (parent == null)
                {
                    _graph.Doc.Add(group);
                }
                else
                {
                    parent.Add(group);
                }
                _groups.Add(shape.AssociatedId, group);

                group.Validate();

                result = group;
            }

            if (shape.Identity is IThreatEventsContainer container)
            {
                container.ThreatEventAdded   += OnThreatEventAddedToShape;
                container.ThreatEventRemoved += OnThreatEventRemovedFromShape;
            }

            return(result);
        }
示例#12
0
 public GoSetupNode(GoNode parentNode) : base(parentNode, true)
 {
 }
示例#13
0
 public bool IsRightVariant(GoNode node)
 {
     return(true);
 }
示例#14
0
        private void PlaceStone(Stone stone)
        {
            GoNode node = null;

            foreach (var child in Game.CurrentNode.ChildNodes)
            {
                if (child is GoMoveNode)
                {
                    if ((child as GoMoveNode).Stone.X == stone.X &&
                        (child as GoMoveNode).Stone.Y == stone.Y)
                    {
                        node    = child;
                        message = string.Empty;
                        break;
                    }
                }
            }
            if (node != null)
            {
                Game.ToMove(node);
                if (Game.CurrentNode is GoMoveNode)
                {
                    SoundUtils.Play("Stone");
                }
                var count = node.ChildNodes.Count;
                if (count > 0)
                {
                    var variant = random.Next(0, count - 1);
                    Game.ToMove(node.ChildNodes[variant]);
                    if (Game.CurrentNode is GoMoveNode)
                    {
                        SoundUtils.Play("Stone");
                    }
                    playerTurn = true;
                }
                else
                {
                    playerTurn = false;
                }

                if (!Game.CurrentNode.HasChildren)
                {
                    if (format.IsRightVariant(Game.CurrentNode))
                    {
                        message = "Solved";
                    }
                    else
                    {
                        message = "Wrong";
                    }
                }

                Invalidate();
                SetComment();
            }
            else
            {
                message = "No path";
                Invalidate();
            }
        }
示例#15
0
 public GoNodeSgfBuilder(GoNode goNode) : this(goNode, new SgfBuilder())
 {
 }
示例#16
0
 private PointF CalculatePosition(GoNode node, int index, float width, float height)
 {
     return(new PointF((width - node.Width) / 2f + 20, 10 + index * (height + 10 * Dpi.Factor.Height)));
 }
示例#17
0
 private GoNodeWrapper GetNodeWrapper(GoNode goNode)
 {
     return(nodeWrappers.First(x => x.Node == goNode));
 }
示例#18
0
 public GoNodeSgfBuilder(GoNode goNode, SgfBuilder b)
 {
     this.goNode = goNode;
     this.b      = b;
 }