-
Notifications
You must be signed in to change notification settings - Fork 3
/
chessplayertypes.pas
133 lines (116 loc) · 3.18 KB
/
chessplayertypes.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
{ Autor: Jürgen Schlottke, Schönaich-C.-Str. 46, D-W 2200 Elmshorn
Tel. 04121/63109
Zweck : Demonstration der Schachprogrammierung unter Turbo-Pascal
Datum : irgendwann 1991, als PD freigegeben am 18.01.93
Version: ohne Versionsnummer
}
unit ChessPlayerTypes;
interface
type
TChessboard = array[-10..109] of shortint;
const
CNil = 0;
CWhite = 1;
CBlack = -1;
CPawn = 2;
CBishop = 6;
CKnight = 7;
CRook = 10;
CQueen = 19;
CKing = 126;
CBorder = 127;
(*
CColToInt: array['a'..'h'] of integer = (1, 2, 3, 4, 5, 6, 7, 8);
CRowToInt: array['1'..'8'] of integer = (1, 2, 3, 4, 5, 6, 7, 8);
CDigitToRow: array['1'..'8'] of char = ('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h');
CRowToDigit: array['a'..'h'] of char = ('1', '2', '3', '4', '5', '6', '7', '8');
*)
function ColToInt(const c: char): integer;
function RowToInt(const c: char): integer;
function DigitToRow(const c: char): char;
procedure MoveToInt(const m: string; var i, p: integer);
function MoveToStr(const m: integer): string;
function PieceToInt(const p: char): shortint;
function PieceToChar(const p: shortint): char;
implementation
uses
SysUtils;
function ColToInt(const c: char): integer;
begin
result := Ord(c) - Ord('a') + 1;
end;
function RowToInt(const c: char): integer;
begin
result := Ord(c) - Ord('1') + 1;
end;
function DigitToRow(const c: char): char;
begin
result := Chr(Ord(c) - Ord('1') + Ord('a'));
end;
function RowToDigit(const c: char): char;
begin
result := Chr(Ord(c) - Ord('a') + Ord('1'));
end;
function MoveToStr(const m: integer): string;
begin
result := IntToStr(m);
result[1] := DigitToRow(result[1]);
result[3] := DigitToRow(result[3]);
end;
procedure MoveToInt(const m: string; var i, p: integer);
var
s: string;
begin
s := Copy(m, 1, 4);
s[1] := RowToDigit(s[1]);
s[3] := RowToDigit(s[3]);
i := StrToInt(s);
p := 0;
if Length(m) > 4 then
case m[5] of
'b': p := CBishop;
'n': p := CKnight;
'r': p := CRook;
'q': p := CQueen;
end;
end;
function PieceToInt(const p: char): shortint;
begin
case p of
'P': result := CWhite * CPawn;
'N': result := CWhite * CKnight;
'B': result := CWhite * CBishop;
'R': result := CWhite * CRook;
'Q': result := CWhite * CQueen;
'K': result := CWhite * CKing;
'p': result := CBlack * CPawn;
'n': result := CBlack * CKnight;
'b': result := CBlack * CBishop;
'r': result := CBlack * CRook;
'q': result := CBlack * CQueen;
'k': result := CBlack * CKing;
else
result := CNil;
end;
end;
function PieceToChar(const p: shortint): char;
begin
case p of
CWhite * CPawn : result := 'P';
CWhite * CKnight: result := 'N';
CWhite * CBishop: result := 'B';
CWhite * CRook : result := 'R';
CWhite * CQueen : result := 'Q';
CWhite * CKing : result := 'K';
CBlack * CPawn : result := 'p';
CBlack * CKnight: result := 'n';
CBlack * CBishop: result := 'b';
CBlack * CRook : result := 'r';
CBlack * CQueen : result := 'q';
CBlack * CKing : result := 'k';
CNil : result := '.';
CBorder : result := '#'
else result := '?';
end;
end;
end.