,(0.90,-0.05)\r
] \r
\r
-:: Mem = {home :: !Home, origpos :: Position}\r
+:: Mem = {home :: !Home, origpos :: Position, seed :: !RandomSeed}\r
+\r
+mirrorMem :: !Mem !FootballField -> Mem\r
+mirrorMem mm field = {mm & home=other mm.home, origpos=mirror field mm.origpos}\r
\r
Aesir :: !ClubName !Home !FootballField !Position !PlayersNumber !String -> Footballer\r
Aesir club home field position nr name\r
, effect = Nothing\r
, stamina = max_stamina\r
, health = max_health\r
- , brain = {memory = {home=home, origpos=position}, ai = mind field }\r
+ , brain = {memory=if (home == West) mm (mirrorMem mm field), ai = mind field}\r
}\r
- \r
-closerToGoal :: !Home -> Metre Metre -> Bool\r
-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
+ where\r
+ mm = {home=West, origpos=position, seed=nullRandomSeed}\r
+ \r
+nextRandomNumber :: !Mem -> (Int, !Mem)\r
+nextRandomNumber mm=:{seed} = let (i, newseed) = random seed in (i rem 100, {mm & seed=newseed})\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
- | 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=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
+// 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
+// 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: Some other player is the closest to the ball\r
+ | otherwise = halt (x, mm)\r
+// TODO: We have the ball\r
+| any (\x.ballIsGainedBy x.playerID football) us = halt (x, mm)\r
+ // TODO: I have the ball\r
+ | ballIsGainedBy me.playerID football\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
where\r
- us = me team others\r
ballPos = (getBall x).ballPos\r
- nextPos = nextPlayer home field us me.pos\r
- we_have_ball = or (map (\x.ballIsGainedBy x.playerID football) us)\r
-\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 == [] = centerOfGoal (other home) field\r
-| otherwise = (minListBy (\x y.(dist x.pos pos) < (dist y.pos pos)) xs).pos\r
-\r
+ them = me opponents others\r
+ us = me team others\r
+ prec = scale 0.5 (maxKickReach me)\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
-afterfix :: (FootballerAI m) !Position !Metre !(!BrainInput, m) -> (BrainOutput, m)\r
-afterfix after point diff (input=:{me}, m)\r
-| d < diff = after (input, m)\r
-| otherwise = (move, m)\r
+closerToGoal :: !Home -> Metre Metre -> Bool\r
+closerToGoal East = (<)\r
+closerToGoal West = (>)\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
+ where\r
+ (*) m1 m2 = (m (toReal m1)/(toReal m2))\r
+ (/) m1 m2 = (m (toReal m1)/(toReal m2))\r
+ d = sqrt(((b.px-a.px)*(b.px-a.px))+((b.py-a.py)*(b.py-a.py)))\r
+\r
+//afterfix :: (FootballerAI m) !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