2023-08-12 09:24:40 +00:00
|
|
|
package chess
|
|
|
|
|
|
|
|
import (
|
|
|
|
"mchess_server/types"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
2023-08-13 22:05:47 +00:00
|
|
|
func (b *Board) PGN() string {
|
2023-08-12 09:24:40 +00:00
|
|
|
var pgn string
|
|
|
|
var shortName string
|
|
|
|
|
|
|
|
for row := types.RangeFirstValid; row <= types.RangeLastValid; row++ {
|
|
|
|
for col := types.RangeFirstValid; col <= types.RangeLastValid; col++ {
|
|
|
|
coord := types.Coordinate{Col: col, Row: row}
|
|
|
|
piece := b.getPieceAt(coord)
|
|
|
|
|
|
|
|
if piece != nil {
|
|
|
|
shortName = GetShortNameForPiece(piece).String()
|
|
|
|
if piece.GetColor() == types.White {
|
|
|
|
shortName = strings.ToUpper(shortName)
|
|
|
|
}
|
|
|
|
pgn = pgn + shortName
|
|
|
|
} else {
|
|
|
|
pgn = pgn + "-"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if row != types.RangeLastValid {
|
|
|
|
pgn = pgn + "/"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return pgn
|
|
|
|
}
|