Lambda-search pseudo-code (version 1.0)
01 lambdaLoop(n,d) {
02 xxif(d<0) {
03xxxxxif(n==-1) {
04xxxxxxxreturn evaluation();
05xxxxx}
06xxxxxelse {
07 xxxxxxreturn 0.0;
08xxxxx}
09 xx}
10 xxlabel1:
11 xxfor(j=-1;j<=n &&
j<=(d-1)/2;j=j+1) {
12 xxxxfor(dmax=id*d;dmax>=-infinity;dmax=dmax-2)
{
13 xxxxxxvalue=lambda(j,d,dmax,1,0.25,0.75);
14 xxxxxxif(value==1)break label1;
15 xxxx}
16 xx}
17 xxreturn value;
18 }
19
20 lambda(n,d,dmax,moveColor,alpha,beta) {
21 xxcurrent=-infinity;
22 xxif (n<=-1 || d<=0 ||
d<=dmax) {
23 xxxxreturn evaluation();
24 xx}
25 xxflag=0;
26 xxgenerateAllLegalMoves(moveColor);
27 xxlabel2:
28 xxfor(i=1;i<=numberOfAllLegalMoves;i=i+1)
{
29 xxxxoneMoveForwards(allLegalMoves[i],moveColor);
30 xxxxif(moveColor==1) {
31 xxxxxxif(lambdaLoop(n-1,d-2)<1) {
32 xxxxxxxxundoOneMoveForwards();
33 xxxxxxxxcontinue label2;
34 xxxxxx}
35 xxxx}
36 xxxxif(moveColor==-1) {
37 xxxxxxif(lambdaLoop(n-1,d-1)==1) {
38 xxxxxxxxundoOneMoveForwards();
39 xxxxxxxxcontinue label2;
40 xxxxxx}
41 xxxx}
42 xxxxflag=1;
43 xxxxscore=-lambda(n,d-1,dmax,-moveColor,-beta,-alpha);
44 xxxxundoOneMoveForwards();
45 xxxxif(score>=current) {
46 xxxxxxcurrent=score;
47 xxxxxxif(score>=alpha)alpha=score;
48 xxxxxxif(score>=beta)break label2;
49 xxxx}
50 xx}
51 xxif(flag==0) {
52 xxxxif(moveColor==1) {
53 xxxxxxreturn 0.0*moveColor;
54 xxxx}
55 xxxxif(moveColor==-1) {
56 xxxxxxreturn 1.0*moveColor;
57 xxxx}
58 xx}
59 xxreturn current;
60 }
The procedure lamdaLoop() is called by two arguments, n and d, restricting the l -search to at most l-order n, and restricting the search depth to at most d plies. lamdaLoop() must be called with d being an uneven number, and lamdaLoop() always assumes that the attacker moves first. If lambdaLoop() returns value 1, the attacker's goal can be obtained; if it returns value 0, it cannot be obtained at l-order n and depth d. The variable id controls whether the l-trees are searched with standard depth-first alpha-beta (id=0), or iterated deepening (id=1).
In the procedure lambda(), the variable moveColor attains value 1 if the attacker is to move, and 1 if the defender is to move. Otherwise, lambda() is just standard alpha-beta, except for the lines 22-25, 30-42 (pruning off non-l n-moves), and 51-58. Evaluation() is a procedure that evaluates the position, the evaluation being = 1·moveColor if the attacker's goal is obtained, and 0·moveColor otherwise.
The above code could be supplemented with the possibility of returning value 0.5 instead of only 1 or 0. Hence, 0.5 wold signify that the goal cannot be acheived at the current search depth, whereas 0 would signify that it has been disproved that the goal can be acheived (at any search depth). In the latter case, itereated deepening could also stop searching deeper.