Skip to content

Instantly share code, notes, and snippets.

@eminetto
Created June 4, 2019 02:14
Show Gist options
  • Save eminetto/8b3ada803fd7538e5241d811c52fcacf to your computer and use it in GitHub Desktop.
Save eminetto/8b3ada803fd7538e5241d811c52fcacf to your computer and use it in GitHub Desktop.
package chess
import "bytes"
type board struct {
data [][]string
}
func NewBoard(data [][]string) *board {
return &board{data: data}
}
func (b *board) Board() string {
var buffer = &bytes.Buffer{}
b.collectRows(buffer)
return buffer.String()
}
func (b *board) collectRows(buffer *bytes.Buffer) {
for i := 0; i < 10; i++ {
b.collectRow(buffer, i)
}
}
func (b *board) collectRow(buffer *bytes.Buffer, row int) {
for j := 0; j < 10; j++ {
buffer.WriteString(b.data[row][j])
}
buffer.WriteString("\n")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment