Skip to content

Instantly share code, notes, and snippets.

@hpoit
Created January 9, 2018 15:48
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 hpoit/f1f7f850b369d631e359f21912af84c9 to your computer and use it in GitHub Desktop.
Save hpoit/f1f7f850b369d631e359f21912af84c9 to your computer and use it in GitHub Desktop.
go board
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