-- network stub -- richard buckland -- task 2, comp1711 2003 s1 -- ver 0.2 17 April 2003 module Network ( Network, makeNetwork, nextTick, sendCommands, getLights, getProfit, getTicks, isAccident, isUnsafe, getMessages ) where import ThomasLib makeNetwork :: TrackData -> [(Train, Track)] -> Market -> [Speed] -> Network -- contruct a network simulator using: -- *the track specified by TrackData -- *the trains specified by the (Train,Track) pairs, -- each train will start at position 0 on a -- Simple track, facing in the direction from -- 'From' to 'To'. -- *The source/destinations/prices for the goods -- carried by the trucks -- *the speeds of the trains for the simulation. -- The first speed in the list is the tick 1 speed for -- the first train, then the tick 1 speed for the -- second train, .. then the tick 2 speed for the first -- train, and so on. If the list is finite then, when -- it is exhausted, start again from the beginning. -- nextTick :: Network -> Network -- simulate the network one tick. Move each train -- the distance determined by their next speed value. sendCommands :: Network -> [Command] -> Network -- change the network by processing a sequence of commands -- from the fat controllers control panel. getLights :: Network -> [On] -- return the current status of the lights on the Fat -- Controller's control panel. getTicks :: Network -> Int -- return the number of ticks since the simulation started. -------------------- -- function below for bonus marks -- implement the following function if you have time -- otherwise just leave it = niy getProfit :: Network -> [Profit] -- return the current profit for each train. This equals -- the profit obtained for past delivery of goods less -- a running cost of 1.0 per tick for each tick the train -- is not stopped. -------------------- -- functions below -- not needed in task2: leave them = niy -- to be implemented in project isAccident :: Network -> Bool -- True if two trains are on the same track (collision) -- OR -- if a command was issued in the current tick for a track -- on which there is a train (switching a track while a train -- is on it) isUnsafe :: Network -> Bool -- True if controls cannot be used to prevent a future accident -- with 100% certainty (under the conservative assumption that -- trains can travel at any speed.) getMessages :: Network -> [Message] -- extension - whenever the network is detected to be unsafe or when -- an accident occurs a message string (in a format to be -- provided) is to be added to the list of safety messages. This function -- returns the entire list (useful for debugging) -------------------------------------------------------------------- -- Implementation -------------------------------------------------------------------- -- data Network = -- you may change lines below here only YourOwnDefinitionHere deriving (Show) -- define the type to be whatever you like, but it MUST be a data -- type - not a type synonym -- you may derive Show etc for debugging - but comment it -- out when submitting -- niy = error "Not Implemented Yet" makeNetwork _ _ _ _ = niy nextTick = niy sendCommands _ _ = niy getLights _ = niy getProfit _ = niy getTicks _ = niy isAccident _ = niy isUnsafe _ = niy getMessages _ = niy