예제 #1
0
        /// <summary>
        /// The event handler for OnPieceMove.
        /// </summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event arguments.</param>
        private void Board_OnPieceMove(object sender, PieceMovedEventArgs e)
        {
            var move = Bitboard.Moves.FirstOrDefault(p => p.From == e.From && p.To == e.To);

            switch (move)
            {
            case null:
            {
                CalculateBitboard(new QuietMove(e.From, e.To, e.Piece.Type, e.Piece.Color), _quiescenceSearch);
                break;
            }

            case PromotionMove _:
            {
                var promotionMoves = Bitboard.Moves.OfType <PromotionMove>().Where(p => p.From == move.From && p.To == move.To);
                PromotionWindow.Display(move.Color, promotionMoves);
                break;
            }

            default:
            {
                CalculateBitboard(move, _quiescenceSearch);
                break;
            }
            }
        }
예제 #2
0
        /// <summary>
        /// The event handler for OnPieceMove.
        /// </summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event arguments.</param>
        private void Board_OnPieceMove(object sender, PieceMovedEventArgs e)
        {
            if (!_done && _currentColor == _playerColor && e.Piece != null && e.Piece.Color == _currentColor)
            {
                var enemyColor = ColorOperations.Invert(_currentColor);

                var move = Bitboard.Moves.FirstOrDefault(p => p.From == e.From && p.To == e.To);

                if (move == null)
                {
                    return;
                }

                var testBitboard = Bitboard.Move(move);
                testBitboard.Calculate(false);

                if (testBitboard.IsCheck(_currentColor))
                {
                    ConsoleManager.WriteLine("$RInvalid move");
                    return;
                }

                switch (move)
                {
                case PromotionMove _:
                {
                    var promotionMoves = Bitboard.Moves.OfType <PromotionMove>().Where(p => p.From == move.From &&
                                                                                       p.To == move.To);
                    PromotionWindow.Display(move.Color, promotionMoves);

                    break;
                }

                default:
                {
                    CalculateBitboard(move, false);
                    break;
                }
                }

                CheckIfGameHasEnded(Bitboard);

                _currentColor = ColorOperations.Invert(_currentColor);
                _history.Add(move);

                MoveAI();
            }
        }
예제 #3
0
 private void PieceMoved(object sender, PieceMovedEventArgs e)
 {
     pieces[e.OldCoordinates].SetBoardPosition(e.NewCoordinates);
     pieces.Add(e.NewCoordinates, pieces[e.OldCoordinates]);
     pieces.Remove(e.OldCoordinates);
 }
예제 #4
0
 private void OnPieceMoved(PieceMovedEventArgs e)
 {
     PieceMoved?.Invoke(this, e);
 }