-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathc1.txt
More file actions
153 lines (148 loc) · 5.92 KB
/
c1.txt
File metadata and controls
153 lines (148 loc) · 5.92 KB
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
function score(c:gamestatearray;d:integer):integer;
begin
if c[3] then
score:=1
else
begin
score:=d;
if c[5] then score:=20;
if c[6] then score:=40;
if c[4] then
score*=2
else
score*=-2;
end;
end;
function AIinput
( a:boardarraytype; b:boardlevel; c:gamestatearray;death:integer):AIscore;
var
ALLBoard:boardarraytype;
ALLboardlevel,order:boardlevel; //USE order of a random order to calcuate best input
ALLgamestate:gamestatearray;
ALLscore:Aiscore;
i,j:integer;
begin
//write('.');
if death=0 then
begin
//writeln('kill');
randomarray(order);
i:=1;
while(inrange(order[i],1,7)) do
begin
if validatemove(b,order[i]) then
break;
i+=1;
end;
AIinput[1]:=order[i];//write(AIinput[1]);
AIinput[2]:=0 ;
end
else
if c[1] then
begin
//calcuate default value(valdiated)
randomarray(order);
i:=1;
//writeln(order[1]);
while(inrange(i,1,7)) do
begin
if validatemove(b,order[i])then
break;
i+=1;
end;
ALlscore[1]:=order[i];if c[1] then ALlscore[2]:=0 else ALlscore[2]:=0;
//write(AIinput[1]);
i:=1;// ALlscore[1]:=1;ALlscore[2]:=-2;
while inrange(i,1,7) and (ALlscore[2]<>80) do
begin
if not(validatemove(b,order[i])) then
begin
i+=1;
continue;
end;
// write( order[i]);
//similate move
copyboardarraytype(ALLBoard,a);
copygamestatearray(ALLgamestate,c);
copyboardlevel(ALLboardlevel,b);
//writeln('1');
move(ALLBoard,ALLboardlevel,ALLgamestate,order[i]);
//writeln(order[i]) ;
if(ALLgamestate[2]) then
begin
j:=score(ALLgamestate,death);
//calcuate score
end
else
begin
// write(2);
j:=AIinput(ALLBoard,ALLboardlevel,ALLgamestate,death-1)[2];
end;
if ALLscore[2]<=j then
begin
ALLscore[1]:=order[i];
ALLscore[2]:=j;
end;
i+=1;
end;
AIinput:= ALLscore;
end
else
begin
i:=1;
randomarray(order);
while(inrange(i,1,7)) do
begin
if validatemove(b,order[i])then
break;
i+=1;
end;
ALlscore[1]:=order[i];
ALlscore[2]:=0;
i:=1;randomarray(order);
// writeln(order[1]);writeln(order[2]);
// ALlscore[1]:=1;ALlscore[2]:=2;
while inrange(i,1,7) and (ALlscore[2]<>-80) do
begin
if not(validatemove(b,order[i])) then
begin
i+=1;
continue;
end;
copyboardarraytype(ALLBoard,a);
copygamestatearray(ALLgamestate,c);
copyboardlevel(ALLboardlevel,b);//writeln('-1');
move(ALLBoard,ALLboardlevel,ALLgamestate,order[i]);
if(ALLgamestate[2]) then
begin
j:=score(ALLgamestate,death);
end
else
begin //write(1);
j:=AIinput(ALLBoard,ALLboardlevel,ALLgamestate,death-1)[2];
end;
if ALLscore[2]>=j then
begin
ALLscore[1]:=order[i];
ALLscore[2]:=j;
end;
i+=1;
end;
AIinput:= ALLscore;
end;
//writeln();write(AIinput[1]);write('||');writeln(AIinput[2]);
end;
function AIinputtoplevel
( a:boardarraytype; b:boardlevel;c:gamestatearray;step:integer):AIscore;
begin
if step<7 then
AIinputtoplevel:=AIinput(a,b,c,6)
else
if step<25 then
AIinputtoplevel:=AIinput(a,b,c,9)
else
AIinputtoplevel:=AIinput(a,b,c,deap);
if a[6,5]=emptyunit then AIinputtoplevel[1]:=5;
if a[6,4]=emptyunit then AIinputtoplevel[1]:=4;
write('AI01 alpha-beta play in :');
writeln(AIinputtoplevel[1]);