Microsoft QuickPascal

This commit is contained in:
davidly 2024-07-02 06:52:31 -07:00
parent cef8f335d0
commit e476d8fafc
52 changed files with 1015 additions and 0 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,27 @@
type
regpack = record
ax,bx,cx,dx,bp,si,di,ds,es,flags: integer;
end;
procedure get_time( var tt : timetype );
var
recpack: registers;
ahigh: byte;
begin
ahigh := $2c;
with recpack do
begin
ax := ahigh shl 8;
end;
intr( $21, recpack );
with recpack do
begin
tt.h := cx shr 8;
tt.m := cx mod 256;
tt.s := dx shr 8;
tt.l := dx mod 256;
end;
end;

View File

@ -0,0 +1,42 @@
program e;
const
DIGITS = 200;
type
arrayType = array[ 0..DIGITS ] of integer;
var
high, n, x : integer;
a : arrayType;
begin
high := DIGITS;
x := 0;
n := high - 1;
while n > 0 do begin
a[ n ] := 1;
n := n - 1;
end;
a[ 1 ] := 2;
a[ 0 ] := 0;
while high > 9 do begin
high := high - 1;
n := high;
while 0 <> n do begin
a[ n ] := x MOD n;
x := 10 * a[ n - 1 ] + x DIV n;
n := n - 1;
end;
Write( x );
end;
writeln;
writeln( 'done' );
end.


Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,142 @@
>>
>>contents
The NOTES.HLP file provides an easy way to add your own information
to the QP Advisor.
The NOTES.HLP file is a special ASCII help file that appears in the
help window whenever you press a <Notes> button. Press the ALT+F1 key
to return from the NOTES.HLP file to the QP Advisor.
Note: the chevrons (>>) are special characters to NOTES.HLP. They
are markers the QP Advisor seeks when it loads a specific section of
NOTES.HLP. The chevrons with the name of the section in NOTES.HLP
should not be edited, but you can change any other part of NOTES.HLP.
The NOTES.HLP file contains three parts:
Part Description
>>contents Appears when you select the <Notes> button on the
Contents screen. This is the part of the NOTES.HLP
file now being displayed.
>>edit Appears when you select the <Notes> button on the
QuickPascal Keys screen.
>>index Appears when you select the <Notes> button on the
Index screen.
To change the contents of the NOTES.HLP file, you must do the
following:
1. Close the NOTES.HLP file if it is currently displayed in the
help window.
2. Open the NOTES.HLP file with any editor (such as the QuickPascal
editor) to edit NOTES.HLP. Change anything in the file except
the file name NOTES.HLP and lines that begin with the >>
characters. These lines are links to the buttons in the QP
Advisor
3. Save your modified NOTES.HLP file as a normal ASCII file.
4. When you open NOTES.HLP with one of the <Notes> buttons in the
QP Advisor, you will see your additions and changes.
5. Press ALT+F1 to return to the QP Advisor.
>>edit
The NOTES.HLP file provides an easy way to add your own information
to the QP Advisor.
The NOTES.HLP file is a special ASCII help file that appears in the
help window whenever you press a <Notes> button. Press the ALT+F1 key
to return from the NOTES.HLP file to the QP Advisor.
Note: the chevrons (>>) are special characters to NOTES.HLP. They
are markers the QP Advisor seeks when it loads a specific section of
NOTES.HLP. The chevrons with the name of the section in NOTES.HLP
should not be edited, but you can change any other part of NOTES.HLP.
The NOTES.HLP file contains three parts:
Part Description
>>contents Appears when you select the <Notes> button on the
Contents screen.
>>edit Appears when you select the <Notes> button on the
QuickPascal Keys screen. This is the part of the
NOTES.HLP file now being displayed.
>>index Appears when you select the <Notes> button on the
Index screen.
To change the contents of the NOTES.HLP file you must do the
following:
1. Close the NOTES.HLP file if it is currently displayed in the
help window.
2. Open the NOTES.HLP file with any editor (such as the QuickPascal
editor) to edit NOTES.HLP. Change anything in the file except
the file name NOTES.HLP and lines that begin with the >>
characters. These lines are links to the buttons in the QP
Advisor
3. Save your modified NOTES.HLP file as a normal ASCII file.
4. When you open NOTES.HLP with one of the <Notes> buttons in the
QP Advisor, you will see your additions and changes.
5. Press ALT+F1 to return to the QP Advisor.
>>index
The NOTES.HLP file provides an easy way to add your own information
to the QP Advisor.
The NOTES.HLP file is a special ASCII help file that appears in the
help window whenever you press a <Notes> button. Press the ALT+F1 key
to return from the NOTES.HLP file to the QP Advisor.
Note: the chevrons (>>) are special characters to NOTES.HLP. They
are markers the QP Advisor seeks when it loads a specific section of
NOTES.HLP. The chevrons with the name of the section in NOTES.HLP
should not be edited, but you can change any other part of NOTES.HLP.
The NOTES.HLP file contains three parts:
Part Description
>>contents Appears when you select the <Notes> button on the
Contents screen.
>>edit Appears when you select the <Notes> button on the
QuickPascal Keys screen.
>>index Appears when you select the <Notes> button on the
Index screen. This is the part of the NOTES.HLP file
now being displayed.
To change the contents of the NOTES.HLP file you must do the
following:
1. Close the NOTES.HLP file if it is currently displayed in the
help window.
2. Open the NOTES.HLP file with any editor (such as the QuickPascal
editor) to edit NOTES.HLP. Change anything in the file except
the file name NOTES.HLP and lines that begin with the >>
characters. These lines are links to the buttons in the QP
Advisor
3. Save your modified NOTES.HLP file as a normal ASCII file.
4. When you open NOTES.HLP with one of the <Notes> buttons in the
QP Advisor, you will see your additions and changes.
5. Press ALT+F1 to return to the QP Advisor.

View File

@ -0,0 +1,88 @@
Packing List for Microsoft QuickPascal (R) Compiler, Version 1.0
5.25" Disk Set
Copyright (c) Microsoft Corporation, 1989
DISK 1: Setup/Utilities
Files Description
----- -----------
PACKING.LST Packing list (this file).
SETUP.EXE SETUP program -- installs QuickPascal.
README.DOC Directs you to README in Help.
FIXSHIFT.COM Fixes BIOS bug for certain Compaq (R) and other
keyboards.
MOUSE.COM Microsoft Mouse driver.
MSHERC.COM TSR -- supports Hercules (R) card graphics.
QPMKKEY.EXE Creates customized keyboard command files.
SAMPLES\BIGHEAP.PAS New versions of GetMem and FreeMem that can allocate
heap space in blocks larger than 65520 bytes.
SAMPLES\BIGMEM.PAS BIGMEM.PAS uses the sample BigHeap unit.
SAMPLES\MOUSE.PAS Real mode mouse control routines; derived from
Microsoft OS/2 Programmer's Reference, Chapter 3.
SAMPLES\SORTDEMO.PAS Graphically demonstrates six common sorting algorithms
SAMPLES\OBJECTS.PAS Object-oriented demo.
SAMPLES\CRLF.PAS Normalizes all line endings of a text file to CRLF.
SAMPLES\GRDMEO.PAS Demonstrates the QuickPascal graphics library. It
uses two additional units: menu and turtle.
SAMPLES\MENU.PAS Used by Grdemo.
SAMPLES\TURTLE Used by Grdemo (for Turtle graphics).
BRIEF.KEY Keyboard MAP files.
EMACS.KEY " "
EPSILON.KEY " "
QP.KEY " "
ME.KEY " "
DISK 2 : Program
Files Description
----- -----------
QP.EXE Microsoft QuickPascal program development environment.
QPL.COM QuickPascal command-line compiler.
QPL.ERR QuickPascal command-line compiler error messages.
DISK 3: Microsoft QuickPascal Advisor
Files Description
----- -----------
QP.HLP QuickPascal help files.
QPENV.HLP " "
DISK 4: Libraries
Files Description
----- -----------
SYSTEM.QPU System Unit.
CRT.QPU CRT Interface Unit.
DOS.QPU DOS Interface Unit.
MSGRAPH.QPU Graphics Interface Unit.
MSGRUTIL.QPU Graphics Support Unit.
GRAPH.QPU Graphics Support Unit.
PRINTER.QPU Printer Interface Unit.
COURB.FON Font files.
ROMAN.FON " "
SCRIPT.FON " "
TMSRB.FON " "
HELVB.FON " "
MODERN.FON " "
Disk 5: Microsoft QuickPascal Express
Files Description
----- -----------
LEARN.EXE Computer-Based Training file.
QPCBT.CTX " "
QPCBT.SCN " "
QPCBT.SOB " "
LEARN.PIF Computer-Based Training Windows PIF file.
ATT6300.VID Computer-Based Training additional display drivers.
CGASNOW.VID " "
ERICSSON.VID " "
HERC102.VID " "
HERC112.VID " "
QPERR.HLP QuickPascal additional help files
QPGRAPH.HLP " "
NOTES.HLP " "

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,163 @@
0001 Out of memory
0002 Cannot open file
0003 File too big
0004 Too many nested files
0005 Cannot read file
0006 Cannot close file
0007 Cannot seek file
0008 Invalid end of line
0009 Illegal character
0010 Line too long
0011 Error in integer constant
0012 Error in character constant
0013 String constant exceeds line
0014 Unexpected end of file
0015 Invalid directive
0016 End of file expected
0017 Identifier expected
0018 ";" expected
0019 ")" expected
0020 "." expected
0021 BEGIN expected
0022 END expected
0023 Label must be in the range 0..9999
0024 Label already defined
0025 Identifier or Label already defined
0026 Error in type definition
0027 This type not allowed here
0028 OF expected
0029 Implementation restriction
0030 "[" expected
0031 "]" expected
0032 Unknown identifier
0033 Error in simple type definition
0034 Type identifier expected
0035 "=" expected
0036 Constant expected
0037 Integer or real constant expected
0038 Range expected
0039 Subrange bounds must be scalar
0040 Incompatible subrange types
0041 Low bound exceeds high bound
0042 ":" expected
0043 Unsatisfied forward reference
0044 Integer constant expected
0045 Invalid string length
0046 Tag field type must be scalar or subrange
0047 "(" expected
0048 Too many literals
0049 Structure too big
0050 Error in expression
0051 Conflicting operands
0052 Right operand is not a set
0053 Invalid identifier
0054 Invalid type cast
0055 Cannot create file
0056 Cannot write file
0057 Variable type must be pointer
0058 Variable type must be record
0059 Variable type must be array or string
0060 No such field in this record or object
0061 Index type is not compatible with the declaration
0062 Routine too big
0063 UNTIL expected
0064 Boolean expression expected
0065 DO expected
0066 THEN expected
0067 Invalid label
0068 Unknown label
0069 Label not within current block
0070 Label already defined
0071 Label expected
0072 Undefined label in preceding statement part
0073 Error in statement
0074 ":=" expected
0075 Type mismatch
0076 Variable identifier expected
0077 Invalid FOR control variable
0078 Scalar type expected
0079 TO or DOWNTO expected
0080 Disk full
0081 Constant value out of range
0082 "," expected
0083 Division by zero
0084 Too many local routines
0085 Integer expression expected
0086 Pointer type cannot be referenced
0087 Typed pointer expected
0088 File type expected
0089 Cannot write expressions of this type
0090 Ordinal expression expected
0091 Invalid file type
0092 Variable parameter expected
0093 Cannot read expressions of this type
0094 Integer or real expression expected
0095 Integer or real variable expected
0096 Function not mounted
0097 Inline error
0098 Label definition not allowed in interface part
0099 INTERFACE expected
0100 IMPLEMENTATION expected
0101 Invalid unit file
0102 Field or method already defined
0103 Invalid QPU file
0104 Duplicate unit name
0105 Circular unit reference
0106 Error in real constant
0107 Coprocessor required
0108 Too many nested conditional directives
0109 Misplaced directive
0110 $ENDIF directive missing
0111 Too many conditional symbols
0112 Header does not match previous declaration
0113 Invalid qualification
0114 Too many parameters
0115 Class must be defined at global level
0116 Class must be defined in type definition
0117 Invalid procedure or function reference
0118 Procedure or function variable expected
0119 Object type expected
0120 Object must be defined at global level
0121 Object must be defined in type definition
0122 Invalid class type
0123 Class table overflow
0124 Syntax error
0125 This method has no parent
0126 Type of expression must be pointer
0127 Invalid variable reference
0128 Symbol table overflow
0129 Too many imported units
0130 Code cannot exceed 64k bytes
0131 Invalid real operation
0132 Real overflow
0133 Real underflow
0134 Undefined external
0135 Too many object file names
0136 Invalid object file
0137 Object file too large
0138 Invalid segment definition
0139 Invalid segment name
0140 Code segment too large
0141 Invalid PUBLIC definition
0142 Invalid EXTRN definition
0143 Too many EXTRNs
0144 Invalid fixup
0145 Too many opened files
0146 Too many variables
0147 Directive must be at top of program
0148 Invalid assigment
0149 Set type out of range
0150 Index out of range
0151 Object variable expected in MEMBER function
0152 Object type expected in MEMBER function
0153 Expression too complicated
0154 Invalid unit name
0155 Line information table overflow
0156 Fixup table overflow
0157 Source table overflow
0158 Unit expected
0159 Unsatisfied forward name reference
0160 Invalid fixupp in iterated data record
0161 Include files not allowed here
0162 Stack overflow


Binary file not shown.

View File

@ -0,0 +1,63 @@
README.DOC File
Release Notes for Microsoft(R) QuickPascal
(C) Copyright Microsoft Corporation, 1989
You can read the release notes directly from the ON-Line help.
The ON-line help file containing the release notes is titled:
QPENV.ENV. If you are running HELP from a floppy drive make sure
that QPENV.ENV is present on that drive.
Special Setup Notes
-------------------
For your convenience SETUP has been modified and the "path
setting screens" section in the "Installing QuickPascal"
chapter of "Up and Running" has changed. You will now only
set three "paths" instead of four. The DOC path has been
eliminated.
Documentation Note:
-------------------
Page 17 of "Up and Running" tells you that to run QuickPascal
you should put disk 1 in drive A. It should instead say
put "Program disk" in drive A. In addition "SYSTEM.QPU" is
now on the "Libraries" disk instead of on DISK 1.
Special Instructions for QP Express
-----------------------------------
You may have difficulty running the QP Express Computer-Based
Training (CBT) program due to your video driver/graphics card
combination. Try the following:
1. Make a backup copy of the QP Express or QP Express/QP Advisor
disk. Use the backup copy for the remainder of this procedure.
2. On the backup copy of the QP Express or QP Express/QP Advisor disk
you will find files with the extension .VID. Each of these files
is a driver for a specific type of graphics card. The following
drivers support the indicated graphics cards:
ATT6300.VID For Olivetti and ATT PCs.
CGASNO.VID For CGA cards that produce a snow effect.
ERICSSON.VID For Ericsson PCs
HERC102.VID For the Hercules 102 card
HERC112.VID For the Hercules 112 card
If you use one of these computers/displays, rename the appropriate
driver to SCREEN.VID. For example, if you run an AT&T computer,
type: RENAME ATT6300.VID SCREEN.VID
3. You can now resume SETUP or run the CBT directly by typing: LEARN.
Special Instructions for Windows 386 Users
------------------------------------------
If you want to use QP under Windows 386 please set the
following in your WIN.INI file under the header [win386]:
emmsize=0
This setting will prevent a a potential conflict in EMS
usage between QP and Windows 386.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,31 @@
program sieve;
const
size = 8190;
type
flagType = array[ 0..size ] of boolean;
var
i, k, prime, count, iter : integer;
flags : flagType;
begin
for iter := 1 to 10 do begin
count := 0;
for i := 0 to size do flags[ i ] := true;
for i := 0 to size do begin
if flags[ i ] then begin
prime := i + i + 3;
k := i + prime;
while k <= size do begin
flags[ k ] := false;
k := k + prime;
end;
count := count + 1;
end;
end;
end;
writeln( 'count of primes: ', count );
end.

Binary file not shown.

View File

@ -0,0 +1,66 @@
type
timetype = record h, m, s, l : integer; end;
procedure time_difference( var tStart, tEnd, tDiff : timetype );
var
startSecond, startMinute, startHour : integer;
begin { time_difference }
startSecond := tStart.s;
startMinute := tStart.m;
startHour := tStart.h;
tDiff.l := tEnd.l - tStart.l;
if ( tDiff.l < 0 ) then
begin
tDiff.l := tDiff.l + 100;
startSecond := startSecond + 1;
end;
tDiff.s := tEnd.s - startSecond;
if ( tDiff.s < 0 ) then
begin
tDiff.s := tDiff.s + 60;
startMinute := startMinute + 1;
end;
tDiff.m := tEnd.m - startMinute;
if ( tDiff.m < 0 ) then
begin
tDiff.m := tDiff.m + 60;
startHour := startHour + 1;
end;
tDiff.h := tEnd.h - startHour;
if ( tDiff.h < 0 ) then
tDiff.h := tDiff.h + 12;
end;
procedure print_time_part( num : integer );
begin
if ( num < 10 ) then write( '0' );
write( num );
end;
procedure print_time( var t: timetype );
begin
print_time_part( t.h );
write( ':' );
print_time_part( t.m );
write( ':' );
print_time_part( t.s );
write( '.' );
print_time_part( t.l );
end;
procedure print_elapsed_time( var timeStart, timeEnd: timetype );
var
timeDiff: timetype;
begin
time_difference( timeStart, timeEnd, timeDiff );
write( 'elapsed time: ' );
print_time( timeDiff );
writeln;
end;


Binary file not shown.

View File

@ -0,0 +1,389 @@
{ App to prove you can't win at Tic-Tac-Toe }
{ use of byte instead of integer should be faster, but it's not }
program ttt;
uses Dos;
{$I timeutil.pas}
{$I dos_gt.pas}
type TScoreFunc = function : integer;
const
scoreWin = 6;
scoreTie = 5;
scoreLose = 4;
scoreMax = 9;
scoreMin = 2;
scoreInvalid = 0;
pieceBlank = 0;
pieceX = 1;
pieceO = 2;
iterations = 1;
type
boardType = array[ 0..8 ] of integer;
funcArrayType = array[ 0..8 ] of pointer;
var
{ update evaluated after each run because longint operations are slow }
evaluated: longint;
moves: integer;
board: boardType;
timeStart, timeEnd: timetype;
scoreFuncs : funcArrayType;
procedure dumpBoard;
var
i : integer;
begin
Write( '{' );
for i := 0 to 8 do
Write( board[i] );
Write( '}' );
end;
function func0 : integer;
var x : integer;
begin
x := board[0];
if ( ( ( x = board[1] ) and ( x = board[2] ) ) or
( ( x = board[3] ) and ( x = board[6] ) ) or
( ( x = board[4] ) and ( x = board[8] ) ) ) then
func0 := x
else
func0 := pieceBlank;
end;
function func1 : integer;
var x : integer;
begin
x := board[1];
if ( ( ( x = board[0] ) and ( x = board[2] ) ) or
( ( x = board[4] ) and ( x = board[7] ) ) ) then
func1 := x
else
func1 := pieceBlank;
end;
function func2 : integer;
var x : integer;
begin
x := board[2];
if ( ( ( x = board[0] ) and ( x = board[1] ) ) or
( ( x = board[5] ) and ( x = board[8] ) ) or
( ( x = board[4] ) and ( x = board[6] ) ) ) then
func2 := x
else
func2 := pieceBlank;
end;
function func3 : integer;
var x : integer;
begin
x := board[3];
if ( ( ( x = board[4] ) and ( x = board[5] ) ) or
( ( x = board[0] ) and ( x = board[6] ) ) ) then
func3 := x
else
func3 := pieceBlank;
end;
function func4 : integer;
var x : integer;
begin
x := board[4];
if ( ( ( x = board[0] ) and ( x = board[8] ) ) or
( ( x = board[2] ) and ( x = board[6] ) ) or
( ( x = board[1] ) and ( x = board[7] ) ) or
( ( x = board[3] ) and ( x = board[5] ) ) ) then
func4 := x
else
func4 := pieceBlank;
end;
function func5 : integer;
var x : integer;
begin
x := board[5];
if ( ( ( x = board[3] ) and ( x = board[4] ) ) or
( ( x = board[2] ) and ( x = board[8] ) ) ) then
func5 := x
else
func5 := pieceBlank;
end;
function func6 : integer;
var x : integer;
begin
x := board[6];
if ( ( ( x = board[7] ) and ( x = board[8] ) ) or
( ( x = board[0] ) and ( x = board[3] ) ) or
( ( x = board[4] ) and ( x = board[2] ) ) ) then
func6 := x
else
func6 := pieceBlank;
end;
function func7 : integer;
var x : integer;
begin
x := board[7];
if ( ( ( x = board[6] ) and ( x = board[8] ) ) or
( ( x = board[1] ) and ( x = board[4] ) ) ) then
func7 := x
else
func7 := pieceBlank;
end;
function func8 : integer;
var x : integer;
begin
x := board[8];
if ( ( ( x = board[6] ) and ( x = board[7] ) ) or
( ( x = board[2] ) and ( x = board[5] ) ) or
( ( x = board[0] ) and ( x = board[4] ) ) ) then
func8 := x
else
func8 := pieceBlank;
end;
function lookForWinner : integer;
var
t, p : integer;
begin
{dumpBoard;}
p := pieceBlank;
t := board[ 0 ];
if pieceBlank <> t then
begin
if ( ( ( t = board[1] ) and ( t = board[2] ) ) or
( ( t = board[3] ) and ( t = board[6] ) ) ) then
p := t;
end;
if pieceBlank = p then
begin
t := board[1];
if ( t = board[4] ) and ( t = board[7] ) then
p := t
else
begin
t := board[2];
if ( t = board[5] ) and ( t = board[8] ) then
p := t
else
begin
t := board[3];
if ( t = board[4] ) and ( t = board[5] ) then
p := t
else
begin
t := board[6];
if ( t = board[7] ) and ( t = board[8] ) then
p := t
else
begin
t := board[4];
if ( ( ( t = board[0] ) and ( t = board[8] ) ) or
( ( t = board[2] ) and ( t = board[6] ) ) ) then
p := t
end;
end;
end;
end;
end;
lookForWinner := p;
end;
function winner2( move: integer ) : integer;
var
x : integer;
begin
case move of
0: begin
x := board[ 0 ];
if not ( ( ( x = board[1] ) and ( x = board[2] ) ) or
( ( x = board[3] ) and ( x = board[6] ) ) or
( ( x = board[4] ) and ( x = board[8] ) ) )
then x := PieceBlank;
end;
1: begin
x := board[ 1 ];
if not ( ( ( x = board[0] ) and ( x = board[2] ) ) or
( ( x = board[4] ) and ( x = board[7] ) ) )
then x := PieceBlank;
end;
2: begin
x := board[ 2 ];
if not ( ( ( x = board[0] ) and ( x = board[1] ) ) or
( ( x = board[5] ) and ( x = board[8] ) ) or
( ( x = board[4] ) and ( x = board[6] ) ) )
then x := PieceBlank;
end;
3: begin
x := board[ 3 ];
if not ( ( ( x = board[4] ) and ( x = board[5] ) ) or
( ( x = board[0] ) and ( x = board[6] ) ) )
then x := PieceBlank;
end;
4: begin
x := board[ 4 ];
if not ( ( ( x = board[0] ) and ( x = board[8] ) ) or
( ( x = board[2] ) and ( x = board[6] ) ) or
( ( x = board[1] ) and ( x = board[7] ) ) or
( ( x = board[3] ) and ( x = board[5] ) ) )
then x := PieceBlank;
end;
5: begin
x := board[ 5 ];
if not ( ( ( x = board[3] ) and ( x = board[4] ) ) or
( ( x = board[2] ) and ( x = board[8] ) ) )
then x := PieceBlank;
end;
6: begin
x := board[ 6 ];
if not ( ( ( x = board[7] ) and ( x = board[8] ) ) or
( ( x = board[0] ) and ( x = board[3] ) ) or
( ( x = board[4] ) and ( x = board[2] ) ) )
then x := PieceBlank;
end;
7: begin
x := board[ 7 ];
if not ( ( ( x = board[6] ) and ( x = board[8] ) ) or
( ( x = board[1] ) and ( x = board[4] ) ) )
then x := PieceBlank;
end;
8: begin
x := board[ 8 ];
if not ( ( ( x = board[6] ) and ( x = board[7] ) ) or
( ( x = board[2] ) and ( x = board[5] ) ) or
( ( x = board[0] ) and ( x = board[4] ) ) )
then x := PieceBlank;
end;
end;
winner2 := x;
end;
function minmax( alpha: integer; beta: integer; depth: integer; move : integer ): integer;
var
p, value, pieceMove, score : integer;
begin
moves := moves + 1;
value := scoreInvalid;
if depth >= 4 then
begin
{ p := winner2( move ); }
p := TScoreFunc( scoreFuncs[ move ] );
{ p := LookForWinner; this is 10% slower than using function pointers }
if p <> pieceBlank then
begin
if p = pieceX then
value := scoreWin
else
value := scoreLose
end
else if depth = 8 then
value := scoreTie;
end;
if value = scoreInvalid then
begin
if Odd( depth ) then
begin
value := scoreMin;
pieceMove := pieceX;
end
else
begin
value := scoreMax;
pieceMove := pieceO;
end;
p := 0;
repeat
if board[ p ] = pieceBlank then
begin
board[ p ] := pieceMove;
score := minmax( alpha, beta, depth + 1, p );
board[ p ] := pieceBlank;
if Odd( depth ) then
begin
if ( score > value ) then
begin
value := score;
if ( value = scoreWin ) or ( value >= beta ) then p := 10
else if ( value > alpha ) then alpha := value;
end;
end
else
begin
if ( score < value ) then
begin
value := score;
if ( value = scoreLose ) or ( value <= alpha ) then p := 10
else if ( value < beta ) then beta := value;
end;
end;
end;
p := p + 1;
until p > 8;
end;
minmax := value;
end;
procedure runit( move : integer );
var score : integer;
begin
board[move] := pieceX;
score := minmax( scoreMin, scoreMax, 0, move );
board[move] := pieceBlank;
end;
var
i, errpos, loops: integer;
begin
loops := Iterations;
if 0 <> Length( ParamStr( 1 ) ) then
Val( ParamStr( 1 ), loops, errpos );
for i := 0 to 8 do
board[i] := pieceBlank;
scoreFuncs[0] := @func0;
scoreFuncs[1] := @func1;
scoreFuncs[2] := @func2;
scoreFuncs[3] := @func3;
scoreFuncs[4] := @func4;
scoreFuncs[5] := @func5;
scoreFuncs[6] := @func6;
scoreFuncs[7] := @func7;
scoreFuncs[8] := @func8;
evaluated := 0;
get_time( timeStart );
for i := 1 to loops do
begin
moves := 0;
runit( 0 );
runit( 1 );
runit( 4 );
evaluated := evaluated + moves;
end;
get_time( timeEnd );
print_elapsed_time( timeStart, timeEnd );
WriteLn( 'moves evaluated: ', evaluated );
WriteLn( 'iterations: ', loops );
end.

View File

@ -0,0 +1,4 @@
@echo off
setlocal
ntvdm -r:. -t qpl %1.pas