34 lines
666 B
Go
34 lines
666 B
Go
package chess
|
|
|
|
import (
|
|
"mchess_server/types"
|
|
"strings"
|
|
)
|
|
|
|
func (b *Board) PGN() string {
|
|
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
|
|
}
|