Created
June 4, 2019 02:18
-
-
Save eminetto/7488bd95674262fafca782145eeb1506 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 | |
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