This commit was manufactured by cvs2svn to create tag 'buildscript'.
[IRC.git] /
1 /* Startup object is generated with the initialstate flag set by the
2  *  system to start the computation up */
3
4 // Create ServerSocket
5 task Startup(StartupObject s {initialstate}) {
6         System.printString("TTT Server Starting...\n");
7         ServerSocket ss = new ServerSocket(8000);
8         System.printString("Creating ServerSocket\n");
9         Board tttBoard = new Board() {init};
10         taskexit(s {!initialstate}); // Turn off initial state flag
11 }
12
13 //Listen for a request and accept request 
14 task AcceptConnection(ServerSocket ss{SocketPending}) {
15         System.printString("Waiting for connection...\n");
16         TTTServerSocket ttts = new TTTServerSocket() {TTTSInitialize};
17         System.printString("Calling accept...\n");
18         ss.accept(ttts);
19         System.printString("Connected...\n");
20 }
21
22 // Process incoming requests
23 task ProcessRequest(TTTServerSocket ttts{IOPending && TTTSInitialize}) {
24         System.printString("Request received...");
25         int action = ttts.receive();
26         if (action == 1) { // Make move
27                 taskexit(ttts {MakeMove});
28         }
29         else { // Send Error
30                 taskexit(ttts {SendError});
31         }
32 }
33
34 task ProcessMove(TTTServerSocket ttts{MakeMove}, Board tttBoard{init}) {
35         System.printString("Processing player's move...");
36         int result = tttBoard.makeMove(ttts.getRow(), ttts.getCol());
37         if (result == 1) { //Move made, send board display
38                 taskexit(ttts {!MakeMove, SendBoard});
39         }
40         else if (result == 2) { //Move made, game over
41                 taskexit(ttts {!MakeMove, SendDone});
42         }
43         else {// Error
44                 taskexit(ttts {!MakeMove, SendError});
45         }
46 }
47
48 task SendBoardDisplay(TTTServerSocket ttts{SendBoard}, Board tttBoard{init}) {
49         ttts.sendBoardDisplay(tttBoard);
50 }
51
52 task GameOver(TTTServerSocket ttts{SendDone}, Board tttBoard{init}) {
53         ttts.sendDone(tttBoard.winner());
54 }
55
56 task SendErrorMessage(TTTServerSocket ttts{SendError}, Board tttBoard{init}) {
57         ttts.sendError();
58 }