Пример #1
0
        /// <summary>
        /// Adds all moves to Tree
        /// </summary>
        /// <param name="whitePos">Position of white figures on board</param>
        /// <param name="moves">Pairs of moves and replies e.g. ("e2-e4", "e7-e5")</param>
        public void AddMoves(PlayerPosition whitePos, params string[] moves)
        {
            Move     temp     = new Move(moves[0]);
            MoveNode tempNode = new MoveNode(temp);

            //iterator, that will add move to tree
            MoveIterator pushingIterator = null;

            MoveNode next = null;

            if (!rootMoves.ContainsKey(tempNode))
            {
                rootMoves.Add(tempNode, tempNode);
                next = rootMoves[tempNode].Add(new Move(moves[1]));
            }
            else
            {
                next = rootMoves[tempNode].Add(new Move(moves[1]));
            }

            pushingIterator = GetIterator(tempNode);
            //next answer
            pushingIterator.CurrentNode = next;

            int i = 2;

            while (i < moves.Length)
            {
                pushingIterator.CurrentNode = pushingIterator.CurrentNode.Add(moves[i], whitePos);
                ++i;
            }
        }
Пример #2
0
            public MoveIterator(MoveIterator from)
            {
                if (from == MoveIterator.End)
                {
                    return;
                }

                iter = new MoveNode(from.iter);
                prev = new MoveIterator(from.prev);
            }
Пример #3
0
        /// <summary>
        /// Adds reply to certain move in moves map
        /// </summary>
        /// <param name="moveReply">Move, represented by System.String</param>
        /// <param name="whitePos">Position of White figures on board</param>
        /// <returns>Move node, that points to added move</returns>
        public MoveNode Add(string moveReply, PlayerPosition whitePos)
        {
            MoveNode tempNode = new MoveNode(moveReply, whitePos);

            if (!replies.ContainsKey(tempNode))
            {
                replies.Add(tempNode, tempNode);
            }

            return(replies[tempNode]);
        }
Пример #4
0
        /// <summary>
        /// Adds reply to certain move in moves map
        /// </summary>
        /// <param name="moveReply">Move-reply to add</param>
        /// <returns>Move node, that points to added move</returns>
        public MoveNode Add(Move moveReply)
        {
            MoveNode temp = new MoveNode(moveReply);

            if (!replies.ContainsKey(temp))
            {
                replies.Add(temp, temp);
            }

            return(replies[temp]);
        }
Пример #5
0
 /// <summary>
 /// Looks for beginning of move search
 /// </summary>
 /// <param name="firstMove"></param>
 /// <returns>MoveIterator, that points to reply on
 /// specified MoveNode in RootMoves</returns>
 public MoveIterator GetIterator(MoveNode firstMove)
 {
     if (rootMoves.ContainsKey(firstMove))
     {
         return(new MoveIterator(rootMoves[firstMove]));
     }
     else
     {
         return(MoveIterator.End);
     }
 }
Пример #6
0
 public MoveNode(MoveNode from)
 {
     if ((object)from == null)
     {
         currentMove = null;
         replies     = new Dictionary <MoveNode, MoveNode>();
     }
     else
     {
         currentMove = new Move(from.currentMove);
         replies     = new Dictionary <MoveNode, MoveNode>(from.replies);
     }
 }
Пример #7
0
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return(false);
            }

            MoveNode move = (MoveNode)obj;

            if ((object)move == null)
            {
                return(false);
            }

            if (move.currentMove != this.currentMove)
            {
                return(false);
            }

            return(true);
        }
Пример #8
0
        /// <summary>
        /// Checks if we have debut answer for moves
        /// </summary>
        /// <param name="moves">List of all moves</param>
        /// <returns>MoveIterator that points on certain node, or End iterator if there no answer</returns>
        public MoveIterator CheckMoves(List <Move> moves)
        {
            //there no so long combinations in tree :(
            if (moves.Count > 10)
            {
                return(MoveIterator.End);
            }

            MoveNode temp = new MoveNode(moves[0]);

            if (!rootMoves.ContainsKey(temp))
            {
                return(MoveIterator.End);
            }

            MoveIterator iter = new MoveIterator(rootMoves[temp]);

            for (int i = 1; i < moves.Count; ++i)
            {
                if (iter == MoveIterator.End)
                {
                    break;
                }

                temp.Move = moves[i];

                if (!iter.CurrentNode.Replies.ContainsKey(temp))
                {
                    return(MoveIterator.End);
                }

                iter.CurrentNode = iter.CurrentNode.Replies[temp];
            }

            return(iter);
        }
Пример #9
0
 public MoveIterator(MoveNode node, MoveIterator prevIter)
 {
     iter = node;
     prev = prevIter;
 }
Пример #10
0
 public MoveIterator(MoveNode node)
 {
     iter = node;
 }