Skip to content

Instantly share code, notes, and snippets.

@eminetto
Created June 4, 2019 02:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eminetto/7488bd95674262fafca782145eeb1506 to your computer and use it in GitHub Desktop.
Save eminetto/7488bd95674262fafca782145eeb1506 to your computer and use it in GitHub Desktop.
package chess
type piece struct {
representation string
}
type location struct {
current *piece
}
type board struct {
locations []*location
}
func NewLocation(piece *piece) *location {
return &location{current: piece}
}
func NewPiece(representation string) *piece {
return &piece{representation: representation}
}
func NewBoard() *board {
locations := []*location{
NewLocation(NewPiece("London")),
NewLocation(NewPiece("New York")),
NewLocation(NewPiece("Dubai")),
}
return &board{
locations: locations,
}
}
func (b *board) squares() []*location {
return b.locations
}
func (b *board) BoardRepresentation() string {
var buffer = &bytes.Buffer{}
for _, l := range b.squares() {
buffer.WriteString(l.current.representation[0:1])
}
return buffer.String()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment