Esempio n. 1
0
        public void Add(Node end, Domino d, IPlayer player)
        {
            if (_root == null)
                throw new InvalidOperationException("Graph has not been started");

            var possibleEnds = Ends(player);
            if (!possibleEnds.Contains(end))
            {
                throw new ArgumentException("Must use a valid end!");
            }
            end.AddChild(d);
        }
Esempio n. 2
0
        private int PrintNode(Node node, StringBuilder sb, int indent, int openCount, IEnumerable<Node> open)
        {
            if (node.End == node.Value.Second)
                sb.Append(node.Value);
            else
                sb.Append(node.Value.ToBackwardsString());

            if (!node.Children.Any())
            {
                if (open.Contains(node))
                   sb.Append(string.Format(" ({0})", ++openCount));
                sb.AppendLine();
                return openCount;
            }
            openCount = PrintNode(node.Children.First(), sb, indent+1, openCount, open);
            foreach (var child in node.Children.Skip(1))
            {
                foreach ( var i in Enumerable.Range(0,indent+1)) sb.Append("       ");
                openCount =PrintNode(child, sb, indent + 2, openCount, open);
            }
            //refactor this and the if statement above together.
            int remaining = node.Available - 1;
            if (remaining > 0 && open.Contains(node))
            {
                foreach (int i in Enumerable.Range(0,remaining))
                {
                    foreach (var j in Enumerable.Range(0, indent)) sb.Append("       ");
                    sb.AppendLine(string.Format(" ({0})", ++openCount));
                }
            }

            return openCount;
        }
Esempio n. 3
0
 //used by King of fools otherwise it would be private.
 internal Node(Domino v, Node parent)
 {
     Value  = v;
      Children = new List<Node>();
      if (parent.End == Value.First)
          End = Value.Second;
      else if (parent.End == Value.Second)
          End = Value.First;
      else
          throw new ArgumentException("Dominoes don't match");
      Owner = parent.Owner;
 }