Google
 

Trailing-Edge - PDP-10 Archives - decuslib20-04 - decus/20-0135/10/cat.sim
There are 4 other files named cat.sim in the archive. Click here to see a list.
00050	OPTIONS(/l);
00100	BEGIN
00150	EXTERNAL CHARACTER PROCEDURE insinglechar, fetchar;
00200	EXTERNAL INTEGER PROCEDURE trmop, gettab, checkreal, checkint, iondx;
00250	EXTERNAL PROCEDURE echo, abort, outchr, depchar, forceout, outstring;
00275	EXTERNAL PROCEDURE outche;
00300	EXTERNAL BOOLEAN PROCEDURE meny, tmpout;
00350	EXTERNAL TEXT PROCEDURE storbokstav, scanto, tmpin, maketext;
00400	EXTERNAL CLASS termty;
00450	EXTERNAL CLASS vista;
00500	
00550	vista CLASS boardvista(boardwidth, boardheight);
00600	INTEGER boardwidth, boardheight;
00650	BEGIN
00700	  INTEGER boardwidthm1, boardheightm1;
00750	  PROCEDURE make_board;
00950	    COMMENT: Will make the whole screen blank. If
01000	    boardheight
01050	    and boardwidth are greater than zero,
01100	    a board of this size
01150	    is written on the screen;
01200	  BEGIN
01250	    INTEGER h, v;
01300	    sysout.outimage;
01350	    blank_the_screen;
01400	    IF boardwidth > 0 AND boardheight > 0 THEN
01450	    BEGIN
01500	      COMMENT type screen border;
01550	      home_the_cursor;
01600	      FOR h:= -1 STEP 1 UNTIL boardwidth DO
01650	      outchar('-');
01700	      FOR v:= 1 STEP 1 UNTIL boardheight DO
01750	      BEGIN
01800	        set_char_on_screen('!',0,v);
01850	        set_char_on_screen('!',boardwidth+1,v);
01900	      END;
01950	      move_the_cursor_to(0,boardheight+1);
02000	      FOR h:= -1 STEP 1 UNTIL boardwidth DO
02050	      outchar('-');
02100	    END;
02150	    home_the_cursor; breakoutimage;
02200	  END;
02250	  boardwidthm1:= boardwidth-1;
02300	  boardheightm1:= boardheight-1;
02350	END;
02400	
02450	INSPECT NEW boardvista(78, 16, sysin, sysout, FALSE, 0,
02500	NOTEXT, NOTEXT, 20, 8) DO
02550	BEGIN
02600	  simulation BEGIN
02650	    INTEGER numberofdeadrats, numberofsavedrats, exith,
02700	    u;
02750	    INTEGER numberofratholes;
02800	    INTEGER playtime, number_of_fillers,
02850	    sysin_strip_length;
02900	    INTEGER avoidingdistance;
02950	    REAL real_time_step, terminal_speed,
03000	    rat_intelligence, ratfactor;
03050	    TEXT blanks6;
03100	    BOOLEAN direction_ordered;
03150	    CHARACTER starter, direction;
03200	    REF(rat) therat;
03250	    REF(cat) thecat;
03300	
03350	    PROCEDURE setratfactor;
03400	    BEGIN
03450	      IF ratfactor < 0.5 THEN ratfactor:= 0.5 ELSE
03500	      IF ratfactor >= 0.96 THEN ratfactor:= 0.96;
03550	      ratfactor:= 0.005*(rat_intelligence+40);
03600	      IF numberofratholes >= 0 THEN
03650	      BEGIN
03700	        move_the_cursor_to(45,4);
03750	        outtext("Rat intelligence: ");
03800	        outfix(rat_intelligence,0,4);
03850	        home_the_cursor;
03900	      END;
03950	    END;
04000	
04050	
04100	    PROCEDURE
04150	    put_question_in_lower_left_corner(question);
04200	    VALUE question; TEXT question;
04250	    BEGIN
04300	      move_the_cursor_to(0,boardheight+4);
04350	      outtext(question);
04400	      outimage; outtext(blanks6); outimage;
04450	      outtext(blanks6);
04500	      move_the_cursor_to(0,boardheight+5);
04550	    END;
04600	
04650	    process CLASS animal;
04700	    BEGIN INTEGER v, h, vnew, hnew;
04750	    END;
     
04850	
04900	
04950	    animal CLASS rat;
05000	    BEGIN
05050	      INTEGER i; BOOLEAN dead;
05100	
05150	      INTEGER PROCEDURE clever_gives_positive;
05200	      clever_gives_positive:= IF draw(ratfactor,
05250	      u) THEN 1 ELSE -1;
05300	
05350	      jumpin:
05400	      h:= randint(1,boardwidth,u);
05450	      v:= randint(1,boardheight,u);
05500	      IF get_char_from_screen(h,
05550	      v) NE ' ' THEN GOTO jumpin;
05600	      WHILE NOT dead DO
05650	      BEGIN
05700	        set_char_on_screen(' ',h,v);
05750	        IF h = 0 OR h > boardwidth THEN
05800	        BEGIN
05850	          rat_intelligence:= rat_intelligence-42;
05900	          setratfactor;
05950	          numberofsavedrats:= numberofsavedrats+1;
06000	          move_the_cursor_to(boardwidth+7,boardheight+2);
06050	          start_blink;
06100	          move_the_cursor_to(numberofsavedrats+boardwidth+7,
06150	          boardheight+2);
06200	          outchar('o'); stop_blink;
06250	
06300	          thecat.eat:= 1; GOTO out;
06350	        END;
06400	        IF h = 1 AND v = exith AND numberofratholes >=
06450	        1 THEN h:= h-1 ELSE
06500	        IF h = boardwidth AND v = exith AND
06550	        numberofratholes >= 2
06600	        THEN h:= h+1 ELSE
06650	        BEGIN
06700	          hnew:= h + clever_gives_positive
06750	          * (IF numberofratholes <= 0 THEN
06800	          (IF h > boardwidth//2 THEN -1 ELSE 1)
06850	          ELSE IF numberofratholes <= 1 THEN -1
06900	          ELSE IF h > thecat.h THEN 1 ELSE IF h <
06950	          thecat.h THEN -1
07000	          ELSE ((IF h > boardwidth//2 THEN 1 ELSE -1)
07050	          * (IF h = 1 OR h = boardwidth THEN -1 ELSE
07100	          1)));
07150	          IF abs(v-thecat.v)+abs(h-thecat.h) <=
07200	          avoidingdistance THEN
07250	          vnew:= v + clever_gives_positive
07300	          * (IF v > thecat.v THEN 1 ELSE -1)
07350	          ELSE
07400	          vnew:= v + clever_gives_positive
07450	          * (IF v > exith THEN -1 ELSE 1);
07500	          IF get_char_from_screen(hnew, vnew) = ' ' THEN
07550	          BEGIN
07600	            h:= hnew; v:= vnew;
07650	          END ELSE
07700	          IF get_char_from_screen(hnew,vnew) = '|' THEN
07750	          BEGIN
07800	            hnew:= h;
07850	            IF get_char_from_screen(hnew,
07900	            vnew) = ' ' THEN
07950	            v:= vnew;
08000	          END ELSE
08050	          BEGIN
08100	            vnew:= v;
08150	            IF get_char_from_screen(hnew,
08200	            vnew) = ' ' THEN
08250	            h:= hnew;
08300	          END;
08350	
08400	        END;
08450	        set_char_on_screen('o',h,v);
08500	        IF h >= 0 THEN hold(1.0);
08550	        cause_real_time_delay((IF direction_ordered
08600	        THEN 2 ELSE 1)
08650	        *number_of_fillers);
08700	      END;
08750	      out:
08800	      ACTIVATE thecat DELAY 0;
08850	    END rat;
     
08950	
09000	
09050	    animal CLASS cat;
09100	    BEGIN
09150	      INTEGER eat;
09200	      v:= boardheight/2; h:= boardwidth/2;
09250	      GOTO jump;
09300	      WHILE TRUE DO
09350	      BEGIN
09400	        set_char_on_screen(' ',h,v);
09450	        jump:
09500	        IF (IF direction_ordered THEN direction = up OR
09550	        direction = down OR direction = linefeed
09600	        ELSE draw(0.5,u)) THEN
09650	        BEGIN COMMENT move vertically;
09700	          IF (IF direction_ordered THEN direction = up
09750	          ELSE v > therat.v)
09800	          THEN vnew:= v-1 ELSE vnew:= v+1;
09850	          hnew:= h;
09900	        END ELSE
09950	        BEGIN COMMENT move horizontally;
10000	          IF (IF direction_ordered THEN direction =
10050	          left ELSE h > therat.h)
10100	          THEN hnew:= h-1 ELSE hnew:= h+1;
10150	          vnew:= v;
10200	        END;
10250	        IF get_char_from_screen(hnew,vnew) = '-'
10300	        OR get_char_from_screen(hnew,vnew) = '|'
10350	        OR hnew = 0 OR hnew = boardwidth+1 THEN
10400	        BEGIN
10450	          IF NOT direction_ordered THEN GOTO jump
10500	          ELSE
10550	          BEGIN
10600	            hnew:= h; vnew:= v;
10650	          END;
10700	        END;
10750	
10800	        h:= hnew; v:= vnew;
10850	        IF get_char_from_screen(h,v) = 'o' THEN
10900	        BEGIN
10950	          therat.dead:= TRUE;
11000	          numberofdeadrats:= numberofdeadrats+1;
11050	          eat:= 1;
11100	          rat_intelligence:= rat_intelligence+25;
11150	          setratfactor;
11200	          move_the_cursor_to(boardwidth+7,0);
11250	          start_blink; outtext("Dead rats:"); stop_blink;
11300	          set_char_on_screen('o',
11350	          boardwidth+8+mod(numberofdeadrats-1,10),
11400	          1+((numberofdeadrats-1)//10));
11450	        END;
11500	        set_char_on_screen('&',h,v);
11550	        hold(1.0);
11600	        IF NOT direction_ordered THEN
11650	        cause_real_time_delay(number_of_fillers);
11700	        IF eat > 0 THEN
11750	        BEGIN
11800	          eat:= eat-1; IF eat = 0 THEN
11850	          BEGIN
11900	            therat:- NEW rat; ACTIVATE therat DELAY 0.5;
11950	            set_char_on_screen(' ',boardwidth+7,0);
12000	            outtext(" Dead rats:");
12050	          END;
12100	        END ELSE
12150	        BEGIN
12200	        END;
12250	      END;
12300	    END cat;
     
12350	
12400	
12450	    blanks6:- blanks(6);
12500	    INSPECT sysout DO INSPECT sysin DO
12550	    BEGIN
12600	      cancel_display;
12650	      outtext("Answer RETURN to get default values");
12700	      outtext(" on preliminary questions!");
12750	      outimage; outimage;
12800	      numberofratholes:= -1;
12850	      outtext("Input start random integer: ");
12900	      breakoutimage; inimage;
12950	      u:= IF sysin.image.strip.length = 0 THEN 87697
13000	      ELSE inint;
13050	      outtext(
13100	      "Input initial rat intelligence quotient: ");
13150	      breakoutimage; inimage;
13200	      rat_intelligence:= IF sysin.image.strip.length =
13250	      0 THEN 80 ELSE inreal;
13300	      outtext(
13350	      "Input distance at which rat is afraid of cat: ");
13400	      breakoutimage; inimage;
13450	      avoidingdistance:= IF sysin.image.strip.length =
13500	      0 THEN 2 ELSE inint;
13550	      outtext("Input number of ratholes, 0, 1 or 2: ");
13600	      breakoutimage; inimage;
13650	      numberofratholes:= IF sysin.image.strip.length =
13700	      0 THEN 2 ELSE inint;
13750	      outtext(
13800	      "Input wanted real step time in seconds: ");
13850	      breakoutimage; inimage;
13900	      real_time_step:= IF sysin.image.strip.length = 0
13950	      THEN 0.15 ELSE inreal;
13967	      terminal_speed:= trmspeed//10;
14250	      number_of_fillers:= real_time_step*terminal_speed;
14300	      resume_display;
14350	    END;
14400	
14450	    make_board;
14500	    exith:= boardheight//2+1;
14550	    IF numberofratholes > 0 THEN set_char_on_screen(' ',
14600	    0,exith);
14650	    IF numberofratholes > 1 THEN set_char_on_screen(' ',
14700	    boardwidth+1,exith);
14750	    home_the_cursor;
14800	    move_the_cursor_to(boardwidth+8,0);
14850	    outtext("Dead rats:"); stop_blink;
14900	    setratfactor;
14950	    move_the_cursor_to(boardwidth+8,boardheight);
15000	    outtext("Safe rats:");
15050	    move_the_cursor_to(boardwidth+7,boardheight+2);
15100	    start_blink;
15150	    move_the_cursor_to(75,boardheight+2);
15200	    stop_blink;
15250	    home_the_cursor;
15300	    thecat:- NEW cat; ACTIVATE thecat DELAY 0.5;
15350	    therat:- NEW rat; ACTIVATE therat;
15400	    hold(1.25);
15450	    WHILE TRUE DO
15500	    BEGIN
15550	      randomquestion:
15600	      put_question_in_lower_left_corner
15650	      ("Do you want random cat walk?                    ");
15700	      IF inyes THEN
15750	      BEGIN
15800	        put_question_in_lower_left_corner
15850	        ("Give number of play steps:                     ");
15900	        playtime:= inint;
15950	        IF playtime < 0 THEN
16000	        BEGIN
16050	          playtime:= -playtime;
16100	          restore_the_whole_screen;
16150	        END;
16200	        hold(playtime);
16250	      END ELSE COMMENT ordered cat walk;
16300	      BEGIN
16350	        put_question_in_lower_left_corner
16400	        ("Give direction of cat movement:                      "
16450	        "");
16500	        WHILE TRUE DO
16550	        BEGIN
16600	          getdirection:
16650	          move_the_cursor_to(thecat.h,thecat.v); breakoutimage;
16700	          direction:= insingle(FALSE);
16724	          direction_ordered:= controlchar AND
16737	          (direction = up OR direction = down OR direction = linefeed
16752	          OR direction = left OR direction = right);
16950	          IF NOT direction_ordered THEN
17000	          BEGIN
17050	            IF direction = '!' THEN GOTO exit ELSE
17100	            IF direction = altmode THEN GOTO
17150	            randomquestion
17200	            ELSE
17250	            BEGIN
17300	              restore_the_whole_screen;
17350	              GOTO getdirection;
17400	            END;
17450	          END;
17500	          hold(1.0);
17550	        END;
17600	      END;
17650	    END;
17700	
17750	
17800	  END comment simulation;
17850	END comment inspect vista;
17900	exit:
17950	END;