Created
January 10, 2018 14:01
-
-
Save hpoit/0c9334f2efda5a0cbab7dc5dae5f4383 to your computer and use it in GitHub Desktop.
temp1
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
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