示例#1
0
        /// <summary>
        /// The event handler for OnFieldSelection.
        /// </summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event arguments.</param>
        private void Board_OnFieldSelection(object sender, FieldSelectedEventArgs e)
        {
            if (!_done && _currentColor == _playerColor && e.Piece != null && e.Piece.Color == _currentColor)
            {
                var enemyColor = ColorOperations.Invert(_currentColor);

                var movesForPiece = Bitboard.Moves
                                    .Where(p => p.From == e.Position && !Bitboard.Moves.Any(q => p.Piece == PieceType.King &&
                                                                                            q.Color == enemyColor && q.To == p.To))
                                    .Select(p => p.To)
                                    .ToList();

                VisualBoard.AddExternalSelections(movesForPiece);
            }
        }
        /// <summary>
        /// The event handler for OnFieldSelection.
        /// </summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event arguments.</param>
        private void Board_OnFieldSelection(object sender, FieldSelectedEventArgs e)
        {
            if (e.Piece == null)
            {
                var fieldAttackers = VisualBoard.FriendlyBoard.GetFieldAttackers(e.Position);
                VisualBoard.AddExternalSelections(fieldAttackers);
            }
            else
            {
                var movesForPiece = Bitboard.Moves
                                    .Where(p => p.From == e.Position)
                                    .Select(p => p.To)
                                    .ToList();

                VisualBoard.AddExternalSelections(movesForPiece);
            }
        }
        /// <summary>
        /// Draws all fields attacked by pieces with the specified color.
        /// </summary>
        /// <param name="command">The Attacks command.</param>
        private void DrawAttacks(Command command)
        {
            var colorArgument = command.GetArgument <string>(0);

            List <Position> attacks;

            if (colorArgument == "all")
            {
                attacks = VisualBoard.FriendlyBoard.GetAttacks();
            }
            else
            {
                var colorTypeParseResult = Enum.TryParse(colorArgument, true, out Color colorType);
                if (!colorTypeParseResult)
                {
                    ConsoleManager.WriteLine($"$rInvalid color parameter ($R{colorArgument}$r)");
                    return;
                }

                attacks = VisualBoard.FriendlyBoard.GetAttacks(colorType);
            }

            VisualBoard.AddExternalSelections(attacks);
        }