Skip to content

Instantly share code, notes, and snippets.

@hpoit
Created January 10, 2018 14:01
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/0c9334f2efda5a0cbab7dc5dae5f4383 to your computer and use it in GitHub Desktop.
Save hpoit/0c9334f2efda5a0cbab7dc5dae5f4383 to your computer and use it in GitHub Desktop.
temp1
julia> abstract type Stone end
julia> struct Empty <: Stone end
julia> struct Black <: Stone end
julia> struct White <: Stone end
julia> Base.show(io::IO, ::Black) = print(io, "⚈")
julia> Base.show(io::IO, ::White) = print(io, "⚆")
julia> Base.show(io::IO, ::Empty) = print(io, "·")
julia> mutable struct Board <: AbstractMatrix{Stone}
array::Matrix{Stone}
end
julia> Base.size(board::Board) = size(board.array)
julia> Base.getindex(board::Board, i) = board.array[i]
julia> Base.IndexStyle(::Board) = IndexLinear()
julia> empty = Empty()
julia> black = Black()
julia> white = White()
julia> createboard(magnitude) = Board(Matrix{Empty}(magnitude, magnitude))
createboard (generic function with 1 method)
julia> magnitude = 19; cb = createboard(magnitude)
19×19 Board:
· · · · · · · · · · · · · · · · · · ·
· · · · · · · · · · · · · · · · · · ·
· · · · · · · · · · · · · · · · · · ·
· · · · · · · · · · · · · · · · · · ·
· · · · · · · · · · · · · · · · · · ·
· · · · · · · · · · · · · · · · · · ·
· · · · · · · · · · · · · · · · · · ·
· · · · · · · · · · · · · · · · · · ·
· · · · · · · · · · · · · · · · · · ·
· · · · · · · · · · · · · · · · · · ·
· · · · · · · · · · · · · · · · · · ·
· · · · · · · · · · · · · · · · · · ·
· · · · · · · · · · · · · · · · · · ·
· · · · · · · · · · · · · · · · · · ·
· · · · · · · · · · · · · · · · · · ·
· · · · · · · · · · · · · · · · · · ·
· · · · · · · · · · · · · · · · · · ·
· · · · · · · · · · · · · · · · · · ·
· · · · · · · · · · · · · · · · · · ·
julia> #cb.array[1:19,1:19] = empty
cb.array[5, 8] = black
julia> cb.array[13,17] = white
julia> cb
19×19 Board:
· · · · · · · · · · · · · · · · · · ·
· · · · · · · · · · · · · · · · · · ·
· · · · · · · · · · · · · · · · · · ·
· · · · · · · · · · · · · · · · · · ·
· · · · · · · ⚈ · · · · · · · · · · ·
· · · · · · · · · · · · · · · · · · ·
· · · · · · · · · · · · · · · · · · ·
· · · · · · · · · · · · · · · · · · ·
· · · · · · · · · · · · · · · · · · ·
· · · · · · · · · · · · · · · · · · ·
· · · · · · · · · · · · · · · · · · ·
· · · · · · · · · · · · · · · · · · ·
· · · · · · · · · · · · · · · · ⚆ · ·
· · · · · · · · · · · · · · · · · · ·
· · · · · · · · · · · · · · · · · · ·
· · · · · · · · · · · · · · · · · · ·
· · · · · · · · · · · · · · · · · · ·
· · · · · · · · · · · · · · · · · · ·
· · · · · · · · · · · · · · · · · · ·
julia>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment