|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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! |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > Delphi Programming > Problem with value of arguments |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|