Home » CEEFAX disks » telesoftware16.adl » 14-07-89/P\Sol

14-07-89/P\Sol

This website contains an archive of files for the Acorn Electron, BBC Micro, Acorn Archimedes, Commodore 16 and Commodore 64 computers, which Dominic Ford has rescued from his private collection of floppy disks and cassettes.

Some of these files were originally commercial releases in the 1980s and 1990s, but they are now widely available online. I assume that copyright over them is no longer being asserted. If you own the copyright and would like files to be removed, please contact me.

Tape/disk: Home » CEEFAX disks » telesoftware16.adl
Filename: 14-07-89/P\Sol
Read OK:
File size: 17BF bytes
Load address: 0000
Exec address: 0000
File contents
PROGRAM Solitaire(INPUT,OUTPUT);
{ A program to simulate and solve the game of solitaire, using a recursive
  backtracking algorithm.
  Rob Anderson. June '88
}

TYPE movetype = RECORD
                  sx,sy : INTEGER;   { x,y of source peg }
                  jx,jy : INTEGER;   { x,y of peg to be jumped }
                END;

VAR
  board      : ARRAY [1..7, 1..7] OF BOOLEAN;
  answer     : ARRAY [1..31] OF movetype;
  pegs, low, movenum, loop : INTEGER;       { pegs -> no. of pegs remaining.
                                              low -> fewest pegs remaining.
                                              movenum -> current move no.    }

{ ----------------------------- printboard --------------------------------- }
PROCEDURE printboard;
{ print the current solitaire board. }

VAR x,y : INTEGER;

BEGIN

  WRITELN('----------------------------');
  WRITELN('Number of pegs = ',pegs:3);
  FOR y := 1 TO 7 DO
  BEGIN
    FOR x := 1 TO 7 DO
      IF board[x,y]
      THEN WRITE('O')
      ELSE WRITE('1');
  WRITELN;
  END; { for x }
  WRITELN('----------------------------');

END; { printboard }


{ ----------------------------- initialise --------------------------------- }
PROCEDURE initialise;

VAR loop1, loop2 : INTEGER;

BEGIN

  WRITELN('Generating a solution for solitaire.');
  WRITELN('------------------------------------');

  { set up the board initially }
  FOR loop1 := 1 TO 7 DO
  BEGIN
    FOR loop2 := 1 TO 7 DO
      board[loop1,loop2] := FALSE;
  END; { for loop 1 }

  board[4,4] := TRUE;                  { Middle is initially empty }

  { Now make unused parts of array FALSE (ie empty), which speeds up checking
    process in the 'trymove' procedure. }
  board[1,1] := TRUE; board[2,1] := TRUE;
  board[1,2] := TRUE; board[2,2] := TRUE;
  board[6,1] := TRUE; board[7,1] := TRUE;
  board[6,2] := TRUE; board[7,2] := TRUE;
  board[1,6] := TRUE; board[2,6] := TRUE;
  board[1,7] := TRUE; board[2,7] := TRUE;
  board[6,6] := TRUE; board[7,6] := TRUE;
  board[6,7] := TRUE; board[7,7] := TRUE;

  pegs := 32;
  low  := 32;
  movenum := 1;

  printboard;

END; { initialise }



{ ------------------------------- trymove ---------------------------------- }
FUNCTION trymove : BOOLEAN;
{ recursive function which makes the moves. }

VAR
  xpos, ypos : INTEGER;
  goodmove  : BOOLEAN;

  { ------------------------- makemove (local to trymove) ------------------ }
  FUNCTION makemove(xsorc, ysorc, xmid,
                    ymid, xdest, ydest : INTEGER) : BOOLEAN;
  { decides if specified move is legal, and if so then the move is made. }

  VAR movemade : BOOLEAN;

    { ----------------------- legalpos (local to makemove) ----------------- }
    FUNCTION legalpos(x,y : INTEGER) : BOOLEAN;
    { decides if x,y is a legal coordinate on the board }
    BEGIN
      legalpos := ( ((x>2) AND (x<6) AND (y<3) AND (y>0)) OR
                    ((x>2) AND (x<6) AND (y>5) AND (y<8)) OR
                    ((x>0) AND (X<8) AND (y>2) AND (y<6))
                  )
    END; { legalpos }

  BEGIN
    movemade := FALSE;
    IF legalpos(xsorc,ysorc) AND legalpos(xdest, ydest)
    THEN
      IF NOT(board[xsorc,ysorc]) AND
         NOT(board[xmid,ymid]) AND
         board[xdest, ydest]
      THEN
      BEGIN
        { legal move, so make it }
        board[xsorc,ysorc] := TRUE;
        board[xmid,ymid] := TRUE;
        board[xdest,ydest] := FALSE;
        pegs := pegs - 1;
        movemade := TRUE;

        { now record the move }
        WITH answer[movenum] DO
        BEGIN
          sx := xsorc;
          sy := ysorc;
          jx := xmid;
          jy := ymid;
        END;
        movenum := SUCC(movenum);

      END; { then }
  makemove := movemade;
  END; { makemove }

  { ------------------------- undomove (local to trymove) ------------------ }
  PROCEDURE undomove(xsorc, ysorc, xmid,
                    ymid, xdest, ydest : INTEGER);
  { undo a move from which a solution could not be found. ie backtrack. }

  BEGIN
    board[xsorc,ysorc] := FALSE;
    board[xmid,ymid] := FALSE;
    board[xdest,ydest] := TRUE;
    pegs := pegs + 1;
    movenum := PRED(movenum);
  END; { undomove }


BEGIN

  { output some info to show program is still running! }
  IF pegs < low
  THEN
  BEGIN
    WRITELN('A new low has been found;');
    printboard;
    low := pegs;
  END; { if }

  goodmove := FALSE;

  IF (pegs = 1) AND NOT(board[4,4]) THEN goodmove := TRUE;

  { try to make a new move }
  FOR xpos := 1 TO 7 DO
  BEGIN
    FOR ypos := 1 TO 7 DO
    BEGIN

      { move right ? }
      IF NOT(goodmove)
      THEN
        IF makemove(xpos,ypos,xpos+1,ypos,xpos+2,ypos)
        THEN
        BEGIN
          goodmove := trymove;
          IF NOT(goodmove)
          THEN undomove(xpos,ypos,xpos+1,ypos,xpos+2,ypos);
        END; { if }

      { move left ? }
      IF NOT(goodmove)
      THEN
        IF makemove(xpos,ypos,xpos-1,ypos,xpos-2,ypos)
        THEN
        BEGIN
          goodmove := trymove;
          IF NOT(goodmove)
          THEN undomove(xpos,ypos,xpos-1,ypos,xpos-2,ypos);
        END; { if }

      { move up ? }
      IF NOT(goodmove)
      THEN
        IF makemove(xpos,ypos,xpos,ypos-1,xpos,ypos-2)
        THEN
        BEGIN
          goodmove := trymove;
          IF NOT(goodmove)
          THEN undomove(xpos,ypos,xpos,ypos-1,xpos,ypos-2);
        END; { if }

      { move down ? }
      IF NOT(goodmove)
      THEN
        IF makemove(xpos,ypos,xpos,ypos+1,xpos,ypos+2)
        THEN
        BEGIN
          goodmove := trymove;
          IF NOT(goodmove)
          THEN undomove(xpos,ypos,xpos,ypos+1,xpos,ypos+2);
        END; { if }

    END; { for ypos }
  END; { for xpos }

trymove := goodmove;

END; { trymove }



{ ---------------------------- main program --------------------------------- }

BEGIN

  initialise;
  IF trymove
  THEN
  BEGIN
    WRITELN('A solution has been found; ');
    printboard;
    FOR loop := 1 TO 31 DO
    WITH answer[loop] DO
      WRITE('Jump ',sx:1,',',sy:1,' over ',jx:1,',',jy:1,'. ');

  END { then }
  ELSE WRITELN('No solution?????');

  WRITELN;

END.
00000000  50 52 4f 47 52 41 4d 20  53 6f 6c 69 74 61 69 72  |PROGRAM Solitair|
00000010  65 28 49 4e 50 55 54 2c  4f 55 54 50 55 54 29 3b  |e(INPUT,OUTPUT);|
00000020  0d 7b 20 41 20 70 72 6f  67 72 61 6d 20 74 6f 20  |.{ A program to |
00000030  73 69 6d 75 6c 61 74 65  20 61 6e 64 20 73 6f 6c  |simulate and sol|
00000040  76 65 20 74 68 65 20 67  61 6d 65 20 6f 66 20 73  |ve the game of s|
00000050  6f 6c 69 74 61 69 72 65  2c 20 75 73 69 6e 67 20  |olitaire, using |
00000060  61 20 72 65 63 75 72 73  69 76 65 0d 20 20 62 61  |a recursive.  ba|
00000070  63 6b 74 72 61 63 6b 69  6e 67 20 61 6c 67 6f 72  |cktracking algor|
00000080  69 74 68 6d 2e 0d 20 20  52 6f 62 20 41 6e 64 65  |ithm..  Rob Ande|
00000090  72 73 6f 6e 2e 20 4a 75  6e 65 20 27 38 38 0d 7d  |rson. June '88.}|
000000a0  0d 0d 54 59 50 45 20 6d  6f 76 65 74 79 70 65 20  |..TYPE movetype |
000000b0  3d 20 52 45 43 4f 52 44  0d 20 20 20 20 20 20 20  |= RECORD.       |
000000c0  20 20 20 20 20 20 20 20  20 20 20 73 78 2c 73 79  |           sx,sy|
000000d0  20 3a 20 49 4e 54 45 47  45 52 3b 20 20 20 7b 20  | : INTEGER;   { |
000000e0  78 2c 79 20 6f 66 20 73  6f 75 72 63 65 20 70 65  |x,y of source pe|
000000f0  67 20 7d 0d 20 20 20 20  20 20 20 20 20 20 20 20  |g }.            |
00000100  20 20 20 20 20 20 6a 78  2c 6a 79 20 3a 20 49 4e  |      jx,jy : IN|
00000110  54 45 47 45 52 3b 20 20  20 7b 20 78 2c 79 20 6f  |TEGER;   { x,y o|
00000120  66 20 70 65 67 20 74 6f  20 62 65 20 6a 75 6d 70  |f peg to be jump|
00000130  65 64 20 7d 0d 20 20 20  20 20 20 20 20 20 20 20  |ed }.           |
00000140  20 20 20 20 20 45 4e 44  3b 0d 0d 56 41 52 0d 20  |     END;..VAR. |
00000150  20 62 6f 61 72 64 20 20  20 20 20 20 3a 20 41 52  | board      : AR|
00000160  52 41 59 20 5b 31 2e 2e  37 2c 20 31 2e 2e 37 5d  |RAY [1..7, 1..7]|
00000170  20 4f 46 20 42 4f 4f 4c  45 41 4e 3b 0d 20 20 61  | OF BOOLEAN;.  a|
00000180  6e 73 77 65 72 20 20 20  20 20 3a 20 41 52 52 41  |nswer     : ARRA|
00000190  59 20 5b 31 2e 2e 33 31  5d 20 4f 46 20 6d 6f 76  |Y [1..31] OF mov|
000001a0  65 74 79 70 65 3b 0d 20  20 70 65 67 73 2c 20 6c  |etype;.  pegs, l|
000001b0  6f 77 2c 20 6d 6f 76 65  6e 75 6d 2c 20 6c 6f 6f  |ow, movenum, loo|
000001c0  70 20 3a 20 49 4e 54 45  47 45 52 3b 20 20 20 20  |p : INTEGER;    |
000001d0  20 20 20 7b 20 70 65 67  73 20 2d 3e 20 6e 6f 2e  |   { pegs -> no.|
000001e0  20 6f 66 20 70 65 67 73  20 72 65 6d 61 69 6e 69  | of pegs remaini|
000001f0  6e 67 2e 0d 20 20 20 20  20 20 20 20 20 20 20 20  |ng..            |
00000200  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
*
00000220  20 20 6c 6f 77 20 2d 3e  20 66 65 77 65 73 74 20  |  low -> fewest |
00000230  70 65 67 73 20 72 65 6d  61 69 6e 69 6e 67 2e 0d  |pegs remaining..|
00000240  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
*
00000260  20 20 20 20 20 20 20 20  20 20 20 20 20 20 6d 6f  |              mo|
00000270  76 65 6e 75 6d 20 2d 3e  20 63 75 72 72 65 6e 74  |venum -> current|
00000280  20 6d 6f 76 65 20 6e 6f  2e 20 20 20 20 7d 0d 0d  | move no.    }..|
00000290  7b 20 2d 2d 2d 2d 2d 2d  2d 2d 2d 2d 2d 2d 2d 2d  |{ --------------|
000002a0  2d 2d 2d 2d 2d 2d 2d 2d  2d 2d 2d 2d 2d 2d 2d 20  |--------------- |
000002b0  70 72 69 6e 74 62 6f 61  72 64 20 2d 2d 2d 2d 2d  |printboard -----|
000002c0  2d 2d 2d 2d 2d 2d 2d 2d  2d 2d 2d 2d 2d 2d 2d 2d  |----------------|
000002d0  2d 2d 2d 2d 2d 2d 2d 2d  2d 2d 2d 2d 20 7d 0d 50  |------------ }.P|
000002e0  52 4f 43 45 44 55 52 45  20 70 72 69 6e 74 62 6f  |ROCEDURE printbo|
000002f0  61 72 64 3b 0d 7b 20 70  72 69 6e 74 20 74 68 65  |ard;.{ print the|
00000300  20 63 75 72 72 65 6e 74  20 73 6f 6c 69 74 61 69  | current solitai|
00000310  72 65 20 62 6f 61 72 64  2e 20 7d 0d 0d 56 41 52  |re board. }..VAR|
00000320  20 78 2c 79 20 3a 20 49  4e 54 45 47 45 52 3b 0d  | x,y : INTEGER;.|
00000330  0d 42 45 47 49 4e 0d 0d  20 20 57 52 49 54 45 4c  |.BEGIN..  WRITEL|
00000340  4e 28 27 2d 2d 2d 2d 2d  2d 2d 2d 2d 2d 2d 2d 2d  |N('-------------|
00000350  2d 2d 2d 2d 2d 2d 2d 2d  2d 2d 2d 2d 2d 2d 2d 27  |---------------'|
00000360  29 3b 0d 20 20 57 52 49  54 45 4c 4e 28 27 4e 75  |);.  WRITELN('Nu|
00000370  6d 62 65 72 20 6f 66 20  70 65 67 73 20 3d 20 27  |mber of pegs = '|
00000380  2c 70 65 67 73 3a 33 29  3b 0d 20 20 46 4f 52 20  |,pegs:3);.  FOR |
00000390  79 20 3a 3d 20 31 20 54  4f 20 37 20 44 4f 0d 20  |y := 1 TO 7 DO. |
000003a0  20 42 45 47 49 4e 0d 20  20 20 20 46 4f 52 20 78  | BEGIN.    FOR x|
000003b0  20 3a 3d 20 31 20 54 4f  20 37 20 44 4f 0d 20 20  | := 1 TO 7 DO.  |
000003c0  20 20 20 20 49 46 20 62  6f 61 72 64 5b 78 2c 79  |    IF board[x,y|
000003d0  5d 0d 20 20 20 20 20 20  54 48 45 4e 20 57 52 49  |].      THEN WRI|
000003e0  54 45 28 27 4f 27 29 0d  20 20 20 20 20 20 45 4c  |TE('O').      EL|
000003f0  53 45 20 57 52 49 54 45  28 27 31 27 29 3b 0d 20  |SE WRITE('1');. |
00000400  20 57 52 49 54 45 4c 4e  3b 0d 20 20 45 4e 44 3b  | WRITELN;.  END;|
00000410  20 7b 20 66 6f 72 20 78  20 7d 0d 20 20 57 52 49  | { for x }.  WRI|
00000420  54 45 4c 4e 28 27 2d 2d  2d 2d 2d 2d 2d 2d 2d 2d  |TELN('----------|
00000430  2d 2d 2d 2d 2d 2d 2d 2d  2d 2d 2d 2d 2d 2d 2d 2d  |----------------|
00000440  2d 2d 27 29 3b 0d 0d 45  4e 44 3b 20 7b 20 70 72  |--');..END; { pr|
00000450  69 6e 74 62 6f 61 72 64  20 7d 0d 0d 0d 7b 20 2d  |intboard }...{ -|
00000460  2d 2d 2d 2d 2d 2d 2d 2d  2d 2d 2d 2d 2d 2d 2d 2d  |----------------|
00000470  2d 2d 2d 2d 2d 2d 2d 2d  2d 2d 2d 2d 20 69 6e 69  |------------ ini|
00000480  74 69 61 6c 69 73 65 20  2d 2d 2d 2d 2d 2d 2d 2d  |tialise --------|
00000490  2d 2d 2d 2d 2d 2d 2d 2d  2d 2d 2d 2d 2d 2d 2d 2d  |----------------|
000004a0  2d 2d 2d 2d 2d 2d 2d 2d  2d 20 7d 0d 50 52 4f 43  |--------- }.PROC|
000004b0  45 44 55 52 45 20 69 6e  69 74 69 61 6c 69 73 65  |EDURE initialise|
000004c0  3b 0d 0d 56 41 52 20 6c  6f 6f 70 31 2c 20 6c 6f  |;..VAR loop1, lo|
000004d0  6f 70 32 20 3a 20 49 4e  54 45 47 45 52 3b 0d 0d  |op2 : INTEGER;..|
000004e0  42 45 47 49 4e 0d 0d 20  20 57 52 49 54 45 4c 4e  |BEGIN..  WRITELN|
000004f0  28 27 47 65 6e 65 72 61  74 69 6e 67 20 61 20 73  |('Generating a s|
00000500  6f 6c 75 74 69 6f 6e 20  66 6f 72 20 73 6f 6c 69  |olution for soli|
00000510  74 61 69 72 65 2e 27 29  3b 0d 20 20 57 52 49 54  |taire.');.  WRIT|
00000520  45 4c 4e 28 27 2d 2d 2d  2d 2d 2d 2d 2d 2d 2d 2d  |ELN('-----------|
00000530  2d 2d 2d 2d 2d 2d 2d 2d  2d 2d 2d 2d 2d 2d 2d 2d  |----------------|
00000540  2d 2d 2d 2d 2d 2d 2d 2d  2d 27 29 3b 0d 0d 20 20  |---------');..  |
00000550  7b 20 73 65 74 20 75 70  20 74 68 65 20 62 6f 61  |{ set up the boa|
00000560  72 64 20 69 6e 69 74 69  61 6c 6c 79 20 7d 0d 20  |rd initially }. |
00000570  20 46 4f 52 20 6c 6f 6f  70 31 20 3a 3d 20 31 20  | FOR loop1 := 1 |
00000580  54 4f 20 37 20 44 4f 0d  20 20 42 45 47 49 4e 0d  |TO 7 DO.  BEGIN.|
00000590  20 20 20 20 46 4f 52 20  6c 6f 6f 70 32 20 3a 3d  |    FOR loop2 :=|
000005a0  20 31 20 54 4f 20 37 20  44 4f 0d 20 20 20 20 20  | 1 TO 7 DO.     |
000005b0  20 62 6f 61 72 64 5b 6c  6f 6f 70 31 2c 6c 6f 6f  | board[loop1,loo|
000005c0  70 32 5d 20 3a 3d 20 46  41 4c 53 45 3b 0d 20 20  |p2] := FALSE;.  |
000005d0  45 4e 44 3b 20 7b 20 66  6f 72 20 6c 6f 6f 70 20  |END; { for loop |
000005e0  31 20 7d 0d 0d 20 20 62  6f 61 72 64 5b 34 2c 34  |1 }..  board[4,4|
000005f0  5d 20 3a 3d 20 54 52 55  45 3b 20 20 20 20 20 20  |] := TRUE;      |
00000600  20 20 20 20 20 20 20 20  20 20 20 20 7b 20 4d 69  |            { Mi|
00000610  64 64 6c 65 20 69 73 20  69 6e 69 74 69 61 6c 6c  |ddle is initiall|
00000620  79 20 65 6d 70 74 79 20  7d 0d 0d 20 20 7b 20 4e  |y empty }..  { N|
00000630  6f 77 20 6d 61 6b 65 20  75 6e 75 73 65 64 20 70  |ow make unused p|
00000640  61 72 74 73 20 6f 66 20  61 72 72 61 79 20 46 41  |arts of array FA|
00000650  4c 53 45 20 28 69 65 20  65 6d 70 74 79 29 2c 20  |LSE (ie empty), |
00000660  77 68 69 63 68 20 73 70  65 65 64 73 20 75 70 20  |which speeds up |
00000670  63 68 65 63 6b 69 6e 67  0d 20 20 20 20 70 72 6f  |checking.    pro|
00000680  63 65 73 73 20 69 6e 20  74 68 65 20 27 74 72 79  |cess in the 'try|
00000690  6d 6f 76 65 27 20 70 72  6f 63 65 64 75 72 65 2e  |move' procedure.|
000006a0  20 7d 0d 20 20 62 6f 61  72 64 5b 31 2c 31 5d 20  | }.  board[1,1] |
000006b0  3a 3d 20 54 52 55 45 3b  20 62 6f 61 72 64 5b 32  |:= TRUE; board[2|
000006c0  2c 31 5d 20 3a 3d 20 54  52 55 45 3b 0d 20 20 62  |,1] := TRUE;.  b|
000006d0  6f 61 72 64 5b 31 2c 32  5d 20 3a 3d 20 54 52 55  |oard[1,2] := TRU|
000006e0  45 3b 20 62 6f 61 72 64  5b 32 2c 32 5d 20 3a 3d  |E; board[2,2] :=|
000006f0  20 54 52 55 45 3b 0d 20  20 62 6f 61 72 64 5b 36  | TRUE;.  board[6|
00000700  2c 31 5d 20 3a 3d 20 54  52 55 45 3b 20 62 6f 61  |,1] := TRUE; boa|
00000710  72 64 5b 37 2c 31 5d 20  3a 3d 20 54 52 55 45 3b  |rd[7,1] := TRUE;|
00000720  0d 20 20 62 6f 61 72 64  5b 36 2c 32 5d 20 3a 3d  |.  board[6,2] :=|
00000730  20 54 52 55 45 3b 20 62  6f 61 72 64 5b 37 2c 32  | TRUE; board[7,2|
00000740  5d 20 3a 3d 20 54 52 55  45 3b 0d 20 20 62 6f 61  |] := TRUE;.  boa|
00000750  72 64 5b 31 2c 36 5d 20  3a 3d 20 54 52 55 45 3b  |rd[1,6] := TRUE;|
00000760  20 62 6f 61 72 64 5b 32  2c 36 5d 20 3a 3d 20 54  | board[2,6] := T|
00000770  52 55 45 3b 0d 20 20 62  6f 61 72 64 5b 31 2c 37  |RUE;.  board[1,7|
00000780  5d 20 3a 3d 20 54 52 55  45 3b 20 62 6f 61 72 64  |] := TRUE; board|
00000790  5b 32 2c 37 5d 20 3a 3d  20 54 52 55 45 3b 0d 20  |[2,7] := TRUE;. |
000007a0  20 62 6f 61 72 64 5b 36  2c 36 5d 20 3a 3d 20 54  | board[6,6] := T|
000007b0  52 55 45 3b 20 62 6f 61  72 64 5b 37 2c 36 5d 20  |RUE; board[7,6] |
000007c0  3a 3d 20 54 52 55 45 3b  0d 20 20 62 6f 61 72 64  |:= TRUE;.  board|
000007d0  5b 36 2c 37 5d 20 3a 3d  20 54 52 55 45 3b 20 62  |[6,7] := TRUE; b|
000007e0  6f 61 72 64 5b 37 2c 37  5d 20 3a 3d 20 54 52 55  |oard[7,7] := TRU|
000007f0  45 3b 0d 0d 20 20 70 65  67 73 20 3a 3d 20 33 32  |E;..  pegs := 32|
00000800  3b 0d 20 20 6c 6f 77 20  20 3a 3d 20 33 32 3b 0d  |;.  low  := 32;.|
00000810  20 20 6d 6f 76 65 6e 75  6d 20 3a 3d 20 31 3b 0d  |  movenum := 1;.|
00000820  0d 20 20 70 72 69 6e 74  62 6f 61 72 64 3b 0d 0d  |.  printboard;..|
00000830  45 4e 44 3b 20 7b 20 69  6e 69 74 69 61 6c 69 73  |END; { initialis|
00000840  65 20 7d 0d 0d 0d 0d 7b  20 2d 2d 2d 2d 2d 2d 2d  |e }....{ -------|
00000850  2d 2d 2d 2d 2d 2d 2d 2d  2d 2d 2d 2d 2d 2d 2d 2d  |----------------|
00000860  2d 2d 2d 2d 2d 2d 2d 2d  20 74 72 79 6d 6f 76 65  |-------- trymove|
00000870  20 2d 2d 2d 2d 2d 2d 2d  2d 2d 2d 2d 2d 2d 2d 2d  | ---------------|
00000880  2d 2d 2d 2d 2d 2d 2d 2d  2d 2d 2d 2d 2d 2d 2d 2d  |----------------|
00000890  2d 2d 2d 20 7d 0d 46 55  4e 43 54 49 4f 4e 20 74  |--- }.FUNCTION t|
000008a0  72 79 6d 6f 76 65 20 3a  20 42 4f 4f 4c 45 41 4e  |rymove : BOOLEAN|
000008b0  3b 0d 7b 20 72 65 63 75  72 73 69 76 65 20 66 75  |;.{ recursive fu|
000008c0  6e 63 74 69 6f 6e 20 77  68 69 63 68 20 6d 61 6b  |nction which mak|
000008d0  65 73 20 74 68 65 20 6d  6f 76 65 73 2e 20 7d 0d  |es the moves. }.|
000008e0  0d 56 41 52 0d 20 20 78  70 6f 73 2c 20 79 70 6f  |.VAR.  xpos, ypo|
000008f0  73 20 3a 20 49 4e 54 45  47 45 52 3b 0d 20 20 67  |s : INTEGER;.  g|
00000900  6f 6f 64 6d 6f 76 65 20  20 3a 20 42 4f 4f 4c 45  |oodmove  : BOOLE|
00000910  41 4e 3b 0d 0d 20 20 7b  20 2d 2d 2d 2d 2d 2d 2d  |AN;..  { -------|
00000920  2d 2d 2d 2d 2d 2d 2d 2d  2d 2d 2d 2d 2d 2d 2d 2d  |----------------|
00000930  2d 2d 20 6d 61 6b 65 6d  6f 76 65 20 28 6c 6f 63  |-- makemove (loc|
00000940  61 6c 20 74 6f 20 74 72  79 6d 6f 76 65 29 20 2d  |al to trymove) -|
00000950  2d 2d 2d 2d 2d 2d 2d 2d  2d 2d 2d 2d 2d 2d 2d 2d  |----------------|
00000960  2d 20 7d 0d 20 20 46 55  4e 43 54 49 4f 4e 20 6d  |- }.  FUNCTION m|
00000970  61 6b 65 6d 6f 76 65 28  78 73 6f 72 63 2c 20 79  |akemove(xsorc, y|
00000980  73 6f 72 63 2c 20 78 6d  69 64 2c 0d 20 20 20 20  |sorc, xmid,.    |
00000990  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
000009a0  79 6d 69 64 2c 20 78 64  65 73 74 2c 20 79 64 65  |ymid, xdest, yde|
000009b0  73 74 20 3a 20 49 4e 54  45 47 45 52 29 20 3a 20  |st : INTEGER) : |
000009c0  42 4f 4f 4c 45 41 4e 3b  0d 20 20 7b 20 64 65 63  |BOOLEAN;.  { dec|
000009d0  69 64 65 73 20 69 66 20  73 70 65 63 69 66 69 65  |ides if specifie|
000009e0  64 20 6d 6f 76 65 20 69  73 20 6c 65 67 61 6c 2c  |d move is legal,|
000009f0  20 61 6e 64 20 69 66 20  73 6f 20 74 68 65 6e 20  | and if so then |
00000a00  74 68 65 20 6d 6f 76 65  20 69 73 20 6d 61 64 65  |the move is made|
00000a10  2e 20 7d 0d 0d 20 20 56  41 52 20 6d 6f 76 65 6d  |. }..  VAR movem|
00000a20  61 64 65 20 3a 20 42 4f  4f 4c 45 41 4e 3b 0d 0d  |ade : BOOLEAN;..|
00000a30  20 20 20 20 7b 20 2d 2d  2d 2d 2d 2d 2d 2d 2d 2d  |    { ----------|
00000a40  2d 2d 2d 2d 2d 2d 2d 2d  2d 2d 2d 2d 2d 20 6c 65  |------------- le|
00000a50  67 61 6c 70 6f 73 20 28  6c 6f 63 61 6c 20 74 6f  |galpos (local to|
00000a60  20 6d 61 6b 65 6d 6f 76  65 29 20 2d 2d 2d 2d 2d  | makemove) -----|
00000a70  2d 2d 2d 2d 2d 2d 2d 2d  2d 2d 2d 2d 20 7d 0d 20  |------------ }. |
00000a80  20 20 20 46 55 4e 43 54  49 4f 4e 20 6c 65 67 61  |   FUNCTION lega|
00000a90  6c 70 6f 73 28 78 2c 79  20 3a 20 49 4e 54 45 47  |lpos(x,y : INTEG|
00000aa0  45 52 29 20 3a 20 42 4f  4f 4c 45 41 4e 3b 0d 20  |ER) : BOOLEAN;. |
00000ab0  20 20 20 7b 20 64 65 63  69 64 65 73 20 69 66 20  |   { decides if |
00000ac0  78 2c 79 20 69 73 20 61  20 6c 65 67 61 6c 20 63  |x,y is a legal c|
00000ad0  6f 6f 72 64 69 6e 61 74  65 20 6f 6e 20 74 68 65  |oordinate on the|
00000ae0  20 62 6f 61 72 64 20 7d  0d 20 20 20 20 42 45 47  | board }.    BEG|
00000af0  49 4e 0d 20 20 20 20 20  20 6c 65 67 61 6c 70 6f  |IN.      legalpo|
00000b00  73 20 3a 3d 20 28 20 28  28 78 3e 32 29 20 41 4e  |s := ( ((x>2) AN|
00000b10  44 20 28 78 3c 36 29 20  41 4e 44 20 28 79 3c 33  |D (x<6) AND (y<3|
00000b20  29 20 41 4e 44 20 28 79  3e 30 29 29 20 4f 52 0d  |) AND (y>0)) OR.|
00000b30  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00000b40  20 20 20 20 28 28 78 3e  32 29 20 41 4e 44 20 28  |    ((x>2) AND (|
00000b50  78 3c 36 29 20 41 4e 44  20 28 79 3e 35 29 20 41  |x<6) AND (y>5) A|
00000b60  4e 44 20 28 79 3c 38 29  29 20 4f 52 0d 20 20 20  |ND (y<8)) OR.   |
00000b70  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00000b80  20 28 28 78 3e 30 29 20  41 4e 44 20 28 58 3c 38  | ((x>0) AND (X<8|
00000b90  29 20 41 4e 44 20 28 79  3e 32 29 20 41 4e 44 20  |) AND (y>2) AND |
00000ba0  28 79 3c 36 29 29 0d 20  20 20 20 20 20 20 20 20  |(y<6)).         |
00000bb0  20 20 20 20 20 20 20 20  20 29 0d 20 20 20 20 45  |         ).    E|
00000bc0  4e 44 3b 20 7b 20 6c 65  67 61 6c 70 6f 73 20 7d  |ND; { legalpos }|
00000bd0  0d 0d 20 20 42 45 47 49  4e 0d 20 20 20 20 6d 6f  |..  BEGIN.    mo|
00000be0  76 65 6d 61 64 65 20 3a  3d 20 46 41 4c 53 45 3b  |vemade := FALSE;|
00000bf0  0d 20 20 20 20 49 46 20  6c 65 67 61 6c 70 6f 73  |.    IF legalpos|
00000c00  28 78 73 6f 72 63 2c 79  73 6f 72 63 29 20 41 4e  |(xsorc,ysorc) AN|
00000c10  44 20 6c 65 67 61 6c 70  6f 73 28 78 64 65 73 74  |D legalpos(xdest|
00000c20  2c 20 79 64 65 73 74 29  0d 20 20 20 20 54 48 45  |, ydest).    THE|
00000c30  4e 0d 20 20 20 20 20 20  49 46 20 4e 4f 54 28 62  |N.      IF NOT(b|
00000c40  6f 61 72 64 5b 78 73 6f  72 63 2c 79 73 6f 72 63  |oard[xsorc,ysorc|
00000c50  5d 29 20 41 4e 44 0d 20  20 20 20 20 20 20 20 20  |]) AND.         |
00000c60  4e 4f 54 28 62 6f 61 72  64 5b 78 6d 69 64 2c 79  |NOT(board[xmid,y|
00000c70  6d 69 64 5d 29 20 41 4e  44 0d 20 20 20 20 20 20  |mid]) AND.      |
00000c80  20 20 20 62 6f 61 72 64  5b 78 64 65 73 74 2c 20  |   board[xdest, |
00000c90  79 64 65 73 74 5d 0d 20  20 20 20 20 20 54 48 45  |ydest].      THE|
00000ca0  4e 0d 20 20 20 20 20 20  42 45 47 49 4e 0d 20 20  |N.      BEGIN.  |
00000cb0  20 20 20 20 20 20 7b 20  6c 65 67 61 6c 20 6d 6f  |      { legal mo|
00000cc0  76 65 2c 20 73 6f 20 6d  61 6b 65 20 69 74 20 7d  |ve, so make it }|
00000cd0  0d 20 20 20 20 20 20 20  20 62 6f 61 72 64 5b 78  |.        board[x|
00000ce0  73 6f 72 63 2c 79 73 6f  72 63 5d 20 3a 3d 20 54  |sorc,ysorc] := T|
00000cf0  52 55 45 3b 0d 20 20 20  20 20 20 20 20 62 6f 61  |RUE;.        boa|
00000d00  72 64 5b 78 6d 69 64 2c  79 6d 69 64 5d 20 3a 3d  |rd[xmid,ymid] :=|
00000d10  20 54 52 55 45 3b 0d 20  20 20 20 20 20 20 20 62  | TRUE;.        b|
00000d20  6f 61 72 64 5b 78 64 65  73 74 2c 79 64 65 73 74  |oard[xdest,ydest|
00000d30  5d 20 3a 3d 20 46 41 4c  53 45 3b 0d 20 20 20 20  |] := FALSE;.    |
00000d40  20 20 20 20 70 65 67 73  20 3a 3d 20 70 65 67 73  |    pegs := pegs|
00000d50  20 2d 20 31 3b 0d 20 20  20 20 20 20 20 20 6d 6f  | - 1;.        mo|
00000d60  76 65 6d 61 64 65 20 3a  3d 20 54 52 55 45 3b 0d  |vemade := TRUE;.|
00000d70  0d 20 20 20 20 20 20 20  20 7b 20 6e 6f 77 20 72  |.        { now r|
00000d80  65 63 6f 72 64 20 74 68  65 20 6d 6f 76 65 20 7d  |ecord the move }|
00000d90  0d 20 20 20 20 20 20 20  20 57 49 54 48 20 61 6e  |.        WITH an|
00000da0  73 77 65 72 5b 6d 6f 76  65 6e 75 6d 5d 20 44 4f  |swer[movenum] DO|
00000db0  0d 20 20 20 20 20 20 20  20 42 45 47 49 4e 0d 20  |.        BEGIN. |
00000dc0  20 20 20 20 20 20 20 20  20 73 78 20 3a 3d 20 78  |         sx := x|
00000dd0  73 6f 72 63 3b 0d 20 20  20 20 20 20 20 20 20 20  |sorc;.          |
00000de0  73 79 20 3a 3d 20 79 73  6f 72 63 3b 0d 20 20 20  |sy := ysorc;.   |
00000df0  20 20 20 20 20 20 20 6a  78 20 3a 3d 20 78 6d 69  |       jx := xmi|
00000e00  64 3b 0d 20 20 20 20 20  20 20 20 20 20 6a 79 20  |d;.          jy |
00000e10  3a 3d 20 79 6d 69 64 3b  0d 20 20 20 20 20 20 20  |:= ymid;.       |
00000e20  20 45 4e 44 3b 0d 20 20  20 20 20 20 20 20 6d 6f  | END;.        mo|
00000e30  76 65 6e 75 6d 20 3a 3d  20 53 55 43 43 28 6d 6f  |venum := SUCC(mo|
00000e40  76 65 6e 75 6d 29 3b 0d  0d 20 20 20 20 20 20 45  |venum);..      E|
00000e50  4e 44 3b 20 7b 20 74 68  65 6e 20 7d 0d 20 20 6d  |ND; { then }.  m|
00000e60  61 6b 65 6d 6f 76 65 20  3a 3d 20 6d 6f 76 65 6d  |akemove := movem|
00000e70  61 64 65 3b 0d 20 20 45  4e 44 3b 20 7b 20 6d 61  |ade;.  END; { ma|
00000e80  6b 65 6d 6f 76 65 20 7d  0d 0d 20 20 7b 20 2d 2d  |kemove }..  { --|
00000e90  2d 2d 2d 2d 2d 2d 2d 2d  2d 2d 2d 2d 2d 2d 2d 2d  |----------------|
00000ea0  2d 2d 2d 2d 2d 2d 2d 20  75 6e 64 6f 6d 6f 76 65  |------- undomove|
00000eb0  20 28 6c 6f 63 61 6c 20  74 6f 20 74 72 79 6d 6f  | (local to trymo|
00000ec0  76 65 29 20 2d 2d 2d 2d  2d 2d 2d 2d 2d 2d 2d 2d  |ve) ------------|
00000ed0  2d 2d 2d 2d 2d 2d 20 7d  0d 20 20 50 52 4f 43 45  |------ }.  PROCE|
00000ee0  44 55 52 45 20 75 6e 64  6f 6d 6f 76 65 28 78 73  |DURE undomove(xs|
00000ef0  6f 72 63 2c 20 79 73 6f  72 63 2c 20 78 6d 69 64  |orc, ysorc, xmid|
00000f00  2c 0d 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |,.              |
00000f10  20 20 20 20 20 20 79 6d  69 64 2c 20 78 64 65 73  |      ymid, xdes|
00000f20  74 2c 20 79 64 65 73 74  20 3a 20 49 4e 54 45 47  |t, ydest : INTEG|
00000f30  45 52 29 3b 0d 20 20 7b  20 75 6e 64 6f 20 61 20  |ER);.  { undo a |
00000f40  6d 6f 76 65 20 66 72 6f  6d 20 77 68 69 63 68 20  |move from which |
00000f50  61 20 73 6f 6c 75 74 69  6f 6e 20 63 6f 75 6c 64  |a solution could|
00000f60  20 6e 6f 74 20 62 65 20  66 6f 75 6e 64 2e 20 69  | not be found. i|
00000f70  65 20 62 61 63 6b 74 72  61 63 6b 2e 20 7d 0d 0d  |e backtrack. }..|
00000f80  20 20 42 45 47 49 4e 0d  20 20 20 20 62 6f 61 72  |  BEGIN.    boar|
00000f90  64 5b 78 73 6f 72 63 2c  79 73 6f 72 63 5d 20 3a  |d[xsorc,ysorc] :|
00000fa0  3d 20 46 41 4c 53 45 3b  0d 20 20 20 20 62 6f 61  |= FALSE;.    boa|
00000fb0  72 64 5b 78 6d 69 64 2c  79 6d 69 64 5d 20 3a 3d  |rd[xmid,ymid] :=|
00000fc0  20 46 41 4c 53 45 3b 0d  20 20 20 20 62 6f 61 72  | FALSE;.    boar|
00000fd0  64 5b 78 64 65 73 74 2c  79 64 65 73 74 5d 20 3a  |d[xdest,ydest] :|
00000fe0  3d 20 54 52 55 45 3b 0d  20 20 20 20 70 65 67 73  |= TRUE;.    pegs|
00000ff0  20 3a 3d 20 70 65 67 73  20 2b 20 31 3b 0d 20 20  | := pegs + 1;.  |
00001000  20 20 6d 6f 76 65 6e 75  6d 20 3a 3d 20 50 52 45  |  movenum := PRE|
00001010  44 28 6d 6f 76 65 6e 75  6d 29 3b 0d 20 20 45 4e  |D(movenum);.  EN|
00001020  44 3b 20 7b 20 75 6e 64  6f 6d 6f 76 65 20 7d 0d  |D; { undomove }.|
00001030  0d 0d 42 45 47 49 4e 0d  0d 20 20 7b 20 6f 75 74  |..BEGIN..  { out|
00001040  70 75 74 20 73 6f 6d 65  20 69 6e 66 6f 20 74 6f  |put some info to|
00001050  20 73 68 6f 77 20 70 72  6f 67 72 61 6d 20 69 73  | show program is|
00001060  20 73 74 69 6c 6c 20 72  75 6e 6e 69 6e 67 21 20  | still running! |
00001070  7d 0d 20 20 49 46 20 70  65 67 73 20 3c 20 6c 6f  |}.  IF pegs < lo|
00001080  77 0d 20 20 54 48 45 4e  0d 20 20 42 45 47 49 4e  |w.  THEN.  BEGIN|
00001090  0d 20 20 20 20 57 52 49  54 45 4c 4e 28 27 41 20  |.    WRITELN('A |
000010a0  6e 65 77 20 6c 6f 77 20  68 61 73 20 62 65 65 6e  |new low has been|
000010b0  20 66 6f 75 6e 64 3b 27  29 3b 0d 20 20 20 20 70  | found;');.    p|
000010c0  72 69 6e 74 62 6f 61 72  64 3b 0d 20 20 20 20 6c  |rintboard;.    l|
000010d0  6f 77 20 3a 3d 20 70 65  67 73 3b 0d 20 20 45 4e  |ow := pegs;.  EN|
000010e0  44 3b 20 7b 20 69 66 20  7d 0d 0d 20 20 67 6f 6f  |D; { if }..  goo|
000010f0  64 6d 6f 76 65 20 3a 3d  20 46 41 4c 53 45 3b 0d  |dmove := FALSE;.|
00001100  0d 20 20 49 46 20 28 70  65 67 73 20 3d 20 31 29  |.  IF (pegs = 1)|
00001110  20 41 4e 44 20 4e 4f 54  28 62 6f 61 72 64 5b 34  | AND NOT(board[4|
00001120  2c 34 5d 29 20 54 48 45  4e 20 67 6f 6f 64 6d 6f  |,4]) THEN goodmo|
00001130  76 65 20 3a 3d 20 54 52  55 45 3b 0d 0d 20 20 7b  |ve := TRUE;..  {|
00001140  20 74 72 79 20 74 6f 20  6d 61 6b 65 20 61 20 6e  | try to make a n|
00001150  65 77 20 6d 6f 76 65 20  7d 0d 20 20 46 4f 52 20  |ew move }.  FOR |
00001160  78 70 6f 73 20 3a 3d 20  31 20 54 4f 20 37 20 44  |xpos := 1 TO 7 D|
00001170  4f 0d 20 20 42 45 47 49  4e 0d 20 20 20 20 46 4f  |O.  BEGIN.    FO|
00001180  52 20 79 70 6f 73 20 3a  3d 20 31 20 54 4f 20 37  |R ypos := 1 TO 7|
00001190  20 44 4f 0d 20 20 20 20  42 45 47 49 4e 0d 0d 20  | DO.    BEGIN.. |
000011a0  20 20 20 20 20 7b 20 6d  6f 76 65 20 72 69 67 68  |     { move righ|
000011b0  74 20 3f 20 7d 0d 20 20  20 20 20 20 49 46 20 4e  |t ? }.      IF N|
000011c0  4f 54 28 67 6f 6f 64 6d  6f 76 65 29 0d 20 20 20  |OT(goodmove).   |
000011d0  20 20 20 54 48 45 4e 0d  20 20 20 20 20 20 20 20  |   THEN.        |
000011e0  49 46 20 6d 61 6b 65 6d  6f 76 65 28 78 70 6f 73  |IF makemove(xpos|
000011f0  2c 79 70 6f 73 2c 78 70  6f 73 2b 31 2c 79 70 6f  |,ypos,xpos+1,ypo|
00001200  73 2c 78 70 6f 73 2b 32  2c 79 70 6f 73 29 0d 20  |s,xpos+2,ypos). |
00001210  20 20 20 20 20 20 20 54  48 45 4e 0d 20 20 20 20  |       THEN.    |
00001220  20 20 20 20 42 45 47 49  4e 0d 20 20 20 20 20 20  |    BEGIN.      |
00001230  20 20 20 20 67 6f 6f 64  6d 6f 76 65 20 3a 3d 20  |    goodmove := |
00001240  74 72 79 6d 6f 76 65 3b  0d 20 20 20 20 20 20 20  |trymove;.       |
00001250  20 20 20 49 46 20 4e 4f  54 28 67 6f 6f 64 6d 6f  |   IF NOT(goodmo|
00001260  76 65 29 0d 20 20 20 20  20 20 20 20 20 20 54 48  |ve).          TH|
00001270  45 4e 20 75 6e 64 6f 6d  6f 76 65 28 78 70 6f 73  |EN undomove(xpos|
00001280  2c 79 70 6f 73 2c 78 70  6f 73 2b 31 2c 79 70 6f  |,ypos,xpos+1,ypo|
00001290  73 2c 78 70 6f 73 2b 32  2c 79 70 6f 73 29 3b 0d  |s,xpos+2,ypos);.|
000012a0  20 20 20 20 20 20 20 20  45 4e 44 3b 20 7b 20 69  |        END; { i|
000012b0  66 20 7d 0d 0d 20 20 20  20 20 20 7b 20 6d 6f 76  |f }..      { mov|
000012c0  65 20 6c 65 66 74 20 3f  20 7d 0d 20 20 20 20 20  |e left ? }.     |
000012d0  20 49 46 20 4e 4f 54 28  67 6f 6f 64 6d 6f 76 65  | IF NOT(goodmove|
000012e0  29 0d 20 20 20 20 20 20  54 48 45 4e 0d 20 20 20  |).      THEN.   |
000012f0  20 20 20 20 20 49 46 20  6d 61 6b 65 6d 6f 76 65  |     IF makemove|
00001300  28 78 70 6f 73 2c 79 70  6f 73 2c 78 70 6f 73 2d  |(xpos,ypos,xpos-|
00001310  31 2c 79 70 6f 73 2c 78  70 6f 73 2d 32 2c 79 70  |1,ypos,xpos-2,yp|
00001320  6f 73 29 0d 20 20 20 20  20 20 20 20 54 48 45 4e  |os).        THEN|
00001330  0d 20 20 20 20 20 20 20  20 42 45 47 49 4e 0d 20  |.        BEGIN. |
00001340  20 20 20 20 20 20 20 20  20 67 6f 6f 64 6d 6f 76  |         goodmov|
00001350  65 20 3a 3d 20 74 72 79  6d 6f 76 65 3b 0d 20 20  |e := trymove;.  |
00001360  20 20 20 20 20 20 20 20  49 46 20 4e 4f 54 28 67  |        IF NOT(g|
00001370  6f 6f 64 6d 6f 76 65 29  0d 20 20 20 20 20 20 20  |oodmove).       |
00001380  20 20 20 54 48 45 4e 20  75 6e 64 6f 6d 6f 76 65  |   THEN undomove|
00001390  28 78 70 6f 73 2c 79 70  6f 73 2c 78 70 6f 73 2d  |(xpos,ypos,xpos-|
000013a0  31 2c 79 70 6f 73 2c 78  70 6f 73 2d 32 2c 79 70  |1,ypos,xpos-2,yp|
000013b0  6f 73 29 3b 0d 20 20 20  20 20 20 20 20 45 4e 44  |os);.        END|
000013c0  3b 20 7b 20 69 66 20 7d  0d 0d 20 20 20 20 20 20  |; { if }..      |
000013d0  7b 20 6d 6f 76 65 20 75  70 20 3f 20 7d 0d 20 20  |{ move up ? }.  |
000013e0  20 20 20 20 49 46 20 4e  4f 54 28 67 6f 6f 64 6d  |    IF NOT(goodm|
000013f0  6f 76 65 29 0d 20 20 20  20 20 20 54 48 45 4e 0d  |ove).      THEN.|
00001400  20 20 20 20 20 20 20 20  49 46 20 6d 61 6b 65 6d  |        IF makem|
00001410  6f 76 65 28 78 70 6f 73  2c 79 70 6f 73 2c 78 70  |ove(xpos,ypos,xp|
00001420  6f 73 2c 79 70 6f 73 2d  31 2c 78 70 6f 73 2c 79  |os,ypos-1,xpos,y|
00001430  70 6f 73 2d 32 29 0d 20  20 20 20 20 20 20 20 54  |pos-2).        T|
00001440  48 45 4e 0d 20 20 20 20  20 20 20 20 42 45 47 49  |HEN.        BEGI|
00001450  4e 0d 20 20 20 20 20 20  20 20 20 20 67 6f 6f 64  |N.          good|
00001460  6d 6f 76 65 20 3a 3d 20  74 72 79 6d 6f 76 65 3b  |move := trymove;|
00001470  0d 20 20 20 20 20 20 20  20 20 20 49 46 20 4e 4f  |.          IF NO|
00001480  54 28 67 6f 6f 64 6d 6f  76 65 29 0d 20 20 20 20  |T(goodmove).    |
00001490  20 20 20 20 20 20 54 48  45 4e 20 75 6e 64 6f 6d  |      THEN undom|
000014a0  6f 76 65 28 78 70 6f 73  2c 79 70 6f 73 2c 78 70  |ove(xpos,ypos,xp|
000014b0  6f 73 2c 79 70 6f 73 2d  31 2c 78 70 6f 73 2c 79  |os,ypos-1,xpos,y|
000014c0  70 6f 73 2d 32 29 3b 0d  20 20 20 20 20 20 20 20  |pos-2);.        |
000014d0  45 4e 44 3b 20 7b 20 69  66 20 7d 0d 0d 20 20 20  |END; { if }..   |
000014e0  20 20 20 7b 20 6d 6f 76  65 20 64 6f 77 6e 20 3f  |   { move down ?|
000014f0  20 7d 0d 20 20 20 20 20  20 49 46 20 4e 4f 54 28  | }.      IF NOT(|
00001500  67 6f 6f 64 6d 6f 76 65  29 0d 20 20 20 20 20 20  |goodmove).      |
00001510  54 48 45 4e 0d 20 20 20  20 20 20 20 20 49 46 20  |THEN.        IF |
00001520  6d 61 6b 65 6d 6f 76 65  28 78 70 6f 73 2c 79 70  |makemove(xpos,yp|
00001530  6f 73 2c 78 70 6f 73 2c  79 70 6f 73 2b 31 2c 78  |os,xpos,ypos+1,x|
00001540  70 6f 73 2c 79 70 6f 73  2b 32 29 0d 20 20 20 20  |pos,ypos+2).    |
00001550  20 20 20 20 54 48 45 4e  0d 20 20 20 20 20 20 20  |    THEN.       |
00001560  20 42 45 47 49 4e 0d 20  20 20 20 20 20 20 20 20  | BEGIN.         |
00001570  20 67 6f 6f 64 6d 6f 76  65 20 3a 3d 20 74 72 79  | goodmove := try|
00001580  6d 6f 76 65 3b 0d 20 20  20 20 20 20 20 20 20 20  |move;.          |
00001590  49 46 20 4e 4f 54 28 67  6f 6f 64 6d 6f 76 65 29  |IF NOT(goodmove)|
000015a0  0d 20 20 20 20 20 20 20  20 20 20 54 48 45 4e 20  |.          THEN |
000015b0  75 6e 64 6f 6d 6f 76 65  28 78 70 6f 73 2c 79 70  |undomove(xpos,yp|
000015c0  6f 73 2c 78 70 6f 73 2c  79 70 6f 73 2b 31 2c 78  |os,xpos,ypos+1,x|
000015d0  70 6f 73 2c 79 70 6f 73  2b 32 29 3b 0d 20 20 20  |pos,ypos+2);.   |
000015e0  20 20 20 20 20 45 4e 44  3b 20 7b 20 69 66 20 7d  |     END; { if }|
000015f0  0d 0d 20 20 20 20 45 4e  44 3b 20 7b 20 66 6f 72  |..    END; { for|
00001600  20 79 70 6f 73 20 7d 0d  20 20 45 4e 44 3b 20 7b  | ypos }.  END; {|
00001610  20 66 6f 72 20 78 70 6f  73 20 7d 0d 0d 74 72 79  | for xpos }..try|
00001620  6d 6f 76 65 20 3a 3d 20  67 6f 6f 64 6d 6f 76 65  |move := goodmove|
00001630  3b 0d 0d 45 4e 44 3b 20  7b 20 74 72 79 6d 6f 76  |;..END; { trymov|
00001640  65 20 7d 0d 0d 0d 0d 7b  20 2d 2d 2d 2d 2d 2d 2d  |e }....{ -------|
00001650  2d 2d 2d 2d 2d 2d 2d 2d  2d 2d 2d 2d 2d 2d 2d 2d  |----------------|
00001660  2d 2d 2d 2d 2d 20 6d 61  69 6e 20 70 72 6f 67 72  |----- main progr|
00001670  61 6d 20 2d 2d 2d 2d 2d  2d 2d 2d 2d 2d 2d 2d 2d  |am -------------|
00001680  2d 2d 2d 2d 2d 2d 2d 2d  2d 2d 2d 2d 2d 2d 2d 2d  |----------------|
00001690  2d 2d 2d 2d 20 7d 0d 0d  42 45 47 49 4e 0d 0d 20  |---- }..BEGIN.. |
000016a0  20 69 6e 69 74 69 61 6c  69 73 65 3b 0d 20 20 49  | initialise;.  I|
000016b0  46 20 74 72 79 6d 6f 76  65 0d 20 20 54 48 45 4e  |F trymove.  THEN|
000016c0  0d 20 20 42 45 47 49 4e  0d 20 20 20 20 57 52 49  |.  BEGIN.    WRI|
000016d0  54 45 4c 4e 28 27 41 20  73 6f 6c 75 74 69 6f 6e  |TELN('A solution|
000016e0  20 68 61 73 20 62 65 65  6e 20 66 6f 75 6e 64 3b  | has been found;|
000016f0  20 27 29 3b 0d 20 20 20  20 70 72 69 6e 74 62 6f  | ');.    printbo|
00001700  61 72 64 3b 0d 20 20 20  20 46 4f 52 20 6c 6f 6f  |ard;.    FOR loo|
00001710  70 20 3a 3d 20 31 20 54  4f 20 33 31 20 44 4f 0d  |p := 1 TO 31 DO.|
00001720  20 20 20 20 57 49 54 48  20 61 6e 73 77 65 72 5b  |    WITH answer[|
00001730  6c 6f 6f 70 5d 20 44 4f  0d 20 20 20 20 20 20 57  |loop] DO.      W|
00001740  52 49 54 45 28 27 4a 75  6d 70 20 27 2c 73 78 3a  |RITE('Jump ',sx:|
00001750  31 2c 27 2c 27 2c 73 79  3a 31 2c 27 20 6f 76 65  |1,',',sy:1,' ove|
00001760  72 20 27 2c 6a 78 3a 31  2c 27 2c 27 2c 6a 79 3a  |r ',jx:1,',',jy:|
00001770  31 2c 27 2e 20 27 29 3b  0d 0d 20 20 45 4e 44 20  |1,'. ');..  END |
00001780  7b 20 74 68 65 6e 20 7d  0d 20 20 45 4c 53 45 20  |{ then }.  ELSE |
00001790  57 52 49 54 45 4c 4e 28  27 4e 6f 20 73 6f 6c 75  |WRITELN('No solu|
000017a0  74 69 6f 6e 3f 3f 3f 3f  3f 27 29 3b 0d 0d 20 20  |tion?????');..  |
000017b0  57 52 49 54 45 4c 4e 3b  0d 0d 45 4e 44 2e 0d     |WRITELN;..END..|
000017bf
14-07-89/P\Sol.m0
14-07-89/P\Sol.m1
14-07-89/P\Sol.m2
14-07-89/P\Sol.m4
14-07-89/P\Sol.m5