\r
mind :: !FootballField !(!BrainInput, !Mem) -> (!BrainOutput, !Mem)\r
mind field (x=:{referee,football,others,me}, mm=:{home,origpos,role})\r
+# (i, mm) = nextRandomNumber mm\r
// In case of the end of the half, mirror memory\r
| any (isEndHalf) referee = mind field ({x & referee=filter (\x.not (isEndHalf x)) referee}, mirrorMem mm field)\r
// In case of a pause or end, just halt\r
| any (isPauseGame) referee || any (isGameOver) referee = halt (x, mm)\r
-// If I'm a keeper\r
| isKeep role\r
- // Ball is in the other half of the field\r
- | closerToGoal home ballPos zero = halt (x, mm)\r
- // Ball gained by us\r
- | we_have_ball\r
- // Ball not in penalty area\r
- | closerToGoal home ballPos {px=penalty_area_depth, py=zero} = halt (x, mm)\r
- // Ball in penalty area\r
+ | i_have_the_ball = kick kicktarget_keeper (x, mm)\r
+ | (dist me.pos ballPos) < (maxCatchReach me) = (CatchBall, mm)\r
+ | closerToHome home zero ballPos.pxy.px = halt (x, mm)\r
+ | ball_within_16\r
+ | ballIsFree football\r
+ | isClosest others me ballPos.pxy = halt (x, mm)\r
+ | otherwise = stayInGoal (x, mm)\r
+ | we_have_ball = stayInGoal (x, mm)\r
| otherwise \r
- // Ball gained by them\r
- | otherwise = halt (x, mm)\r
+ | length (filter player_within_16 them) == 1\r
+ | (dist me.pos ballPos.pxy) < (maxCatchReach me)= (CatchBall, mm)\r
+ | otherwise = fix ballPos.pxy (maxCatchReach me) (x, mm)\r
+ | otherwise = stayInGoal (x, mm)\r
+ | otherwise\r
+ | we_have_ball = halt (x, mm)\r
+ | otherwise = stayInGoal (x, mm)\r
// If I'm a field player\r
-| otherwise\r
- // TODO:: The ball is free\r
+| otherwise = halt (x, mm)\r
+/* // TODO:: The ball is free\r
| ballIsFree football\r
// I'm closest to the ball\r
| isClosest us me ballPos.pxy = afterfix (\(_,_).(GainBall, mm)) ballPos.pxy prec (x, mm)\r
// TODO: We have the ball\r
| we_have_ball = halt (x, mm)\r
// TODO: I have the ball\r
- | ballIsGainedBy me.playerID football\r
+ | ballIsGainedBy me.playerID football = halt (x, mm)\r
// TODO: Someone else has the ball\r
| otherwise = halt (x, mm)\r
// TODO: The ball is with the others\r
- | otherwise = halt (x, mm)\r
+ | otherwise = halt (x, mm)*/\r
where\r
+ stayInGoal = fix (attract goal_area_depth our_goal ballPos.pxy) prec\r
+ our_goal = (centerOfGoal home field)\r
+ their_goal = (centerOfGoal (other home) field)\r
+ kicktarget_keeper = their_goal //TODO\r
+ i_have_the_ball = ballIsGainedBy me.playerID football\r
+ player_within_16 p = inPenaltyArea field home p.pos\r
+ ball_within_16 = inPenaltyArea field home ballPos.pxy\r
we_have_ball = any (\x.ballIsGainedBy x.playerID football) us\r
+ they_have_ball = any (\x.ballIsGainedBy x.playerID football) them\r
ballPos = (getBall x).ballPos\r
them = me opponents others\r
us = me team others\r
prec = scale 0.5 (maxKickReach me)\r
- \r
+ \r
closest :: [Footballer] Position -> Footballer\r
closest xs p = minListBy (\x y.(dist x.pos p) < (dist y.pos p)) xs\r
\r
isClosest :: [Footballer] Footballer Position -> Bool\r
isClosest xs x p = closest [x:xs] p == x\r
\r
-closerToGoal :: !Home -> Metre Metre -> Bool\r
-closerToGoal East = (<)\r
-closerToGoal West = (>)\r
+closerToHome :: !Home -> a a -> Bool | Ord a\r
+closerToHome East = (>)\r
+closerToHome West = (<)\r
+\r
+closerToGoal :: !Home -> a a -> Bool | Ord a\r
+closerToGoal h = closerToHome (other h)\r
\r
distToLine :: Position Position Position -> Metre\r
distToLine a b c = (abs (((b.px-a.px)*(a.py-c.py))-((a.px-c.px)*(b.py-a.py))))/d\r
\r
afterfix :: (FootballerAI Mem) !Position !Metre !(!BrainInput, !Mem) -> (BrainOutput, !Mem)\r
afterfix after point diff (input=:{me,others}, mm)\r
-# (i, mm) = nextRandomNumber mm\r
| d < diff = after (input, mm)\r
-// There is a enemy standing in the way and I feel like it\r
-| (dist closestOpp me.pos) < (maxTackleReach me) && i < 15 = (Tackle closestOpp.playerID (ms 6.0), mm)\r
// There is no enemy standing in the way\r
| otherwise = (move, mm)\r
where\r
- closestOpp = closest (me opponents others) me.pos\r
d = dist me point\r
a = bearing zero me point\r
r = bearing me.nose me point\r