示例#1
0
        public OpeningNode FindMove(ChessMove move)
        {
            OpeningNode res = null;

            for (int i = 0; i < moves.Count; i++)
            {
                if (moves[i].FromIndex == move.FromIndex &&
                    moves[i].ToIndex == move.ToIndex &&
                    moves[i].PromotionPieceType == move.PromotionPieceType)
                {
                    res = nodes[i];
                    break;
                }
            }
            return(res);
        }
示例#2
0
        private void AddMove(OpeningNode parentNode, XmlReader reader)
        {
            while (reader.IsStartElement("move"))
            {
                string moveString = reader.GetAttribute("id");
                reader.ReadStartElement("move");

                ChessMove   move = MoveFromString(moveString);
                OpeningNode node = new OpeningNode(parentNode);

                parentNode.AddMove(move, node);

                AddMove(node, reader);

                reader.ReadEndElement();
            }
        }
示例#3
0
        public ChessMove GetNextMove(List <ChessMove> gameMoves)
        {
            OpeningNode node = topNode;
            ChessMove   res  = null;

            for (int i = 0; i < gameMoves.Count && node != null; i++)
            {
                ChessMove gameMove = gameMoves[i];
                node = node.FindMove(gameMove);
                if (node == null)
                {
                    break;
                }
            }

            if (node != null && node.Moves.Count > 0)
            {
                int index = random.Next(node.Moves.Count);
                res = node.Moves[index];
            }

            return(res);
        }
示例#4
0
 public void AddMove(ChessMove move, OpeningNode node)
 {
     moves.Add(move);
     nodes.Add(node);
 }
示例#5
0
 public OpeningNode(OpeningNode parent)
 {
     this.parent = parent;
 }