public void SetupPieces(BoardEngine <ChessPieceEntity> engine) { for (var rank = 7; rank >= 0; rank--) { for (var file = 0; file < 8; file++) { var chr = _board[file, rank]; if (_chessPieceEntityFactory.ValidPieces.Contains(chr.ToString().ToUpper())) { var entity = _chessPieceEntityFactory.Create( ChessPieceNameMapper.FromChar(chr), char.IsUpper(chr) ? Colours.White : Colours.Black ); var location = BoardLocation.At(file + 1, rank + 1); engine.AddPiece(entity, location); if (chr.ToString().ToUpper() == "E") { ((PawnEntity)entity).TwoStep = true; } } else if (chr != ' ' && chr != '.' && chr != '\0') { Throw.InvalidPiece(chr); } } } }
private IEnumerable <char> ParseFirstToken(string notation) { var tokens = notation; var firstChar = notation[0]; var firstCharTokenType = _sanTokenParser.GetTokenType(firstChar); if (firstCharTokenType == SanTokenTypes.Piece) { WithPiece(ChessPieceNameMapper.FromChar(firstChar)); tokens = notation.Substring(1); } else if (firstCharTokenType != SanTokenTypes.File && firstCharTokenType != SanTokenTypes.Rank) { Throw.InvalidSan($"Unexpected token in first character '{firstChar}'"); } return(tokens); }
private void WithPromotionPiece(char c) => _promotionPiece = ChessPieceNameMapper.FromChar(c);