-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnortham.pas
66 lines (52 loc) · 1.46 KB
/
northam.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
uses
SysUtils, Math;
function StartPosition(): string;
type
TIntegerArray = array of integer;
function EmptySquares(const aRow: string; const iStart, iEnd: integer): TIntegerArray;
var
i: integer;
begin
SetLength(result, 0);
for i := iStart to iEnd do
if aRow[i] = '.' then
begin
SetLength(result, Succ(Length(result)));
result[High(result)] := i;
end;
end;
function CastlingRights(const iRook1, iRook2: integer): string;
begin
result := Concat(
Chr(Ord('A') + Pred(iRook1)),
Chr(Ord('A') + Pred(iRook2)),
Chr(Ord('a') + Pred(iRook1)),
Chr(Ord('a') + Pred(iRook2))
);
end;
var
i, iRook1, iRook2: integer;
arr: TIntegerArray;
blackpieces: string;
begin
result := StringOfChar('.', 8);
result[2 * Random(4) + 1] := 'B';
result[2 * Random(4) + 2] := 'B';
arr := EmptySquares(result, 1, 8);
i := arr[Random(4) + 1];
result[i] := 'K';
iRook1 := RandomFrom(EmptySquares(result, 1, Pred(i)));
result[iRook1] := 'R';
iRook2 := RandomFrom(EmptySquares(result, Succ(i), 8));
result[iRook2] := 'R';
result[RandomFrom(EmptySquares(result, 1, 8))] := 'Q';
for i := 1 to 8 do
if result[i] = '.' then
result[i] := 'N';
blackpieces := LowerCase(result);
result := Concat(blackpieces, '/pppppppp/8/8/8/8/PPPPPPPP/', result, ' w ', CastlingRights(iRook2, iRook1), ' - 0 1');
end;
begin
Randomize;
WriteLn(StartPosition());
end.