mchess-server/chess/pgn.go

34 lines
666 B
Go
Raw Normal View History

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
}