Delphi Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreDelphi Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old February 8th, 2005, 05:01 PM
Delfi Delfi is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 1 Delfi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 21 m 44 sec
Reputation Power: 0
Question Problem with value of arguments

First of all here is the problematic code...(it is a bit big, but don't be scared of it, because the problem is horrible.)

procedure TAI.YourTurn;
var n, x, y, depth: byte;
begin
LoadGens(
strtoint(form1.memo3.Lines[0]),
strtoint(form1.memo3.Lines[1]),
strtoint(form1.memo3.Lines[2]),
strtoint(form1.memo3.Lines[3]),
strtoint(form1.memo3.Lines[4]),
strtoint(form1.memo3.Lines[5]),
strtoint(form1.memo3.Lines[6]),
strtoint(form1.memo3.Lines[7]),
strtoint(form1.memo3.Lines[8]));

movementStarted:=false;
jumped:=0;
steped:=0;
myTurn:=true;
timer.Tag:=0;
timer.Interval:=100;
myGame.AnounceTime;
depth:=StrToInt(Form1.Edit1.Text);
RootSearchAB(-maxint-1, maxint, depth, n, x, y);
inc(game.numberOfMoves);
setlength(game.moves, game.numberOfMoves*4);
game.moves[length(game.moves)-4]:=Pawns[n].x;
game.moves[length(game.moves)-3]:=Pawns[n].y;
game.moves[length(game.moves)-2]:=x;
game.moves[length(game.moves)-1]:=y;

MakeMove(n, pawns[n].x, pawns[n].y, x, y, 9);

game.PlayerDone;
end;

procedure TAI.RootSearchAB(alpha, beta: integer; const depth: byte; var n, x, y: byte);
label 1;
var f, i, p, la, nowp: integer;
a: TDynamicArray;
begin
np:=0;
form1.Memo1.Lines.Clear;
form1.Memo2.Lines.Clear;
nowp:=NumOfWinPawns;
GenerateAllMoves(self.color, depth, a);
{declaration of previous procedure is:
procedure TAI.GenerateAllMoves(c: TColor; const d: byte;var a: TDynamicArray);}
la:=(length(a) div 5)-1;
for i:=0 to la do
begin
MakeMove(a[i*5], a[i*5+1], a[i*5+2], a[i*5+3], a[i*5+4], 9);
myGame.gameState:=(1-myGame.gameState);

f:=-NegaMaxAB(alpha, beta, depth-1, (1-self.color), nowp);
if f>alpha then
begin
alpha:=f;
p:=i;
end;
form1.Memo1.Lines.Append(inttostr(i)+': '+inttostr(a[i*5])+inttostr(a[i*5+1])+ inttostr(a[i*5+2])+ inttostr(a[i*5+3])+ inttostr(a[i*5+4]));
form1.Memo2.Lines.Append(inttostr(f));
myGame.gameState:=(1-myGame.gameState);
MakeMove(a[i*5], a[i*5+3], a[i*5+4], a[i*5+1], a[i*5+2], 9);
if alpha>=beta then goto 1;
end;
1:
n:=jumped;
n:=steped;
n:=a[p*5];
x:=a[p*5+3];
y:=a[p*5+4];
form1.Label1.Caption:='Broj procenjenih pozicija je '+IntToStr(np);
end;

function TAI.NegaMaxAB(alpha, beta: integer; const depth, clr, nowp: byte): integer;
label 1, 2;
var f, i, la, sign, a1, b1, c1, d1, f1, g1: integer;
a: TDynamicArray;
begin
sign:=ord(self.color=clr)+ord(self.color<>clr)*(-1);
if (depth<=0) or myGame.players[1-clr].IAmWinner
then
begin
sign:=sign*(depth+1);
result:=sign*PositionValue(self.a, self.b, self.c, self.d, self.e, self.f, self.g, self.h, self.q, nowp);
inc(np);
end
else
begin
GenerateAllMoves(clr, depth, a);
la:=(length(a) div 5) -1;
if clr<>self.color then //minimizing
begin
for i:=0 to la do
begin
myGame.players[clr].MakeMove(a[i*5], a[i*5+1], a[i*5+2], a[i*5+3], a[i*5+4], 9);
myGame.gameState:=(1-myGame.gameState);

f:=-NegaMaxAB(alpha, beta, depth-1, 1-clr, nowp);
if f<beta then beta:=f;

myGame.gameState:=(1-myGame.gameState);
myGame.players[clr].MakeMove(a[i*5], a[i*5+3], a[i*5+4], a[i*5+1], a[i*5+2], 9);
if alpha>=beta then goto 1;
end;
1: result:=beta;
end
else
begin
for i:=0 to la do
begin
myGame.players[clr].MakeMove(a[i*5], a[i*5+1], a[i*5+2], a[i*5+3], a[i*5+4], 9);
myGame.gameState:=(1-myGame.gameState);

f:=-NegaMaxAB(alpha, beta, depth-1, 1-clr, nowp);
if f>alpha then alpha:=f;

myGame.gameState:=(1-myGame.gameState);
myGame.players[clr].MakeMove(a[i*5], a[i*5+3], a[i*5+4], a[i*5+1], a[i*5+2], 9);
if alpha>=beta then goto 2;
end;
2: result:=alpha;
end;
end;
end;

When YourTurn is called, depth value is 2, and when YourTurn calls RootSearch procedure value of argument depth is 220. When RootSearch calls Negamax with "depth-1"... depth in Negamax has value 120, and it shold acually be 220-1=219! Clr and nowp arguments in Negamax also don't have expected values!

HELP!

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreDelphi Programming > Problem with value of arguments


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT