1 implementation module RefereeCoach_Passing_Assignment
5 import Team_Opponent_Passing_Assignment
7 RefereeCoach_Passing :: !FootballField -> Referee
8 RefereeCoach_Passing field = { name = "RefereeCoach Passing"
9 , brain = { memory = initMem
10 , ai = randomlessRefereeAI (brain field)
15 :: Memory = { first :: !Bool
16 , kickedBy1 :: !Bool // PA: oh dear, you should use [Bool], or better: if in sequence: Int
22 , pos1 :: !Position // PA: dito, but now [Position]
28 , practiceFailed :: !Bool
33 initMem = { first = True
46 , practiceFailed = False
50 brain :: !FootballField !(!RefereeInput,!Memory) -> (!RefereeOutput,!Memory)
51 brain field ({RefereeInput | theBall=ballState, team1, team2}, memory)
52 | memory.gameOver // game over because of succes or failure
54 | memory.practiceFailed // assignment has failed
55 = ([TellMessage "Assignment failed, correct your team and try again"],{memory & gameOver = True})
56 | length players <> 6 // Check if there are indeed six fielders (to prevent run time errors)
57 = ([TellMessage "Number of fielders should be six. Correct your team and try again."],{memory & gameOver = True})
58 # (refActions,memory) = if memory.first // when first, alter ball pos and remember all positions
59 ([DirectFreeKick studentHome ballKickoff],{updateAllPos memory & first = False})
61 # playersMovedToFar = getPlayersThatMovedTooFar memory // check if players did not move more than 10 meters from their starting positions
62 | not (isEmpty playersMovedToFar)
63 = (refActions ++ getMessagesForTooFarPlayers playersMovedToFar,{memory & practiceFailed = True})
64 | not memory.kickedBy1 // first player has not kicked the ball yet
65 # (more,memory) = checkIfPlayerKickedBall 1 memory
66 = (refActions++more,memory)
67 | not memory.kickedBy2 // second player has not kicked the ball yet
68 # (more,memory) = checkIfPlayerKickedBall 2 memory
69 = (refActions++more,memory)
70 | not memory.kickedBy3 // third player has not kicked the ball yet
71 # (more,memory) = checkIfPlayerKickedBall 3 memory
72 = (refActions++more,memory)
73 | not memory.kickedBy4 // fourth player has not kicked the ball yet
74 # (more,memory) = checkIfPlayerKickedBall 4 memory
75 = (refActions++more,memory)
76 | not memory.kickedBy5 // fifth player has not kicked the ball yet
77 # (more,memory) = checkIfPlayerKickedBall 5 memory
78 = (refActions++more,memory)
79 | not memory.kickedBy6 // sixth player has not kicked the ball yet
80 # (more,memory) = checkIfPlayerKickedBall 6 memory
81 = (refActions++more,memory)
82 | ballIsGoingInWrongDirection // ball is going in the wrong direction
83 = (refActions ++ [TellMessage "ball should be played towards the goal"],{memory & practiceFailed = True})
84 | ballBehindLine // ball is behind the line
85 | theBall.ballPos.pz > goal_height // ball is over
86 = (refActions ++ [TellMessage "Try shooting less high, the ball went over"],{memory & practiceFailed = True})
87 | isbetween theBall.ballPos.pxy.py south_pole north_pole
88 = (refActions ++ [TellMessage "Well Done! Move on to the next assignment!"],{memory & gameOver = True})
90 = (refActions ++ [TellMessage "Ball is out, try shooting in the goal next time"],{memory & practiceFailed = True})
91 | theBall.ballSpeed.vxy.velocity == zero // ball stopped moving
92 = (refActions ++ [TellMessage "Try shooting harder, the ball stopped moving forwards"],{memory & practiceFailed = True})
93 | otherwise // ball may be on its way to the goal
96 theBall = getFootball ballState (team1 ++ team2)
97 (compTeam,(studentTeam,studentHome)) = if (stringStarts (nameOf team1) base_TeamName_Opponent_Passing) (team1,(team2,East)) (team2,(team1,West))
98 ballKickoff = {zero & px = if (studentHome == West) (scale -0.5 field.flength + penalty_area_depth) (scale 0.5 field.flength - penalty_area_depth)}
99 getMessagesForTooFarPlayers = map (\fb -> TellMessage ("Your player with number " <+++ fb.playerID.playerNr <+++ " moved further than 10 meters"))
100 (north_pole,south_pole) = goal_poles field
102 players = filter isFielder studentTeam
109 stud1fa = getAction stud1.playerID
110 stud2fa = getAction stud2.playerID
111 stud3fa = getAction stud3.playerID
112 stud4fa = getAction stud4.playerID
113 stud5fa = getAction stud5.playerID
114 stud6fa = getAction stud6.playerID
116 getAction :: !FootballerID -> Maybe FootballerEffect
117 getAction playerID = case [fb.effect \\ fb <- team1 ++ team2 | identify_player playerID fb] of
121 ballIsGoingInWrongDirection = if (studentHome == West) > < theBall.ballSpeed.vxy.direction (rad (0.5*pi)) &&
122 if (studentHome == East) < > theBall.ballSpeed.vxy.direction (rad (1.5*pi))
123 ballBehindLine = abs theBall.ballPos.pxy.px > scale 0.5 field.flength
125 updateAllPos :: !Memory -> Memory
126 updateAllPos memory = {memory & pos1 = stud1.pos
134 getPlayersThatMovedTooFar :: !Memory -> [Footballer]
135 getPlayersThatMovedTooFar memory
136 = [fb \\ fb <- players & pos <- [memory.pos1,memory.pos2,memory.pos3,memory.pos4,memory.pos5,memory.pos6] | dist fb pos > m 10.0]
138 checkIfPlayerKickedBall :: !Int !Memory -> (![RefereeAction],!Memory)
139 checkIfPlayerKickedBall i memory
140 # (studfa,stud) = case i of
147 | perhaps isKickedBall studfa = ([], updateMemory i memory)
148 | perhaps isCaughtBall studfa = ([Hands stud.playerID, ReprimandPlayer stud.playerID RedCard],{memory & practiceFailed = True})
149 | otherwise = ([], memory)
151 updateMemory :: !Int !Memory -> Memory
152 updateMemory 1 m = {m & kickedBy1 = True}
153 updateMemory 2 m = {m & kickedBy2 = True}
154 updateMemory 3 m = {m & kickedBy3 = True}
155 updateMemory 4 m = {m & kickedBy4 = True}
156 updateMemory 5 m = {m & kickedBy5 = True}
157 updateMemory 6 m = {m & kickedBy6 = True}