编辑代码

-- JSRUN引擎2.0,支持多达30种语言在线运行,全仿真在线交互输入输出。
function gettar(tar)
    local itar
    if type(tar) == "string" then
        itar = player.pos(tar)
    elseif type(tar) == "function" then
        itar = tar()
    else
        itar = tar
    end
    return itar
end

local function PassBall(tar)
	local ikick =kick.flat
	local ipower=3000
	local f = flag.dribbling
	local ipos= function(runner)
		local res
		local itar=gettar(tar)
		res=ball.pos()+Utils.Polar2Vector(95,(ball.pos()-itar):dir())
		return res
	end
	local idir =function(runner)
		local res
		local itar = gettar(tar)
		res=(itar - player.pos(runner)):dir()
		return res
	end
	local mexe,mpos = GoCmuRush{pos = ipos,dir = idir, acc = a, flag = f,rec = r,vel = v}
	return {mexe, mpos, ikick, idir, pre.low, kp.specified(ipower), cp.specified(0), f}

end

local function Wait(pos)
	local ipos = pos
	local idir =function(runner)
		local res
		res=(ball.pos() - player.pos(runner)):dir()
		return res
	end
	local mexe,mpos = GoCmuRush{pos = ipos,dir = idir, acc = a, flag = f,rec = r,vel = v}
	return {mexe,mpos}
end

function ReceiveBall()
	local f = flag.dribbling
	local ipos= function(runner)
		local res
		if ball.velMod()<500 then
			res=ball.pos()+Utils.Polar2Vector(95,(ball.pos() - player.pos(runner)):dir())
		else
			res=ball.pos()+Utils.Polar2Vector(player.toBallDist(runner),ball.velDir())
		end
		return res
	end
	local idir = function(runner)
		local res
		res = (ball.pos()-player.pos(runner)):dir()
		return res
	end
	local mexe,mpos = GoCmuRush{pos = ipos,dir = idir, acc = a, flag = f,rec = r,vel = v}
	return {mexe,mpos}
end



local function Getball()
	local f = flag.dodge_ball+flag.allow_dss 
	local ipos =function(runner)
		local pos= ball.pos()+Utils.Polar2Vector(100,(ball.pos()-player.pos("a")):dir())
		return pos
	end
	local idir =function(runner)
		local dir =(ball.pos()-player.pos(runner)):dir()
		return dir
	end
	local mexe,mpos = GoCmuRush{pos = ipos,dir = idir, acc = a, flag = f,rec = r,vel = v}
	return {mexe,mpos}
end


local  function ShootGool()
	local ikick =kick.flat
	local ipower=5500

	local ipos = function()
		local pos= ball.pos()+Utils.Polar2Vector(100,(ball.pos()-CGeoPoint(param.pitchLength/2,0)):dir())
		return pos
	end
	local idir =function(runner)
		local dir =(CGeoPoint(param.pitchLength/2,0)-player.pos(runner)):dir()
		return dir
	end
	local mexe, mpos = GoCmuRush{pos =ipos, dir = idir, acc = a, flag = f,rec = r,vel = v}
	return {mexe, mpos, ikick, idir, pre.middle, kp.specified(ipower), cp.full, flag.nothing}
end

gPlayTable.CreatePlay{

firstState = "start",
["start"] = {
	switch = function ()

		if bufcnt(true,1) then
			return "A_geiball"
		end 
	end,
	a = task.halt(),
	b = Wait(CGeoPoint(0,0)),
	match = "[ab]"
},

["A_geiball"] = {
	switch = function ()
		local dis=(ball.pos()-player.pos("a")):mod()
		if bufcnt(dis<200,30) then
			return "A_PassBall"
		end
	end,
	a = Getball(),
	b = task.halt(),
	match = "{ab}"
},


["A_PassBall"]={
	switch = function()
		local dis=(ball.pos()-player.pos("a")):mod()
		if bufcnt(dis>500,30) then
			return "B_GetBall"
		end
	end,
	a = PassBall("b"),
	b = task.halt(),
	match="{ab}"
},


["B_GetBall"]={
	switch = function()
		local dis = (player.pos("b")-ball.pos()):mod()
		if bufcnt(dis<300,30) then
			return "ShootGool"
		end
	end,
	a = task.halt(),
	b = ReceiveBall(),
	match="{ab}"
},



["ShootGool"] = {
	switch = function ()
		if bufcnt((ball.pos() - CGeoPoint(param.pitchLength/2,0)):mod()<500,30) then
			return "start"
		end
	end,
	a = task.halt(),
	b =ShootGool(),
	match = "{ab}"
},

name = "GetBall",
applicable ={
	exp = "a",
	a = true
},
attribute = "attack",
timeout = 99999
}