public NewGameWindow([NotNull] ILogger logger, [NotNull] IOpeningBookProvider openingBookProvider) { if (logger is null) { throw new ArgumentNullException(nameof(logger)); } if (openingBookProvider is null) { throw new ArgumentNullException(nameof(openingBookProvider)); } ViewModel = new NewGameWindowViewModel(logger, openingBookProvider); DataContext = ViewModel; Title = $@"New Game – {AppConstants.FullTitle}"; InitializeComponent(); var clipboardText = Clipboard.GetText(); ViewModel.Fen = GameBoard.IsValidFen(clipboardText) ? clipboardText : ChessConstants.DefaultInitialFen; }
public GameWindowViewModel([NotNull] ILogger logger, [NotNull] IOpeningBookProvider openingBookProvider) { Logger = logger ?? throw new ArgumentNullException(nameof(logger)); OpeningBookProvider = openingBookProvider ?? throw new ArgumentNullException(nameof(openingBookProvider)); _taskScheduler = TaskScheduler.FromCurrentSynchronizationContext(); _validMoveTargetSquaresInternal = new HashSet <Square>(); _selectionMode = GameWindowSelectionMode.Default; ValidMoveTargetSquares = _validMoveTargetSquaresInternal.AsReadOnly(); _shouldShowPlayerFeedback = true; _shouldShowPlayersTimers = true; _timeUpdateTimer = new Timer( OnUpdatePlayersTimes, null, Timeout.InfiniteTimeSpan, Timeout.InfiniteTimeSpan); SquareViewModels = ChessHelper .AllSquares .ToDictionary(Factotum.Identity, square => new BoardSquareViewModel(this, square)) .AsReadOnly(); SubscribeToChangeOf(() => IsReversedView, OnIsReversedViewChanged); SubscribeToChangeOf(() => CurrentGameBoard, OnCurrentGameBoardChanged); InitializeNewGame( ChessConstants.DefaultInitialFen, ViewModelHelper.CreateGuiHumanChessPlayerInfo(), ViewModelHelper.CreateGuiHumanChessPlayerInfo()); }
public GameWindow([NotNull] ILogger logger, [NotNull] IOpeningBookProvider openingBookProvider) { if (logger is null) { throw new ArgumentNullException(nameof(logger)); } if (openingBookProvider is null) { throw new ArgumentNullException(nameof(openingBookProvider)); } ViewModel = new GameWindowViewModel(logger, openingBookProvider); DataContext = ViewModel; InitializeComponent(); _canExecuteCopyFenToClipboard = true; _canExecuteCopyHistoryToClipboard = true; Title = AppConstants.FullTitle; InitializeControls(false); InitializePromotionControls(); ViewModel.SubscribeToChangeOf(() => ViewModel.CurrentGameBoard, OnCurrentGameBoardChanged); ViewModel.SubscribeToChangeOf(() => ViewModel.IsReversedView, OnIsReversedViewChanged); ViewModel.SubscribeToChangeOf(() => ViewModel.IsComputerPlayerActive, OnIsComputerPlayerActiveChanged); Thread.CurrentThread.Priority = ThreadPriority.AboveNormal; }
/// <summary> /// Initializes a new instance of the <see cref="PlayerChoiceControlViewModel"/> class. /// </summary> public PlayerChoiceControlViewModel( [NotNull] ILogger logger, [NotNull] IOpeningBookProvider openingBookProvider, GameSide playerSide) { if (logger is null) { throw new ArgumentNullException(nameof(logger)); } if (openingBookProvider is null) { throw new ArgumentNullException(nameof(openingBookProvider)); } PlayerSide = playerSide; var playerControlItemsInternal = new[] { new ControlItem <IPlayerInfo>( ViewModelHelper.CreateGuiHumanChessPlayerInfo(), $"Human ({Environment.UserName})"), new ControlItem <IPlayerInfo>( new PlayerInfo <EnginePlayer, SmartEnoughPlayerCreationData>( new SmartEnoughPlayerCreationData(), (side, data) => new EnginePlayer( logger, openingBookProvider, side, new EnginePlayerParameters { UseOpeningBook = data.UseOpeningBook, MaxPlyDepth = data.MaxPlyDepth.EnsureNotNull(), MaxTimePerMove = data.MaxTimePerMove, UseMultipleProcessors = data.UseMultipleProcessors, UseTranspositionTable = data.UseTranspositionTable, TranspositionTableSizeInMegaBytes = data.TranspositionTableSizeInMegaBytes.EnsureNotNull() })), $"Computer ({typeof(EnginePlayer).GetQualifiedName()})") }; PlayerControlItems = CollectionViewSource.GetDefaultView(playerControlItemsInternal); PlayerControlItems.CurrentChanged += PlayerTypes_CurrentChanged; RaiseSelectedPlayerControlItemChanged(); }
public NewGameWindowViewModel([NotNull] ILogger logger, [NotNull] IOpeningBookProvider openingBookProvider) { if (logger is null) { throw new ArgumentNullException(nameof(logger)); } if (openingBookProvider is null) { throw new ArgumentNullException(nameof(openingBookProvider)); } WhitePlayerViewModel = new PlayerChoiceControlViewModel(logger, openingBookProvider, GameSide.White); BlackPlayerViewModel = new PlayerChoiceControlViewModel(logger, openingBookProvider, GameSide.Black); }
public EnginePlayer( [NotNull] ILogger logger, [NotNull] IOpeningBookProvider openingBookProvider, GameSide side, [NotNull] EnginePlayerParameters parameters) : base(side) { if (openingBookProvider is null) { throw new ArgumentNullException(nameof(openingBookProvider)); } if (parameters is null) { throw new ArgumentNullException(nameof(parameters)); } if (parameters.MaxPlyDepth < CommonEngineConstants.MaxPlyDepthLowerLimit) { throw new ArgumentOutOfRangeException( nameof(parameters.MaxPlyDepth), parameters.MaxPlyDepth, $@"The value must be at least {CommonEngineConstants.MaxPlyDepthLowerLimit}."); } if (parameters.MaxTimePerMove.HasValue && parameters.MaxTimePerMove.Value <= TimeSpan.Zero) { throw new ArgumentOutOfRangeException( nameof(parameters.MaxTimePerMove), parameters.MaxTimePerMove, @"The time per move, if specified, must be positive."); } _logger = logger ?? throw new ArgumentNullException(nameof(logger)); _openingBookRandom = new Random(); MaxPlyDepth = parameters.MaxPlyDepth; _openingBook = parameters.UseOpeningBook ? openingBookProvider.VariedOpeningBook : null; _maxTimePerMove = parameters.MaxTimePerMove; _useMultipleProcessors = parameters.UseMultipleProcessors; _transpositionTable = parameters.UseTranspositionTable ? new TranspositionTable(_logger, parameters.TranspositionTableSizeInMegaBytes) : null; }