,(0.90,-0.05)\r
] \r
\r
-:: Mem = {home :: !Home, origpos :: Position, seed :: !RandomSeed}\r
+:: Role = Attack | Mid | Defense | Keeper\r
+\r
+isAttack :: Role -> Bool\r
+isAttack Attack = True\r
+isAttack _ = False\r
+\r
+isMid :: Role -> Bool\r
+isMid Mid = True\r
+isMid _ = False\r
+\r
+isDefense :: Role -> Bool\r
+isDefense Defense = True\r
+isDefense _ = False\r
+\r
+isKeep :: Role -> Bool\r
+isKeep Keeper = True\r
+isKeep _ = False\r
+\r
+fromNumber :: Int -> Role\r
+fromNumber 1 = Keeper\r
+fromNumber i\r
+| i < 4 = Attack\r
+| i < 10 = Mid\r
+| otherwise = Defense\r
+\r
+:: Mem = {home :: !Home, origpos :: Position, seed :: !RandomSeed, role :: Role}\r
\r
mirrorMem :: !Mem !FootballField -> Mem\r
mirrorMem mm field = {mm & home=other mm.home, origpos=mirror field mm.origpos}\r
, brain = {memory=if (home == West) mm (mirrorMem mm field), ai = mind field}\r
}\r
where\r
- mm = {home=West, origpos=position, seed=nullRandomSeed}\r
+ mm = {home=West, origpos=position, seed=nullRandomSeed, role=fromNumber nr}\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
+mind field (x=:{referee,football,others,me}, mm=:{home,origpos,role})\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
+// 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
+ | otherwise \r
+ // Ball gained by them\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
+// If I'm a field player\r
+| otherwise\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
+ | we_have_ball = 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
-// TODO: The ball is with the others\r
-| otherwise = halt (x, mm)\r
where\r
+ we_have_ball = any (\x.ballIsGainedBy x.playerID football) us\r
ballPos = (getBall x).ballPos\r
them = me opponents others\r
us = me team others\r