Skip to content

Instantly share code, notes, and snippets.

@kozross
Created February 23, 2017 01:43
Show Gist options
  • Save kozross/bf942ead864ac6c655fe872178b1b8cc to your computer and use it in GitHub Desktop.
Save kozross/bf942ead864ac6c655fe872178b1b8cc to your computer and use it in GitHub Desktop.
# I have the following sauce code:
import Iterators
type MinimaxNode
id :: Int
min_node :: Bool
val :: Nullable{Int}
children :: Vector{MinimaxNode}
end
current_id = 0
function mk_minimax(d :: Int, branch :: Range{Int}, vrange :: Range{Int}, mini :: Bool)
local val :: Nullable{Int}
local children :: Vector{MinimaxNode}
global current_id = current_id + 1
if d == 0
val = Nullable{Int}(rand(vrange))
children = MinimaxNode[]
else
val = Nullable{Int}()
children = collect(Iterators.repeatedly(() -> mk_minimax(d - 1, branch, vrange, !mini), rand(branch)))
end
return MinimaxNode(current_id, mini, val, children)
end
# However, when I do the following (after `include`ing):
#
# julia> x = mk_minimax(2, 2:3, -10:10, true)
#
# I get:
# MinimaxNode(8,true,Nullable{Int64}(),MinimaxNode[MinimaxNode(5,false,#NULL,MinimaxNode[MinimaxNode(3,true,-4,MinimaxNode[])
# ,MinimaxNode(4,true,10,MinimaxNode[]),MinimaxNode(5,true,-2,MinimaxNode[])]),MinimaxNode(8,false,#NULL,MinimaxN
# ode[MinimaxNode(7,true,7,MinimaxNode[]),MinimaxNode(8,true,-2,MinimaxNode[])])])
#
# Are those #NULLs normal, and if they're not, why am I getting them here?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment