-- library & type definitions for Thomas -- richard buckland -- task 2, comp1711 2003 s1 -- ver 0.2 17 April 2003 -- 21 April 2003 - assumptions moved to Assumptions.txt -- ver 1.0 22 April 2003 - fixed typo in comments re behaviour -- of reversed fork tracks when receive -- a command module ThomasLib where ------------------------------------- -- types used in Network interface -- ------------------------------------- type TrackData = ([Track],[Light],[Control]) data Track = Simple TrackName From To | Fork TrackName From To To | Stop TrackName From deriving (Eq,Ord,Show,Read) type TrackName = String type From = TrackName type To = TrackName -- Simple = straight or curved section of track -- Fork = Y section, precisely one of the 'To' -- segments is connected to the 'From' -- segment depending on the position -- of the switch. -- Stop = a track terminator type Light = [Track] -- the fat controller has a number of lights on his control -- panel. A light is on (True) if and only if there is a -- train on any of the [Track] corresponding to that light. -- For simplicity we will say a train is "on" a section of track -- if and only if the very front of the train is on the track. -- Thus a train is only "on" one Track at any time. In this -- simulator we will regard each train as being a point (ie -- we will ignore its length) type Control = [(Track,Normal)] type Normal = Bool -- The fat controller has a number of On/Off control buttons on his -- control panel. If a control button is changed from to True to -- False, or visa versa, then a motor changes each Track in the -- Control's track list depending on whether the motor for that -- track is "normal" or "reversed". This means: -- -- -- 1. For "Normal" tracks: -- Simple tracks: -- Control Button==True = Stop train on this segment -- Control Button==False = Let train pass thru -- Fork tracks: -- Control Button==True = connect 'From' to first 'To' -- Control Button==False = connect 'From' to second 'To' -- -- 2. For "reversed" tracks: -- Simple tracks: -- Control Button==True = Let train pass thru -- Control Button==False = Stop train on this segment -- Fork tracks: -- Control Button==True = connect 'From' to second 'To' -- Control Button==False = connect 'From' to first 'To' type Train = (TrainName,[Truck]) data TrainName = Thomas | Gordon | James | Henry deriving (Eq,Ord,Show,Read) data Truck = Coal | Milk | Mail deriving (Eq,Ord,Show,Read) -- each train has a name and pulls some trucks -- each truck can carry one sort of good only type Market = ([Source],[Destination]) type Source = (Truck,Track) type Destination = (Truck,Track,Profit) type Profit = Float -- there are certain locations on the network where -- trucks can load up with their goods. This happens -- automatically the instant the train reaches the -- location. There is no need to stop and no option -- not to load up when passing a source location. -- there are certain locations on the network where -- trucks can unload (deliver) their goods. This -- happens automatically the instant the train reaches -- such a location. There is no need to stop. There -- is no option not to sell when passing such a location. -- When a truck unloads the train receives the -- corresponding profit. type Speed = Int -- each track is exactly 4 units long. In each tick of time -- a train travels 0,1,2,3 or 4 units depending on the speed -- of the train for that tick. The speed will be an integer -- in the range 0..4. Speeds greater than 4 are erroneous and -- will not occur. type Command = (ControlNum,On) type ControlNum = Int type On = Bool -- the Fat Controler issues commands by setting switches on his -- panel. (1,True) means set control button #1 to True. -- Control button #1 is the second Control in the [Control] given -- in the trackdata ("second" as list elements are numbered -- from 0 remember) type Message = String