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