Пример #1
0
        private IMove GetMove(IMoveAN moveAN, IEnumerable <Move> validMoves)
        {
            var targetCell = board.GetCell(moveAN.Coordinate.Row, moveAN.Coordinate.Column);

            var movesHitTargetCell = validMoves.Where(m => m.TargetPosition == targetCell && m.InitialPosition.Piece.GetType() == moveAN.PieceType);

            HandleExceptions.ListMoveExceptions <Move>(movesHitTargetCell);

            IMove findCorrectMove = moveAN.File != -1
                ? movesHitTargetCell.Where(p => p.InitialPosition.Column == moveAN.File).Single()
                : movesHitTargetCell.Single();

            HandleExceptions.MoveException(findCorrectMove);
            return(findCorrectMove);
        }
Пример #2
0
        private void NextTurn(Player player, IMoveAN moveAN)
        {
            var validMoves = player.GenerateAllLegalMoves();

            if (moveAN.Coordinate != null)
            {
                IMove findCorrectMove = GetMove(moveAN, validMoves);
                findCorrectMove.MoveAN = moveAN;
                player.MakeMove(findCorrectMove);
            }
            if (moveAN.IsKingCastling || moveAN.IsQueenCastling)
            {
                var isKingSide = moveAN.IsKingCastling ? true : false;
                var color      = player == WhitePlayer ? PieceColor.White : PieceColor.Black;
                board.Castling(color, isKingSide);
            }

            currentPlayer = currentPlayer == WhitePlayer ? BlackPlayer : WhitePlayer;
        }
        private static void InterpretRegexCastling(string moveNotation, string pattern, IMoveAN move)
        {
            pattern = @"^(?<castling>[0]([-][0]){1,2})$";
            Match match = Regex.Match(moveNotation, pattern);

            if (match.Success)
            {
                if (match.Groups["castling"].Value == "0-0")
                {
                    move.IsKingCastling = true;
                }
                if (match.Groups["castling"].Value == "0-0-0")
                {
                    move.IsQueenCastling = true;
                }
            }
        }