From: Mart Lubbers Date: Thu, 18 Jun 2015 09:40:33 +0000 (+0200) Subject: added keeper support X-Git-Url: https://git.martlubbers.net/?a=commitdiff_plain;h=6c0f896324adcdbce0717fd009a61924b9120e02;p=fp1415-soccerfun.git added keeper support --- diff --git a/src/Team_MartLubbers.icl b/src/Team_MartLubbers.icl index 2c53cc1..9fa5a09 100644 --- a/src/Team_MartLubbers.icl +++ b/src/Team_MartLubbers.icl @@ -47,7 +47,32 @@ where ,(0.90,-0.05) ] -:: Mem = {home :: !Home, origpos :: Position, seed :: !RandomSeed} +:: Role = Attack | Mid | Defense | Keeper + +isAttack :: Role -> Bool +isAttack Attack = True +isAttack _ = False + +isMid :: Role -> Bool +isMid Mid = True +isMid _ = False + +isDefense :: Role -> Bool +isDefense Defense = True +isDefense _ = False + +isKeep :: Role -> Bool +isKeep Keeper = True +isKeep _ = False + +fromNumber :: Int -> Role +fromNumber 1 = Keeper +fromNumber i +| i < 4 = Attack +| i < 10 = Mid +| otherwise = Defense + +:: Mem = {home :: !Home, origpos :: Position, seed :: !RandomSeed, role :: Role} mirrorMem :: !Mem !FootballField -> Mem mirrorMem mm field = {mm & home=other mm.home, origpos=mirror field mm.origpos} @@ -67,32 +92,47 @@ Aesir club home field position nr name , brain = {memory=if (home == West) mm (mirrorMem mm field), ai = mind field} } where - mm = {home=West, origpos=position, seed=nullRandomSeed} + mm = {home=West, origpos=position, seed=nullRandomSeed, role=fromNumber nr} nextRandomNumber :: !Mem -> (Int, !Mem) nextRandomNumber mm=:{seed} = let (i, newseed) = random seed in (i rem 100, {mm & seed=newseed}) mind :: !FootballField !(!BrainInput, !Mem) -> (!BrainOutput, !Mem) -mind field (x=:{referee,football,others,me}, mm=:{home,origpos}) +mind field (x=:{referee,football,others,me}, mm=:{home,origpos,role}) // In case of the end of the half, mirror memory | any (isEndHalf) referee = mind field ({x & referee=filter (\x.not (isEndHalf x)) referee}, mirrorMem mm field) // In case of a pause or end, just halt | any (isPauseGame) referee || any (isGameOver) referee = halt (x, mm) -// TODO:: The ball is free -| ballIsFree football - // I'm closest to the ball - | isClosest us me ballPos.pxy = afterfix (\(_,_).(GainBall, mm)) ballPos.pxy prec (x, mm) - // TODO: Some other player is the closest to the ball +// If I'm a keeper +| isKeep role + // Ball is in the other half of the field + | closerToGoal home ballPos zero = halt (x, mm) + // Ball gained by us + | we_have_ball + // Ball not in penalty area + | closerToGoal home ballPos {px=penalty_area_depth, py=zero} = halt (x, mm) + // Ball in penalty area + | otherwise + // Ball gained by them | otherwise = halt (x, mm) -// TODO: We have the ball -| any (\x.ballIsGainedBy x.playerID football) us = halt (x, mm) - // TODO: I have the ball - | ballIsGainedBy me.playerID football - // TODO: Someone else has the ball +// If I'm a field player +| otherwise + // TODO:: The ball is free + | ballIsFree football + // I'm closest to the ball + | isClosest us me ballPos.pxy = afterfix (\(_,_).(GainBall, mm)) ballPos.pxy prec (x, mm) + // TODO: Some other player is the closest to the ball + | otherwise = halt (x, mm) + // TODO: We have the ball + | we_have_ball = halt (x, mm) + // TODO: I have the ball + | ballIsGainedBy me.playerID football + // TODO: Someone else has the ball + | otherwise = halt (x, mm) + // TODO: The ball is with the others | otherwise = halt (x, mm) -// TODO: The ball is with the others -| otherwise = halt (x, mm) where + we_have_ball = any (\x.ballIsGainedBy x.playerID football) us ballPos = (getBall x).ballPos them = me opponents others us = me team others