解決済み、学生バグ
function Tform1.Boardtostr(const aboard:Tboard):string;
var a,b:integer;
begin
result:='';
for a:= 1 to 8 do
begin
for b:=1 to 8 do
begin
if board[b][a] = -1 then //<--should be aboard instead of board
result:=result+'0'
else if board[b][a] = 0 then//<--should be aboard instead of board
result:=result+'1'
else if board[b][a] = 1 then //<--should be aboard instead of board
result:=result+'2';
end;
end;
end;
==================================
私は Sum GNU Anti Reversi の作者です。Delphi プログラムにハッシュ テーブルを追加したいと思います。Delphi 2010 を使用しています。最小最大関数にハッシュ テーブルを追加します。コンピュータが間違ったスコアを出すことを知りません。助けてください。ありがとうございます。オリジナル番組
ハッシュ テーブルのバージョン:
https://sourceforge.net/projects/antireversi8x8/files/Debug-Will%20delete/debuging.zip/download
修正箇所:
aHashTable :TStringHash;
aHashTable :=TStringHash.Create;
function TForm1.AI(Aboard:Tboard;ComputerIsRed:Boolean):string;
....
// if (a + b < 46) and (c > 4) and (Realdepth > 5) then
// a:=minMaxStart(Aboard,ComputerIsRed,Realdepth,thinkstep)
// else
// a:=minMaxRandom(Aboard,ComputerIsRed,Realdepth,thinkstep);
a:=minMaxRandom(Aboard,ComputerIsRed,Realdepth,thinkstep);//<-To test hash table
...
function TForm1.MinMaxRandom(Aboard:Tboard;SideIsRed:Boolean;depth:integer;var aithinkstep:string):integer;
var a,b,c,d,bestvalue, value:integer;templist:tstringlist;tempboard:Tboard;oldaithinkstep:string;aithinksteplist:Tstringlist;
begin
aHashTable.clear;
Application.ProcessMessages;
Score(Aboard,a,b);
if a = 0 then
begin
if SideIsRed then
result:= 2000
else
result:= -2000;
exit;
end;
if b = 0 then
begin
if SideIsRed then
result:= -2000
else
result:= 2000;
exit;
end;
if (depth<=0) or (a+b>63) then
begin
result:= EvaluateScore(Aboard,SideIsRed);
exit;
end;
templist := Tstringlist.Create;
bestvalue:=-INF
if SideIsRed Then
MakeRedMove(Aboard,templist)
else
MakeBlackMove(Aboard,templist);
if templist.Count = 0 then
begin
if SideIsRed Then
MakeBlackMove(Aboard,templist)
else
MakeRedMove(Aboard,templist);
if templist.Count = 0 then // both red and black no move
begin
templist.Free;
result:= EvaluateScore(Aboard,SideIsRed);
exit;
end;
result := -MinMax(Aboard,Not SideIsRed,depth,aithinkstep);//);
templist.Free;
exit;
end;
...
end;
function TForm1.MinMax(Aboard:Tboard;SideIsRed:Boolean;depth:integer;var aithinkstep:string):integer;
var a,b,c,d,bestvalue, value:integer;templist:tstringlist;tempboard:Tboard;oldaithinkstep,bestaithinkstep:string;
Application.ProcessMessages;
bestaithinkstep:=aithinkstep;
Score(Aboard,a,b);
if a = 0 then
begin
if SideIsRed then
result:= 2000
else
result:= -2000;
exit;
end;
if b = 0 then
begin
if SideIsRed then
result:= -2000
else
result:= 2000;
exit;
end;
if (depth<=0) or (a+b>63) or StopThink then
begin
result:= EvaluateScore(Aboard,SideIsRed);
exit;
end;
templist := Tstringlist.Create;
bestvalue:=-INF;
if SideIsRed Then
MakeRedMove(Aboard,templist)
else
MakeBlackMove(Aboard,templist);
if templist.Count = 0 then
begin
if SideIsRed Then
MakeBlackMove(Aboard,templist)
else
MakeRedMove(Aboard,templist);
if templist.Count = 0 then // both red and black no move
begin
templist.Free;
result:= EvaluateScore(Aboard,SideIsRed);
exit;
end;
aithinkstep := aithinkstep +'->PASS';
result := -MinMax(Aboard,Not SideIsRed,depth,aithinkstep);
templist.Free;
exit;
end;
tempboard:=Aboard;
oldaithinkstep :=aithinkstep;
if aHashTable.ValueOf(boardtostr(aboard)+Booltostr(SideIsRed)+inttostr(depth)) = -1 then //Hash test
begin
For a:= 0 to templist.Count-1 do
begin
Application.ProcessMessages;
aithinkstep := oldaithinkstep;
d:= strtoint(templist[a]);
b:= d div 8 +1 ;
c:= d mod 8;
if c = 0 then
begin
b:=b-1;
c:=8;
end;
aithinkstep := aithinkstep+'->'+intTostr(c)+','+intTostr(b);
Aboard:=tempboard;
if SideIsRed Then
RedboardUpdate(Aboard,strToint(templist[a]))
else
BlackboardUpdate(aboard,strToint(templist[a]));
value:= -MinMax(Aboard,Not SideIsRed,depth-1,aithinkstep);
if value > bestvalue then
begin
bestvalue:=value;
bestaithinkstep := aithinkstep;
end;
end;
aHashTable.Add(boardtostr(tempboard)+Booltostr(SideIsRed)+inttostr(depth),bestvalue);
end
else
BestValue:= aHashTable.ValueOf(boardtostr(aboard)+Booltostr(SideIsRed)+inttostr(depth));
templist.Free;
aithinkstep :=bestaithinkstep;
Result:= bestvalue;
end;