initial framework added
[fp1415-soccerfun.git] / src / StdTeam / Buffer.icl
1 implementation module Buffer
2
3 import StdEnvExt
4 import Footballer
5
6 buffer :: !FootballField !Home !Edge !FootballerID -> Footballer
7 buffer field home edge playerID = {defaultFootballer playerID & name = "buffer"
8 , length = m 2.2
9 , skills = (Running, Gaining, Rotating)
10 , brain = { memory = {curDir = if (edge == North) (rad (0.5*pi)) (rad (-0.5*pi))}
11 , ai = the_mind_of_a_buffer field home
12 }
13 }
14
15 :: Memory = { curDir :: !Angle
16 }
17
18 the_mind_of_a_buffer :: !FootballField !Home !(!BrainInput,!Memory) -> (!BrainOutput,!Memory)
19 the_mind_of_a_buffer field home ({football,others,me},memory)
20 | dist ball me < maxGainReach me // I can gain the ball
21 = (GainBall,memory)
22 | dist ball me < m 30.0 && ballIsInZone // I can not gain the ball, but I can run to it
23 = (runTowardsBall,memory)
24 | abs me.pos.py > scale 0.5 field.fwidth - sidebuffer // near the edge, turn around
25 = (Move {velocity = ms 25.0,direction=new_direction} zero, {memory & curDir = new_direction})
26 with
27 new_direction = if (me.speed.direction < zero) (rad (0.5*pi)) (rad (-0.5*pi))
28 | otherwise = (Move {velocity = ms 25.0,direction=memory.curDir} zero,memory) // no ball, no turning, just keep running
29 where
30 sidebuffer = scale 0.01 field.fwidth
31 ball = getFootball football [me:others]
32 ball_x = ball.ballPos.pxy.px
33 ballIsInZone = if (home == East) (isbetween ball_x (scale 0.15 field.flength) (scale 0.20 field.flength))
34 (isbetween ball_x (scale -0.10 field.flength) (scale -0.10 field.flength))
35 nextBallPos = (nextpos ball).ballPos
36 direction2ball = bearing me.speed.direction me nextBallPos.pxy
37 runTowardsBall = Move {direction=direction2ball,velocity=ms 10.0} zero
38
39 nextpos :: !Football -> Football
40 nextpos ball=:{ballSpeed={vxy={velocity=v,direction=d},vz=v3},ballPos}
41 = {ball & ballPos = move_point3D {zero & dxy={dx=m (cosinus d * toReal v),dy=m (sinus d * toReal v)}} ballPos}