home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / simtel / sigm / vols000 / vol024 / othello.pas < prev    next >
Pascal/Delphi Source File  |  1984-04-29  |  6KB  |  126 lines

  1.  (**************************************************************
  2.   *    It was about time I included something for the game freaks
  3.   * so I looked around for something good. The best I could come
  4.   * up with was Othello. Unfortunately it is in UCSD but then I
  5.   * realized that it did not make any difference. It is about time
  6.   * we devoted some time to learning how to convert from UCSD to
  7.   * Z. So that is why I included this program. I want someone to
  8.   * convert it. It also is a good guide to some advanced Pascal 
  9.   * programing.
  10.   *    Othello units:
  11.   *            Othello.pas
  12.   *            Othell1.pas
  13.   *            Othell2.pas
  14.   *            Othellin.pas
  15.   *
  16.   *     Donated by the now defunct UCSD PASCAL USERS GROUP
  17.   * (To the best of my knowledge this software is to be used only)
  18.   * (for us non-commercials. It was originally donated by a )
  19.   * (Company who thought kindly of us.)      
  20.   ***************************************************************)
  21.  
  22.  (*$S+*)
  23.  (* UCSD Pascal *) PROGRAM OTHELLO; (* Steve Brecher 16-Jun-79 *)
  24.  
  25.  (* The position evaluation weights were derived from a FORTRAN program   *)
  26.  (* headed "from Creative Computing/Klaus E Liebold/4-26-78".             *)
  27.  
  28.  (* This program provides playing instructions to the user on request.    *)
  29.   
  30.  CONST
  31.  (* The game pieces are shown on the screen as 2 rows of 3 characters, e.g. *)
  32.  (*                          OOO                                            *)
  33.  (*                          OOO                                            *)
  34.  (* If your crt has a "block" character (like the cursor on some crts), that*)
  35.  (* is good for the white piece, and capital letter O is good for black,    *)
  36.  (* especially if it has a rectangular shape.  Otherwise, choose characters *)
  37.  (* that are centered within the character dot matrix; try to maximize the  *)
  38.                                                                        (* difference in intensity between the black and white pieces while maxi-  *)
  39.  (* mizing the absolute intensity of the black piece.  Avoid characters with*)
  40.  (* semantic content, e.g. "W" and "B" are not so good.                     *)
  41.  whiteascii = 96;     (*ascii value of char making up piece of first mover*)
  42.  blackascii = 79;     (*  "     "   "   "     "     "    "   " 2nd    "   *)
  43.  minticks   = 22.0;   (*min # clock ticks between crt square updates      *)
  44.                       (*--should be long enough for a distinct, separate  *)
  45.  (*terminal bell sound on each square updated        *)
  46.  spaces     = '                             ';
  47.  
  48. TYPE
  49.  coordinate   = 1..8;
  50.  color        = (white,black);
  51.  squareloc    = RECORD
  52.  CASE onboard: BOOLEAN OF
  53.  TRUE:            (row,col:        coordinate);
  54.  END;
  55.  direction    = (north,south,east,west,sw,ne,se,nw); (*pairs of opposites*)
  56.     squarestatus = RECORD
  57.  CASE occupied: BOOLEAN OF
  58.  TRUE:  (occupier:       color                           );
  59.      FALSE: (adjacentpieces: ARRAY[color] OF SET of direction);
  60.  END;
  61.  gamestatus   = RECORD
  62.  boardstatus:  ARRAY[coordinate,coordinate] OF squarestatus;
  63.  nextmover:    color;
  64.  lastmoveloc:  squareloc;
  65.  score:        ARRAY[color] OF INTEGER;
  66.  END;
  67.     movedesc     = RECORD
  68.  moveloc:            squareloc;
  69.  points:             INTEGER;
  70.  dirsflipped:        SET OF direction;
  71.  4bordrsqsflipped:    INTEGER;
  72.  bordnoncorn:        BOOLEAN;
  73.  END;
  74.  movelist     = RECORD
  75.  movecount:          INTEGER;
  76.  okmove:             ARRAY[1..30] OF movedesc;
  77.  END;
  78.     position     = RECORD
  79.  border:             BOOLEAN;
  80.  corner:             BOOLEAN;
  81.  diagnexttocorner:   BOOLEAN;
  82.  incenter4by4:       BOOLEAN;
  83.  adjacentsq:         ARRAY[direction] OF squareloc;
  84.  (* "special" border squares are those border squares        *)
  85.  (* adjacent to a corner or adjacent to board midline; there *)
  86.  (* are 2 pairs of such squares on each border. Sample pair: *)
  87.                                                                 (* (1,2) and (1,4); for each we want a pointer to the other *)
  88.  (* and to the border square between them (1,3).             *)
  89.  CASE specialbordersq: BOOLEAN OF
  90.  TRUE:             (otherofpair,between:  squareloc);
  91.  END;
  92.  
  93.  
  94.  VAR
  95.  board:                       ARRAY[coordinate,coordinate] OF position;
  96.  status,crtstatus:            gamestatus;
  97.  square:                      squareloc;
  98.  legallist:                   movelist;
  99.  move:                        movedesc;
  100.  opposdir:                    ARRAY[direction] OF direction;
  101.  legalmoves:                  ARRAY[color] OF INTEGER;
  102.  colorword:                   ARRAY[color] OF STRING[5];
  103.  usercolor:                   color;
  104.  lastchange:                  REAL; (*time of last square change on crt*)
  105.  
  106.  (*$I OTHELLINIT*)
  107.  (*$I OTHELL1*)
  108.  (*$I OTHELL2*)
  109.  
  110.  BEGIN (*PROGRAM OTHELLO*)
  111.  REPEAT
  112.  initgame;
  113.  findlegalmoves(status,legallist);
  114.  legalmoves[white] := legallist.movecount;
  115.  REPEAT
  116.  play(white);
  117.  findlegalmoves(status,legallist);
  118.             legalmoves[black] := legallist.movecount;
  119.  play(black);
  120.  findlegalmoves(status,legallist);
  121.  legalmoves[white] := legallist.movecount;
  122.  UNTIL (legalmoves[white]=0) and (legalmoves[black]=0);
  123.     UNTIL userquits;
  124.  END.
  125.  
  126.