Created
January 9, 2018 15:48
-
-
Save hpoit/f1f7f850b369d631e359f21912af84c9 to your computer and use it in GitHub Desktop.
go board
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
CellToolbar | |
In [3]: | |
abstract type Stone end | |
| |
struct Empty <: Stone end | |
struct Black <: Stone end | |
struct White <: Stone end | |
| |
Base.show(io::IO, ::Black) = print(io, "⚈") | |
Base.show(io::IO, ::White) = print(io, "⚆") | |
Base.show(io::IO, ::Empty) = print(io, "·") | |
| |
struct Board <: AbstractMatrix{Stone} | |
array :: Matrix{Stone} | |
end | |
| |
Base.size(board::Board) = size(board.array) | |
Base.getindex(board::Board, i) = board.array[i] | |
Base.IndexStyle(::Board) = IndexLinear() | |
In [35]: | |
e = Empty() | |
b = Black() | |
w = White() | |
| |
brd = Board(Matrix{Empty}(19, 19)) | |
Out[35]: | |
19×19 Board: | |
· · · · · · · · · · · · · · · · · · · | |
· · · · · · · · · · · · · · · · · · · | |
· · · · · · · · · · · · · · · · · · · | |
· · · · · · · · · · · · · · · · · · · | |
· · · · · · · · · · · · · · · · · · · | |
· · · · · · · · · · · · · · · · · · · | |
· · · · · · · · · · · · · · · · · · · | |
· · · · · · · · · · · · · · · · · · · | |
· · · · · · · · · · · · · · · · · · · | |
· · · · · · · · · · · · · · · · · · · | |
· · · · · · · · · · · · · · · · · · · | |
· · · · · · · · · · · · · · · · · · · | |
· · · · · · · · · · · · · · · · · · · | |
· · · · · · · · · · · · · · · · · · · | |
· · · · · · · · · · · · · · · · · · · | |
· · · · · · · · · · · · · · · · · · · | |
· · · · · · · · · · · · · · · · · · · | |
· · · · · · · · · · · · · · · · · · · | |
· · · · · · · · · · · · · · · · · · · | |
In [36]: | |
board.array[2, 3] = b | |
board.array[4, 5] = w | |
Out[36]: | |
⚆ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment