internal Variation(MoveTree parentTree, int variationIndex, Move move) { ParentTree = parentTree; VariationIndex = variationIndex; Move = move; MoveTree = new MoveTree(this); }
private void SetActiveTreeInner(MoveTree value) { // Replay all moves until the new active tree has been reached. Stack <Move> previousMoves = new Stack <Move>(); MoveTree newActiveTree = value; MoveTree current; for (current = newActiveTree; current.ParentVariation != null; current = current.ParentVariation.ParentTree) { previousMoves.Push(current.ParentVariation.Move); } // 'value' should be embedded somewhere inside this.moveTree. if (current != MoveTree) { throw new ArgumentException("value is not embedded in Game.MoveTree.", nameof(value)); } Position newPosition = initialPosition.Copy(); foreach (Move move in previousMoves) { newPosition.FastMakeMove(move); } currentPosition = newPosition; ActiveTree = newActiveTree; }
private Game(Position initialPosition, MoveTree moveTree) { this.initialPosition = initialPosition; currentPosition = initialPosition.Copy(); MoveTree = moveTree; ActiveTree = moveTree; }
public void Forward() { // No effect if last move. if (IsLastMove) { return; } currentPosition.FastMakeMove(ActiveTree.MainLine.Move); ActiveTree = ActiveTree.MainLine.MoveTree; }
/// <summary> /// Validates a move against the current position and optionally performs it. /// </summary> /// <param name="moveInfo"> /// The move to validate and optionally perform. /// </param> /// <param name="make"> /// True if the move must actually be made, false if only validated. /// </param> /// <returns> /// A valid legal <see cref="Move"/> structure if <see cref="MoveInfo.Result"/> is equal to /// <see cref="MoveCheckResult.OK"/>, or an incomplete <see cref="Move"/> if one of the other <see cref="MoveCheckResult"/> values. /// If <paramref name="make"/> is true, the move is only made if <see cref="MoveCheckResult.OK"/> is returned. /// </returns> /// <exception cref="ArgumentOutOfRangeException"> /// Thrown when any of the move's members have an enumeration value which is outside of the allowed range. /// </exception> public Move TryMakeMove(ref MoveInfo moveInfo, bool make) { Move move = currentPosition.TryMakeMove(ref moveInfo, make); if (make && moveInfo.Result == MoveCheckResult.OK) { // Move to an existing variation, or create a new one. Variation variation = ActiveTree.GetOrAddVariation(move); ActiveTree = variation.MoveTree; } return(move); }
public void SetActiveTree(MoveTree value) { if (value == null) { throw new ArgumentNullException(nameof(value)); } if (ActiveTree != value) { SetActiveTreeInner(value); } }