initial framework added
[fp1415-soccerfun.git] / src / Game / matchGame.dcl
1 definition module matchGame
2
3 /** This module defines the match and tournament data structures.
4 */
5 import matchLog, guiInterface, render
6
7 :: FootballGame
8 = { match :: !Match // the football match to be played
9 , actionPics :: !ActionPics // the action-images
10 , history :: !History // recent history of game
11 , frames :: !Int // nr of frames so far (reset to zero every second)
12 , options :: !Options // options of football game
13 , logging :: !WhatToLog // logging options
14 }
15
16 :: Options
17 = { closeReferee :: !Bool // automatically close referee dialog after one second (True - default) or by user (False)
18 , showSplash :: !Bool // show splash screen at opening (False - default) or do (True)
19 , displaySpeed :: !DisplaySpeed // slow, normal or fast-play (Normal - default)
20 , showReferee :: !Bool // show referee-intermezzo (True - default) or not (False)
21 , playingTime :: !PlayingTime // default playingtime (defaultPlayingTime)
22 , renderStyle :: !RenderStyle // the chosen render style (flatland style is default)
23 }
24 instance toString Options
25 instance fromString Options
26 instance == Options
27
28 :: History
29 = { time :: !Seconds // time in seconds of length history
30 , past :: ![Match] // the recent history
31 }
32
33 /** incFrames game increases the frames count of game.
34 */
35 incFrames :: !FootballGame -> FootballGame
36
37 /* defaultPlayingTime returns recommended playing time
38 */
39 defaultPlayingTime :: PlayingTime
40
41 /** defaultOptions returns default options.
42 */
43 defaultOptions :: Options
44
45 /* timeLeft is True if the game has not finished
46 */
47 timeLeft :: !FootballGame -> Bool
48
49 /** getOptions env reads the options file (if present) and returns its content.
50 If no options file was found, it is created and filled with default values.
51 setOptions options stores the options in the options file.
52 */
53 getOptions :: !*env -> (!Options,!*env) | FileSystem env
54 setOptions :: !Options !*env -> *env | FileSystem env
55
56 :: Competition = { results :: ![[Maybe Score]] // teams x teams matrix of match results (note: team x team -> Nothing)
57 , west :: ![ClubName] // names of participating teams (west side)
58 , east :: ![ClubName] // names of participating teams (east side)
59 , usedRandomSeed:: !RandomSeed // the seed that is used for computing the matches
60 }
61 :: Ranking :== AssocList ClubName Rank
62 :: Rank = { matchpoints :: !Int // number of matchpoints (>= 0)
63 , goals_scored :: !Int // number of scored goals (>= 0)
64 , goals_against :: !Int // number of goals against (>= 0)
65 }
66 instance zero Rank
67 instance == Rank
68 instance < Rank
69 instance + Rank
70
71 /** competition teams field referee time rs
72 computes an entire competition between all teams in teams.
73 Each match uses the same referee and same initial random seed value rs.
74 */
75 competition :: ![Home FootballField -> Team] !FootballField !Referee !PlayingTime !RandomSeed -> Competition
76
77 /** computeMatch match
78 computes an entire match between the currently selected team1 and team2.
79 */
80 computeMatch :: !Match -> Score
81
82 /** ranking competition
83 computes the ranking of all teams that have participated in competition.
84 */
85 //ranking :: !Competition -> Ranking
86 ranking :: ![ClubName] ![Maybe Score] -> Ranking
87
88 /** checkCompetitionFile west_team_names rs env
89 checks whether there is a competition backup file present for the current set
90 of teams (assuming they start on the West home side) and initial random seed value rs
91 for computing matches.
92 If not, then such a file is created, and the same random seed value and empty list of scores is returned.
93 If so, then the currently stored random seed value and list of scores is returned.
94 */
95 checkCompetitionFile :: ![ClubName] !RandomSeed !*env -> (!(!RandomSeed,![Maybe Score]),!*env) | FileSystem env
96
97 /** appendMatchToCompetitionFile west east env
98 appends an empty entry of a match between west versus east in the competition backup file.
99 It also returns the file pointer to allow a correct update in updateMatchToCompetitionFile.
100 */
101 appendMatchToCompetitionFile:: !ClubName !ClubName !*env -> (!Int,!*env) | FileSystem env
102
103
104 /** updateMatchToCompetitionFile west east score filepointer env
105 updates the line that starts at filepointer in the competition backup file with the result
106 of the match between west versus east.
107 */
108 updateMatchToCompetitionFile:: !ClubName !ClubName !(Maybe Score) !Int !*env -> *env | FileSystem env