-
Notifications
You must be signed in to change notification settings - Fork 3
/
tetris_lib.pas
132 lines (122 loc) · 2.29 KB
/
tetris_lib.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
library tetris_lib;
//uses display;
{$I tetris_def.inc}
{$I tetris_pce.inc}
{$I tetris_ai.inc}
var
i, j, k: longint;
const
guess = 0;
//AI主DLL入口
function AI(boardW, boardH: longint; board: PChar; curPiece: char;
curX, curY, curR: longint; nextPiece: char;
bestX, bestRotation: pinteger): longint; stdcall;
begin
//设置宽度
wbd := boardW;
//设置高度
hbd := boardH;
//初始化盘面及方块
ainew2();
//设置盘面
k := 0;
//厉遍高度
for j := 1 to hbd do
begin
//初始化该行
aibd2[j, 0] := 0;
//厉遍宽度
for i := 1 to wbd do
begin
//如果传入盘面数组元素不为'0'
if board[k] <> #48 then
//对该行与1进行或运算
aibd2[j, 0] := aibd2[j, 0] or 1;
//该行左移
aibd2[j, 0] := aibd2[j, 0] shl 1;
//获取下一数组元素
k := k + 1;
end;
//该行左移(对齐空行)
//该行与空行进行或运算(填补墙壁)
aibd2[j, 0] := (aibd2[j, 0] shl 1) or bdcnull;
end;
//设置深度
aidepthc := 1 + guess;
for k := 1 to depthm do
with aiknext[k] do
begin
knd := 0;
sit := 1;
posx := wbd div 2;
posy := hbd - 1;
end;
//设置当前方块种类
with aiknext[1] do
begin
case curPiece of
'O':
knd := 1;
'I':
knd := 2;
'S':
knd := 3;
'Z':
knd := 4;
'L':
knd := 5;
'J':
knd := 6;
'T':
knd := 7;
else
knd := 0;
end;
//设置当前方块位置及状态
sit := curR;
posx := curX;
posy := curY;
end;
//设置下一块方块种类
with aiknext[2] do
begin
case nextPiece of
'O':
knd := 1;
'I':
knd := 2;
'S':
knd := 3;
'Z':
knd := 4;
'L':
knd := 5;
'J':
knd := 6;
'T':
knd := 7;
else
knd := 0;
end;
//设置深度
if not (knd = 0) then
aidepthc := 2 + guess;
sit := 1;
posx := wbd div 2+1;
posy := hbd - 1;
end;
//AI主函数
aigo(1);
//设置返回结果
bestX^ := airposb;
bestRotation^ := airsit + 1;
end;
//AI名称DLL入口
function Name(): PChar;
begin
//返回AI名称
Name := 'Tetris_ax';
end;
exports AI;
exports Name;
end.