initial framework added
[fp1415-soccerfun.git] / src / Game / Team.icl
1 implementation module Team
2
3 import StdEnvExt
4 import Footballer
5 /* Import all standard teams: */
6 import TeamMiniEffie
7 import Team_Opponent_Slalom_Assignment
8 import Team_Opponent_Passing_Assignment
9 import Team_Opponent_DeepPass_Assignment
10 import Team_Opponent_Keeper_Assignment
11 import Team_Student_Rounds_Assignment
12 import Team_Student_Slalom_Assignment
13 import Team_Student_Passing_Assignment
14 import Team_Student_DeepPass_Assignment
15 import Team_Student_Keeper_Assignment
16
17 allAvailableTeams :: [Home FootballField -> Team]
18 allAvailableTeams = [ Team_MiniEffies
19 , Team_Student_Rounds
20 , Team_Student_Slalom
21 , Team_Student_Passing
22 , Team_Student_DeepPass
23 , Team_Student_Keeper
24 , Team_Opponent_Slalom
25 , Team_Opponent_Passing
26 , Team_Opponent_DeepPass
27 , Team_Opponent_Keeper
28 ]
29
30 instance nameOf Team where nameOf players
31 = case players of
32 [fb:_] = nameOf fb.playerID
33 none = abort "nameOf[Team]: applied to empty team.\n"
34
35 validateTeam :: !Team -> Team
36 validateTeam team = map validateFootballer team
37 where
38 validateFootballer :: !Footballer -> Footballer
39 validateFootballer fb=:{length} = {fb & length = setbetween length min_length max_length
40 , stamina = max_stamina
41 , health = max_health
42 }
43
44 isValidTeam :: !Team -> Bool
45 isValidTeam team = length clubNames == 1
46 &&
47 (isEmpty keepers || isValidKeeper (hd keepers))
48 &&
49 all isValidPlayer players
50 &&
51 sort (map nrOf players) == sort (removeDup (map nrOf players))
52 &&
53 not (isMember 1 (map nrOf fielders))
54 where
55 (keepers,fielders) = spanfilter isKeeper team
56 clubNames = removeDup (map clubOf players)
57 clubName = hd clubNames
58 players = keepers ++ fielders
59 clubOf fb = fb.playerID.clubName
60 nrOf fb = fb.playerID.playerNr
61 isValidKeeper fb = fb.playerID == {clubName=clubName,playerNr=1}
62 isValidPlayer fb = clubOf fb == clubName
63
64 allPlayersAtHome :: !FootballField !Home !Team -> Bool
65 allPlayersAtHome field home team = all atHome team
66 where
67 atHome = if (home == West) (\player -> player.Footballer.pos.px <= zero)
68 (\player -> player.Footballer.pos.px >= zero)
69
70 replaceInTeam :: ![Footballer] !Team -> Team
71 replaceInTeam fbs team = removeMembers team fbs ++ fbs
72
73 getTeam :: !ClubName ![Team] -> Team
74 getTeam cn teams = case [team \\ team<-teams | nameOf team==cn] of
75 [team:_] = team
76 _ = abort ("Team " <+++ cn <+++ " does not seem to exist.\n")
77
78 instance mirror [a] | mirror a where mirror field as = map (mirror field) as
79 instance mirror Footballer where mirror field fb = {fb & pos = mirror field fb.pos
80 , nose = mirror field fb.nose
81 , speed = mirror field fb.speed
82 }
83 instance mirror Position where mirror field pos = {pos & px = ~pos.px}
84 instance mirror Speed where mirror field speed = {speed & direction = mirror field speed.direction}
85 instance mirror Angle where mirror field angle = rad pi - angle