Skip to content

Instantly share code, notes, and snippets.

@Roboneet
Last active June 12, 2018 07:54
Show Gist options
  • Save Roboneet/08a82f608534520f725e0781a6f39cb7 to your computer and use it in GitHub Desktop.
Save Roboneet/08a82f608534520f725e0781a6f39cb7 to your computer and use it in GitHub Desktop.
using AlphaGo
using HttpServer
using JSON
config = Dict()
function _deploy(f)
handler= HttpHandler(f)
server = Server(handler)
run(server, 3000)
server
end
function transform(req,res)
if typeof(req.method) == GETDict
return handleGET(req, res)
else if typeof(req.method) == POSTDict
return handlePOST(req, res)
res
end
function __init__()
# load neural network and configure env
# add nn and other env variables to config dict
# ...
_deploy(transform)
end
struct MCTSPlayer__
# all the info without the common ones ( like nn )
root
qs::Vector{Float32}
searches_π::Vector{Vector{Float32}}
result::Int
position
# .....
end
function MCTSPlayer__(m::MCTSPlayer)
MCTSPlayer__(m.root, m.qs, m.searches_π, m.result, m.position)
end
function handleGET(req, res)
# create MCTSPlayer
player = initialise_player()
player__ = MCTSPlayer__(m)
res.data = JSON.json(Dict(mctsPlayer=>player__))
return res
end
function makeMCTSPlayer(p::MCTSPlayer__)
# make from p and config dict
end
function handlePOST(req, res)
dict = JSON.parse(String(req.data))
player__ = MCTSPlayer__(dict["mctsPlayer"])
player = makeMCTSPlayer(player__)
# add user action to env
# .....
move = pick_move(player)
play_move!(player, move)
# get current env info and current player__ info
# env = player.position?
# player__ = MCTSPlayer__(player)
data = Dict("env"=>env, "mctsPlayer"=>player__)
res.data = JSON.json(data)
return res
end
__init__()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment