update before reboot
[fp1415-soccerfun.git] / src / Team_MartLubbers.icl
index 58be5ed..ee0de18 100644 (file)
@@ -68,26 +68,36 @@ closerToGoal :: !Home -> Metre Metre -> Bool
 closerToGoal East = (<)\r
 closerToGoal West = (>)\r
 \r
+getMin :: !Home -> Metre Metre -> Metre\r
+getMin h = getMax (other h)\r
+\r
+getMax :: !Home -> Metre Metre -> Metre\r
+getMax East = (max)\r
+getMax West = (min)\r
+\r
 mind :: !FootballField !(!BrainInput, !Mem) -> (!BrainOutput, !Mem)\r
 mind field (x=:{referee,football,others,me}, mm=:{home,origpos})\r
+# mm=:{home,origpos} = if (any isEndHalf referee) {home=other home, origpos=mirror field origpos} mm\r
 | ballIsGainedBy me.playerID football\r
-       | me.stamina > 0.5 = fix nextPos (m 1.0) (x, mm)\r
-       | otherwise = kick nextPos (x, mm)\r
+       | dist nextPos me.pos < (m 10.0) = kick nextPos (x, mm)\r
+       | otherwise = fix nextPos (m 1.0) (x, mm)\r
 | isClosest others me ballPos.pxy = afterfix (\(_, m).(GainBall, m)) ballPos.pxy (scale 0.5 (maxKickReach me)) (x, mm)\r
 | otherwise\r
-       | we_have_ball = fix {px=min ballPos.pxy.px (field.flength-me.pos.px), py=me.pos.py} (m 1.0) (x, mm)\r
-       | otherwise = fix origpos (m 1.0) (x, mm)\r
+       | we_have_ball = fix {px=getMin home ballPos.pxy.px (field.flength-me.pos.px), py=me.pos.py} (m 1.0) (x, mm)\r
+       | otherwise\r
+               | me.stamina > 0.5 = fix origpos (m 1.0) (x, mm)\r
+               | otherwise = halt (x, mm)\r
        where\r
                us = me team others\r
                ballPos = (getBall x).ballPos\r
-               nextPos = let np = nextPlayer home us me.pos in if (isNothing np) (centerOfGoal (other home) field) (fromJust np)\r
+               nextPos = nextPlayer home field us me.pos\r
                we_have_ball = or (map (\x.ballIsGainedBy x.playerID football) us)\r
 \r
-nextPlayer :: !Home [Footballer] Position -> Maybe Position\r
-nextPlayer home xs pos\r
+nextPlayer :: !Home !FootballField [Footballer] Position -> Position\r
+nextPlayer home field xs pos\r
 # xs = filter (\x.closerToGoal home x.pos.px pos.px) xs\r
-| xs == [] = Nothing\r
-| otherwise = Just (minListBy (\x y.(dist x.pos pos) < (dist y.pos pos)) xs).pos\r
+| xs == [] = centerOfGoal (other home) field\r
+| otherwise = (minListBy (\x y.(dist x.pos pos) < (dist y.pos pos)) xs).pos\r
 \r
 closest :: [Footballer] Position -> Footballer\r
 closest xs p = minListBy (\x y.(dist x.pos p) < (dist y.pos p)) xs\r