1 implementation module Team_MartLubbers
4 import FootballerFunctions
24 Team_MartLubbers :: !Home !FootballField -> Team
25 Team_MartLubbers home field
26 | home==West = westTeam
27 | otherwise = eastTeam
29 eastTeam = mirror field westTeam
30 westTeam = [keeper : fielders]
31 clubname = base_TeamName_MartLubbers +++ if (home == West) "_W" "_E"
32 keeper = Aesir clubname home field {zero & px=scale -0.5 field.flength} 1 "Thor"
33 fielders = [Aesir clubname home field {px=scale (-0.5*dx) field.flength,py=scale (0.5*dy) field.fwidth} nr name
34 \\ (dx,dy) <- west_positions_fielders
38 west_positions_fielders = [(0.20, 0.40)
51 :: Mem = {home :: !Home, origpos :: Position, seed :: !RandomSeed}
53 mirrorMem :: !Mem !FootballField -> Mem
54 mirrorMem mm field = {mm & home=other mm.home, origpos=mirror field mm.origpos}
56 Aesir :: !ClubName !Home !FootballField !Position !PlayersNumber !String -> Footballer
57 Aesir club home field position nr name
58 = { playerID = {clubName=club,playerNr=nr}
59 , name = name +++ "_" <+++ nr
64 , skills = (Running, Kicking, Tackling)
66 , stamina = max_stamina
68 , brain = {memory=if (home == West) mm (mirrorMem mm field), ai = mind field}
71 mm = {home=West, origpos=position, seed=nullRandomSeed}
73 nextRandomNumber :: !Mem -> (Int, !Mem)
74 nextRandomNumber mm=:{seed} = let (i, newseed) = random seed in (i rem 100, {mm & seed=newseed})
76 mind :: !FootballField !(!BrainInput, !Mem) -> (!BrainOutput, !Mem)
77 mind field (x=:{referee,football,others,me}, mm=:{home,origpos})
78 # (i, mm) = nextRandomNumber mm
79 // In case of the end of the half, mirror memory
80 | any (isEndHalf) referee = mind field ({x & referee=filter (\x.not (isEndHalf x)) referee}, mirrorMem mm field)
81 // In case of a pause or end, just halt
82 | any (isPauseGame) referee || any (isGameOver) referee = halt (x, mm)
84 | me.playerID.playerNr == 1
85 | i_have_ball = kick closest_free_teammate (x, mm)
86 | ball_in_reach maxCatchReach = (CatchBall, mm)
87 | ball_their_half = halt (x, mm)
89 | we_have_ball = stayInGoal (x, mm)
91 | isClosest others me ballPos.pxy = halt (x, mm)
92 | otherwise = stayInGoal (x, mm)
94 | length (filter player_within_16 them) == 1
95 | (dist me.pos ballPos.pxy) < (maxCatchReach me) = (CatchBall, mm)
96 | otherwise = fix ballPos.pxy (maxCatchReach me) (x, mm)
97 | otherwise = stayInGoal (x, mm)
99 | we_have_ball = halt (x, mm)
100 | otherwise = stayInGoal (x, mm)
102 | me.playerID.playerNr > 7
103 | ball_their_half = fix {origpos & px=origpos.px + (scale 0.5 ballPos.pxy.px)} prec (x, mm)
105 // TODO I have the ball
106 | i_have_ball = moveForward i (x, mm)
107 // TODO we have the ball
108 | we_have_ball = fix {px=ballPos.pxy.px, py=origpos.py} prec (x, mm)
109 // they have the ball
110 | otherwise = obtainBall i (x, mm)
113 | i_have_ball = moveForward i (x, mm)
114 | ballIsFree football
115 | ball_in_reach maxGainReach = (GainBall, mm)
116 | isClosest us me ballPos.pxy = fix ballPos.pxy prec (x, mm)
117 | otherwise = fix {px=ballPos.pxy.px + (m 10.0), py=origpos.py} prec (x, mm)
118 | we_have_ball = fix {px=ballPos.pxy.px + (m 10.0), py=origpos.py} prec (x, mm)
119 | otherwise = obtainBall i (x, mm)
121 obtainBall :: Int -> FootballerAI m
123 | ball_in_reach maxTackleReach && length has_ball > 0
124 | i<15 = \(_,mm).(Tackle (hd has_ball).playerID (ms 10.0), mm)
125 | i < 50 = kick closest_free_teammate
126 | otherwise = \(_,mm).(GainBall, mm)
127 | isClosest us me ballPos.pxy = fix ballPos.pxy prec
128 | otherwise = fix closest_free_player prec
130 moveForward :: Int -> FootballerAI m
131 moveForward i = fix their_goal prec//TODO
133 stayInGoal = fix (attract goal_area_depth our_goal ballPos.pxy) prec
134 closest_free_player = their_goal // TODO
135 closest_free_teammate = their_goal // TODO
137 player_within_16 p = inPenaltyArea field home p.pos
138 ball_within_16 = inPenaltyArea field home ballPos.pxy
140 has_ball = filter (\x.ballIsGainedBy x.playerID football) others
141 we_have_ball = any (\x.sameClub me x) has_ball
142 they_have_ball = any (\x.not (sameClub me x)) has_ball
143 i_have_ball = ballIsGainedBy me.playerID football
145 ball_their_half = closerToHome home zero ballPos.pxy.px
146 ball_in_reach distfunc = (dist me.pos ballPos) < (distfunc me)
148 our_goal = (centerOfGoal home field)
149 their_goal = (centerOfGoal (other home) field)
150 ballPos = (getBall x).ballPos
151 them = me opponents others
153 prec = maxGainReach me
155 closest :: [Footballer] Position -> Footballer
156 closest xs p = minListBy (\x y.(dist x.pos p) < (dist y.pos p)) xs
158 isClosest :: [Footballer] Footballer Position -> Bool
159 isClosest xs x p = closest [x:xs] p == x
161 closerToHome :: !Home -> a a -> Bool | Ord a
162 closerToHome East = (>)
163 closerToHome West = (<)
165 distToLine :: Position Position Position -> Metre
166 distToLine a b c = (abs (((b.px-a.px)*(a.py-c.py))-((a.px-c.px)*(b.py-a.py))))/d
168 (*) m1 m2 = (m (toReal m1)/(toReal m2))
169 (/) m1 m2 = (m (toReal m1)/(toReal m2))
170 d = sqrt(((b.px-a.px)*(b.px-a.px))+((b.py-a.py)*(b.py-a.py)))
172 base_TeamName_MartLubbers :: String
173 base_TeamName_MartLubbers = "Æsir"