Created
December 23, 2013 19:24
-
-
Save tleyden/8103061 to your computer and use it in GitHub Desktop.
This file contains 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
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