From 47e02a99ddbf61d4834e192292f42ad163c4a300 Mon Sep 17 00:00:00 2001 From: Mart Lubbers Date: Mon, 8 Jun 2015 14:54:25 +0200 Subject: [PATCH] small referee patch to place ball correctly and passing done --- src/SoccerFun.prj | 0 src/SoccerFun_options.txt | 2 +- .../RefereeCoach_Passing_Assignment.icl | 3 +- .../Team_Student_Passing_Assignment.icl | 50 +++++++++++++++++-- .../Team_Student_Slalom_Assignment.icl | 17 +++++-- 5 files changed, 62 insertions(+), 10 deletions(-) mode change 100755 => 100644 src/SoccerFun.prj mode change 100755 => 100644 src/SoccerFun_options.txt mode change 100755 => 100644 src/StdTeam/Team_Student_Slalom_Assignment.icl diff --git a/src/SoccerFun.prj b/src/SoccerFun.prj old mode 100755 new mode 100644 diff --git a/src/SoccerFun_options.txt b/src/SoccerFun_options.txt old mode 100755 new mode 100644 index 787224a..deea162 --- a/src/SoccerFun_options.txt +++ b/src/SoccerFun_options.txt @@ -1 +1 @@ -{closeReferee=True,showSplash=False,displaySpeed=Normal,showReferee=True,playingTime=4:00 min,renderStyle=Fixed camera} \ No newline at end of file +{closeReferee=True,showSplash=False,displaySpeed=Faster,showReferee=True,playingTime=4:00 min,renderStyle=Fixed camera} \ No newline at end of file diff --git a/src/StdReferee/RefereeCoach_Passing_Assignment.icl b/src/StdReferee/RefereeCoach_Passing_Assignment.icl index 6ab6e2f..d5fdc6a 100644 --- a/src/StdReferee/RefereeCoach_Passing_Assignment.icl +++ b/src/StdReferee/RefereeCoach_Passing_Assignment.icl @@ -95,7 +95,8 @@ brain field ({RefereeInput | theBall=ballState, team1, team2}, memory) where theBall = getFootball ballState (team1 ++ team2) (compTeam,(studentTeam,studentHome)) = if (stringStarts (nameOf team1) base_TeamName_Opponent_Passing) (team1,(team2,East)) (team2,(team1,West)) - ballKickoff = {zero & px = if (studentHome == West) (scale -0.5 field.flength + penalty_area_depth) (scale 0.5 field.flength - penalty_area_depth)} + ballKickoff = {zero & px = if (studentHome == West) (scale -0.5 field.flength + scale 2.0 penalty_area_depth) (scale 0.5 field.flength - scale 2.0 penalty_area_depth)} +// ballKickoff = {zero & px = if (studentHome == West) (scale -0.5 field.flength + penalty_area_depth) (scale 0.5 field.flength - penalty_area_depth)} getMessagesForTooFarPlayers = map (\fb -> TellMessage ("Your player with number " <+++ fb.playerID.playerNr <+++ " moved further than 10 meters")) (north_pole,south_pole) = goal_poles field diff --git a/src/StdTeam/Team_Student_Passing_Assignment.icl b/src/StdTeam/Team_Student_Passing_Assignment.icl index ce8f846..075236d 100644 --- a/src/StdTeam/Team_Student_Passing_Assignment.icl +++ b/src/StdTeam/Team_Student_Passing_Assignment.icl @@ -9,11 +9,13 @@ implementation module Team_Student_Passing_Assignment */ import Footballer +import FootballerFunctions +import StdMaybe Team_Student_Passing :: !Home FootballField -> Team Team_Student_Passing home field = if (home == West) team (mirror field team) where - team = [ {footballer {clubName=club,playerNr=nr} & pos = toPosition (scale (0.5*x) field.flength,scale (0.5*y) field.fwidth),nose = rad (dir*pi)} + team = [ {footballer {clubName=club,playerNr=nr} nr & pos = toPosition (scale (0.5*x) field.flength,scale (0.5*y) field.fwidth),nose = rad (dir*pi)} \\ (x,y) <- positions & nr <- [2..] & dir <- noses @@ -27,7 +29,49 @@ where ,( 0.43,-0.05) ] noses = [1.8,0.0,1.5,0.5,1.2,0.2] - footballer playerID = defaultFootballer playerID // implement your footballer here - + footballer playerID nr = {defaultFootballer playerID & name = "Peter88_" +++ toString nr, brain = {memory=False, ai=mind (getOps field home)}} + base_TeamName_Student_Passing :: String base_TeamName_Student_Passing = "Student Passing" + + +:: Ops = { + c :: Metre Metre -> Bool, + a :: Metre Metre -> Metre, + s :: Metre Metre -> Metre, + g :: Position} + +getOps :: !FootballField !Home -> Ops +getOps field West = {c=(<), a=(+), s=(-), g={px=scale 0.5 field.flength, py=(m 0.0)}} +getOps field East = {c=(>), a=(-), s=(+), g={px= ~(scale 0.5 field.flength), py=(m 0.0)}} + +mind :: !Ops !(!BrainInput, !Bool) -> (!BrainOutput, !Bool) +mind op (x=:{me,others}, mm) +| mm || not (best (me team others) me bp) = halt (x, mm) +| otherwise = (afterfix (((\f.(\(i, _).(f i, True))) o kick`) kickpos) bp (maxKickReach me)) (x, mm) + where + bp = (getBall x).ballPos.pxy + + kickpos = let f = nextPlayer others me in if (isNothing f) op.g (fromJust f).pos + + nextPlayer :: [Footballer] Footballer -> Maybe Footballer + nextPlayer [] me = Nothing + nextPlayer [x:xs] me + | op.c x.pos.px me.pos.px = nextPlayer xs me + | otherwise = Just x + + best :: [Footballer] Footballer Position -> Bool + best [] _ _ = True + best [x:xs] me bp + | dist x.pos bp < dist me.pos bp = False + | otherwise = best xs me bp + + afterfix after point diff (input=:{me}, m) + | d < diff = after (input, m) + | otherwise = (move, m) + where + d = dist me point + a = bearing zero me point + r = bearing me.nose me point + v = ms (max 6.0 (toReal d)) + move = Move {direction=a, velocity=v} r \ No newline at end of file diff --git a/src/StdTeam/Team_Student_Slalom_Assignment.icl b/src/StdTeam/Team_Student_Slalom_Assignment.icl old mode 100755 new mode 100644 index 94bf10c..a62f4a5 --- a/src/StdTeam/Team_Student_Slalom_Assignment.icl +++ b/src/StdTeam/Team_Student_Slalom_Assignment.icl @@ -1,3 +1,4 @@ + implementation module Team_Student_Slalom_Assignment /** Implement a solution to the slalom assignment. @@ -23,14 +24,20 @@ base_TeamName_Student_Slalom :: String base_TeamName_Student_Slalom = "Student Slalom" mind :: !FootballField !Home !(!BrainInput, !Void) -> (!BrainOutput, !Void) -mind field home (x=:{me,others}, mm) = (fix {px=pp2 cp.px (m 2.5), py=up cp.py (m 3.5)} (m 1.0)) (x, mm) +mind field home (x=:{me,others}, mm) +| dist (getBall x).ballPos me.pos < (maxKickReach me) = (kick {px=sig (scale 0.5 field.flength), py=m 0.0}) (x, mm) +| otherwise = (fix {px=pp2 cp.px (m 2.5), py=up cp.py (m 3.5)} (maxKickReach me)) (x, mm) where - (comparator, pp1, pp2, targetsig) = if (home == West) ((<), (-), (+), (\w.w)) ((>), (+), (-), (~)) - sf = sortBy (\x y.comparator x.pos.px y.pos.px) others - (cp, up) = closestPos (zip2 [1..] sf) (pp1 me.pos.px xWidthFootballer) {px=targetsig (scale 0.5 field.flength), py=(m 0.0)} comparator + (comparator, pp1, pp2, sig) = if (home == West) ((<), (-), (+), (\w.w)) ((>), (+), (-), (~)) + sf2 = sortBy (\x y.comparator x.pos.px y.pos.px) others + sf = sf2 % (0, (length sf2) - 2) + (cp, up) = closestPos (zip2 [1..] sf) (pp1 me.pos.px xWidthFootballer) (getBall x).ballPos.pxy comparator closestPos :: [(Int, Footballer)] Metre Position (Metre Metre -> Bool) -> (Position, (Metre Metre -> Metre)) -closestPos [] _ d _ = (d, (+)) +closestPos [] _ d _ = (d, (\x y.x)) closestPos [(i, x):xs] p d c | c p x.pos.px = (x.pos, if (i rem 2 == 0) (+) (-)) | otherwise = closestPos xs p d c + + + -- 2.20.1