Beispiel #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);
        }
Beispiel #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();
            }
        }
Beispiel #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);
        }
Beispiel #4
0
 public void AddMove(ChessMove move, OpeningNode node)
 {
     moves.Add(move);
     nodes.Add(node);
 }
Beispiel #5
0
 public OpeningNode(OpeningNode parent)
 {
     this.parent = parent;
 }