コード例 #1
0
        private void OnPiecePromotion(Position obj)
        {
            var promotionView = ServiceLocator.Current.GetInstance <IView <IPromotionViewModel> >();
            var result        = promotionView.ShowView();

            if (result.HasValue && result.Value)
            {
                _gameTable.GetPieces().First(p => p.CurrentPosition == obj).Type = promotionView.ViewModel.PieceType;
            }
        }
コード例 #2
0
ファイル: SmartComputerPlayer.cs プロジェクト: uaandrei/diss
        public void Act(IGameTable gameTable)
        {
            _gameTable = gameTable;
            var result       = Gateway.GenerateMove(gameTable.GetFen(), gameTable.Difficulty);
            var fromPosition = new Position(result.FromRank, result.FromFile);
            var toPosition   = new Position(result.ToRank, result.ToFile);
            var promotedTo   = result.PromotedTo;

            _gameTable.SetSelectedPiece(fromPosition);
            _gameTable.ParseInput(toPosition);
            if (promotedTo != ' ')
            {
                _gameTable.GetPieces().First(p => p.CurrentPosition == toPosition).Type = Helper.GetType(promotedTo);
            }
            _eventAggregator.GetEvent <RefreshTableEvent>().Publish(gameTable);
        }
コード例 #3
0
        public bool IsSatisfied()
        {
            var king     = _gameTable.CurrentPlayer.Pieces.First(p => p.Type == PieceType.King);
            var opponent = _gameTable.Players.First(p => p.Color != king.Color);

            foreach (var piece in opponent.Pieces)
            {
                var pieceAttacks        = piece.GetAvailableAttacks(_gameTable.GetPieces());
                var anyPieceAttacksKing = pieceAttacks.Any(p => p == king.CurrentPosition);
                if (anyPieceAttacksKing)
                {
                    return(true);
                }
            }
            return(false);
        }