public string ToTextBoard() { var sb = new StringBuilder(); for (var rank = 7; rank >= 0; rank--) { for (var file = 0; file < 8; file++) { var loc = BoardLocation.At(file + 1, rank + 1); var entity = GetItem(loc)?.Item; char chr; if (entity == null) { chr = '.'; } else { chr = ChessPieceNameMapper.ToChar(entity.EntityType, entity.Owner); var epY = char.IsUpper(chr) ? 5 : 4; if (chr == 'p' || chr == 'P' && loc.Y == epY && entity.LocationHistory.Count() == 2) { chr = chr == 'p' ? 'e' : 'E'; } } sb.Append(chr == '\0' ? '.' : chr); } sb.AppendLine(); } return(sb.ToString()); }
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 string buildExtra(ChessPieceName?promotionPiece) { if (promotionPiece.HasValue) { return ($"{SanTokenParser.PromoteNotator.ToString()}{ChessPieceNameMapper.ToChar(promotionPiece.Value, Colours.White)}"); } return(string.Empty); }
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);