Skip to content

Instantly share code, notes, and snippets.

@hpoit
Created January 12, 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/f7586e742489624b78ffc73e4d3f6c77 to your computer and use it in GitHub Desktop.
Save hpoit/f7586e742489624b78ffc73e4d3f6c77 to your computer and use it in GitHub Desktop.
running on REPL
Last login: Fri Jan 12 13:47:11 on ttys000
Kevins-MBP:~ Corvus$ exec '/Applications/Julia-0.6.app/Contents/Resources/julia/bin/julia'
_
_ _ _(_)_ | A fresh approach to technical computing
(_) | (_) (_) | Documentation: https://docs.julialang.org
_ _ _| |_ __ _ | Type "?help" for help.
| | | | | | |/ _` | |
| | |_| | | | (_| | | Version 0.6.0 (2017-06-19 13:05 UTC)
_/ |\__'_|_|_|\__'_| | Official http://julialang.org/ release
|__/ | x86_64-apple-darwin13.4.0
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) # test for 361 intersections
19×19 Board:
· · · · · · · · · · · · · · · · · · ·
· · · · · · · · · · · · · · · · · · ·
· · · · · · · · · · · · · · · · · · ·
· · · · · · · · · · · · · · · · · · ·
· · · · · · · · · · · · · · · · · · ·
· · · · · · · · · · · · · · · · · · ·
· · · · · · · · · · · · · · · · · · ·
· · · · · · · · · · · · · · · · · · ·
· · · · · · · · · · · · · · · · · · ·
· · · · · · · · · · · · · · · · · · ·
· · · · · · · · · · · · · · · · · · ·
· · · · · · · · · · · · · · · · · · ·
· · · · · · · · · · · · · · · · · · ·
· · · · · · · · · · · · · · · · · · ·
· · · · · · · · · · · · · · · · · · ·
· · · · · · · · · · · · · · · · · · ·
· · · · · · · · · · · · · · · · · · ·
· · · · · · · · · · · · · · · · · · ·
· · · · · · · · · · · · · · · · · · ·
julia> # make distinguished marks for star points when possible
"Test board"
cb.array[5, 8] = black # struct Move in BoardState?
ERROR: MethodError: no method matching Base.Docs.Binding(::Board, ::Symbol)
Closest candidates are:
Base.Docs.Binding(::Module, ::Symbol) at docs/bindings.jl:12
julia> cb.array[13,17] = white
julia> cb
19×19 Board:
· · · · · · · · · · · · · · · · · · ·
· · · · · · · · · · · · · · · · · · ·
· · · · · · · · · · · · · · · · · · ·
· · · · · · · · · · · · · · · · · · ·
· · · · · · · ⚈ · · · · · · · · · · ·
· · · · · · · · · · · · · · · · · · ·
· · · · · · · · · · · · · · · · · · ·
· · · · · · · · · · · · · · · · · · ·
· · · · · · · · · · · · · · · · · · ·
· · · · · · · · · · · · · · · · · · ·
· · · · · · · · · · · · · · · · · · ·
· · · · · · · · · · · · · · · · · · ·
· · · · · · · · · · · · · · · · ⚆ · ·
· · · · · · · · · · · · · · · · · · ·
· · · · · · · · · · · · · · · · · · ·
· · · · · · · · · · · · · · · · · · ·
· · · · · · · · · · · · · · · · · · ·
· · · · · · · · · · · · · · · · · · ·
· · · · · · · · · · · · · · · · · · ·
julia> "Empty board"
cb.array[1:19,1:19] = empty # [row, column]
ERROR: MethodError: no method matching Base.Docs.Binding(::Board, ::Symbol)
Closest candidates are:
Base.Docs.Binding(::Module, ::Symbol) at docs/bindings.jl:12
julia> cb
19×19 Board:
· · · · · · · · · · · · · · · · · · ·
· · · · · · · · · · · · · · · · · · ·
· · · · · · · · · · · · · · · · · · ·
· · · · · · · · · · · · · · · · · · ·
· · · · · · · · · · · · · · · · · · ·
· · · · · · · · · · · · · · · · · · ·
· · · · · · · · · · · · · · · · · · ·
· · · · · · · · · · · · · · · · · · ·
· · · · · · · · · · · · · · · · · · ·
· · · · · · · · · · · · · · · · · · ·
· · · · · · · · · · · · · · · · · · ·
· · · · · · · · · · · · · · · · · · ·
· · · · · · · · · · · · · · · · · · ·
· · · · · · · · · · · · · · · · · · ·
· · · · · · · · · · · · · · · · · · ·
· · · · · · · · · · · · · · · · · · ·
· · · · · · · · · · · · · · · · · · ·
· · · · · · · · · · · · · · · · · · ·
· · · · · · · · · · · · · · · · · · ·
julia>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment