Skip to content

Instantly share code, notes, and snippets.

@tleyden
Created December 23, 2013 19:24
Show Gist options
  • Save tleyden/8103061 to your computer and use it in GitHub Desktop.
Save tleyden/8103061 to your computer and use it in GitHub Desktop.
func NewBoard(compactBoard string) Board {
var board Board
name := "boardlexer"
_, tokensChannel := lex(name, compactBoard)
i := 0
for token := range tokensChannel {
row := int(i / 8)
col := int(i % 8)
switch {
case token.typ == itemSquareEmpty:
board[row][col] = EMPTY
case token.typ == itemSquareRed:
board[row][col] = RED
case token.typ == itemSquareRedKing:
board[row][col] = RED_KING
case token.typ == itemSquareBlack:
board[row][col] = BLACK
case token.typ == itemSquareBlackKing:
board[row][col] = BLACK_KING
}
i += 1
}
return board
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment