Created
June 4, 2019 02:14
-
-
Save eminetto/8b3ada803fd7538e5241d811c52fcacf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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