Universität Ulm,
Fakultät für Mathematik und Wirtschaftswissenschaften,
SAI
SS 99 || Ferienprojekt zu Allgemeine Informatik II || Puzzle Library
MODULE PuzzleGames
MODULE PuzzleGames;
IMPORT ChessClocks, Events, Iterators, NetIO, Objects, PersistentEvents,
PersistentObjects, Puzzle, PuzzlePlayers, RemoteObjects, Services,
Streams;
TYPE
Interface = POINTER TO InterfaceRec;
Game = POINTER TO GameRec;
GameRec =
RECORD
(Services.ObjectRec)
if: Interface;
END;
Event = POINTER TO EventRec;
EventRec =
RECORD
(Events.EventRec)
game: Game;
moveNumber: INTEGER; (* counting from 0 *)
move: Puzzle.Move;
situation: Puzzle.Situation; (* after move *)
END;
TYPE
GetNamesProc = PROCEDURE (game: Game; VAR name1, name2: ARRAY OF CHAR);
GetCurrentSituationProc = PROCEDURE (game: Game;
VAR situation: Puzzle.Situation);
GetChessClockProc = PROCEDURE (game: Game;
VAR chessclock: ChessClocks.ChessClock);
TakeInterestProc = PROCEDURE (game: Game;
VAR eventType: Events.EventType);
IterateMovesProc = PROCEDURE (game: Game; VAR it: Iterators.Iterator);
InterfaceRec =
RECORD
(Objects.ObjectRec)
getNames: GetNamesProc;
getCurrentSituation: GetCurrentSituationProc;
getChessClock: GetChessClockProc;
takeInterest: TakeInterestProc;
iterateMoves: IterateMovesProc;
END;
VAR
typeOfMove: Services.Type;
typeOfSituation: Services.Type;
pevtype: PersistentEvents.Type;
PROCEDURE Support(eventType: Events.EventType);
BEGIN
PersistentEvents.Init(eventType, pevtype);
END Support;
PROCEDURE Init(game: Game; if: Interface);
BEGIN
ASSERT((if.getNames # NIL) & (if.getCurrentSituation # NIL) &
(if.getChessClock # NIL) & (if.takeInterest # NIL) &
(if.iterateMoves # NIL));
game.if := if;
END Init;
PROCEDURE GetNames(game: Game; VAR name1, name2: ARRAY OF CHAR);
BEGIN
game.if.getNames(game, name1, name2);
END GetNames;
PROCEDURE GetCurrentSituation(game: Game; VAR situation: Puzzle.Situation);
BEGIN
game.if.getCurrentSituation(game, situation);
END GetCurrentSituation;
PROCEDURE GetChessClock(game: Game; VAR chessclock: ChessClocks.ChessClock);
BEGIN
game.if.getChessClock(game, chessclock);
END GetChessClock;
PROCEDURE TakeInterest(game: Game; VAR eventType: Events.EventType);
BEGIN
game.if.takeInterest(game, eventType); Support(eventType);
END TakeInterest;
PROCEDURE IterateMoves(game: Game; VAR it: Iterators.Iterator);
BEGIN
game.if.iterateMoves(game, it);
END IterateMoves;
PROCEDURE WriteEvent(s: Streams.Stream; event: Events.Event) : BOOLEAN;
BEGIN
WITH event: Event DO
RETURN RemoteObjects.Export(s, event.game) &
NetIO.WriteInteger(s, event.moveNumber) &
PersistentObjects.Write(s, event.move) &
PersistentObjects.Write(s, event.situation)
END;
END WriteEvent;
PROCEDURE ReadEvent(s: Streams.Stream; VAR event: Events.Event) : BOOLEAN;
VAR
newevent: Event;
BEGIN
NEW(newevent); event := newevent;
WITH event: Event DO
RETURN RemoteObjects.Import(s, event.game) &
NetIO.ReadInteger(s, event.moveNumber) &
PersistentObjects.GuardedRead(s, typeOfMove, event.move) &
PersistentObjects.GuardedRead(s,
typeOfSituation, event.situation)
END;
END ReadEvent;
PROCEDURE InitModule;
VAR
type: Services.Type;
persevif: PersistentEvents.Interface;
BEGIN
Services.CreateType(type, "PuzzleGames.Game", "");
Services.SeekType("Puzzle.Move", typeOfMove);
Services.SeekType("Puzzle.Situation", typeOfSituation);
NEW(persevif);
persevif.write := WriteEvent; persevif.read := ReadEvent;
PersistentEvents.CreateType(pevtype, "PuzzleGames.Event", persevif);
END InitModule;
BEGIN
InitModule;
END PuzzleGames.
SS 99 || Ferienprojekt zu Allgemeine Informatik II || Puzzle Library
Andreas Borchert, 26. Juli 1999