Skip to content
This repository was archived by the owner on Jan 25, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 44 additions & 1 deletion board.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,22 @@ func (b *Board) Transpose() *Board {

// Draw returns visual representation of the board useful for debugging.
func (b *Board) Draw() string {
return b.drawForWhite(false)
}

// Draw2 returns visual representation of the board useful for debugging.
// It is similar to Draw() except allows the caller to specify perspective
// and dark mode options
func (b *Board) Draw2(perspective Color, darkMode bool) string {
if perspective == Black {
return b.drawForBlack(darkMode)
} // else

return b.drawForWhite(darkMode)
}

// drawForWhite returns visual representation of the board from white's perspective
func (b *Board) drawForWhite(darkMode bool) string {
s := "\n A B C D E F G H\n"
for r := 7; r >= 0; r-- {
s += Rank(r).String()
Expand All @@ -116,7 +132,34 @@ func (b *Board) Draw() string {
if p == NoPiece {
s += "-"
} else {
s += p.String()
if darkMode {
s += p.DarkString()
} else {
s += p.String()
}
}
s += " "
}
s += "\n"
}
return s
}

// drawForBlack returns visual representation of the board from black's perspective
func (b *Board) drawForBlack(darkMode bool) string {
s := "\n H G F E D C B A\n"
for r := 0; r <= 7; r++ {
s += Rank(r).String()
for f := numOfSquaresInRow - 1; f >= 0; f-- {
p := b.Piece(NewSquare(File(f), Rank(r)))
if p == NoPiece {
s += "-"
} else {
if darkMode {
s += p.DarkString()
} else {
s += p.String()
}
}
s += " "
}
Expand Down
7 changes: 6 additions & 1 deletion piece.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,13 @@ func (p Piece) String() string {
return pieceUnicodes[int(p)]
}

func (p Piece) DarkString() string {
return pieceDarkUnicodes[int(p)]
}

var (
pieceUnicodes = []string{" ", "♔", "♕", "♖", "♗", "♘", "♙", "♚", "♛", "♜", "♝", "♞", "♟"}
pieceUnicodes = []string{" ", "♔", "♕", "♖", "♗", "♘", "♙", "♚", "♛", "♜", "♝", "♞", "♟"}
pieceDarkUnicodes = []string{" ", "♚", "♛", "♜", "♝", "♞", "♟", "♔", "♕", "♖", "♗", "♘", "♙"}
)

func (p Piece) getFENChar() string {
Expand Down