~ubuntu-branches/ubuntu/hardy/dds/hardy

« back to all changes in this revision

Viewing changes to dds.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Christoph Berg
  • Date: 2007-05-12 12:30:20 UTC
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20070512123020-2o0abiib5zlvujim
Tags: upstream-1.1.4+ddd105
ImportĀ upstreamĀ versionĀ 1.1.4+ddd105

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
 
2
 
/* DDS 1.1.3   A bridge double dummy solver.                                        */
 
2
/* DDS 1.1.4   A bridge double dummy solver.                                        */
3
3
/* Copyright (C) 2006-2007 by Bo Haglund                                      */
4
4
/* Cleanups and porting to Linux and MacOSX (C) 2006 by Alex Martelli         */
5
5
/*                                                                                            */
68
68
int threshold=CANCELCHECK;
69
69
#endif
70
70
 
 
71
 
 
72
#if defined(_WIN32)
71
73
extern "C" BOOL APIENTRY DllMain(HMODULE hModule,
72
74
                                DWORD ul_reason_for_call,
73
75
                                LPVOID lpReserved) {
90
92
  }
91
93
  return 1;
92
94
}
 
95
#endif
93
96
 
94
97
 
95
98
  int STDCALL SolveBoard(struct deal dl, int target,
135
138
    DumpInput(-9, dl, target, solutions, mode);
136
139
    return -9;
137
140
  }
138
 
  if ((mode==2)&&((target==-1)||(solutions!=1))) {
 
141
  if ((mode==2)&&((0/*target==-1*/)||(0/*solutions!=1*/))) {
139
142
    DumpInput(-11, dl, target, solutions, mode);
140
143
    return -11;
141
144
  }
411
414
  if ((target==0)&&(solutions<3)) {
412
415
    MoveGen(&lookAheadPos, iniDepth);
413
416
    futp->nodes=0;
414
 
    /*futp->totalNodes=0;*/
 
417
        /*futp->totalNodes=0;*/
415
418
    for (k=0; k<=movePly[iniDepth].last; k++) {
416
419
        futp->suit[k]=movePly[iniDepth].move[k].suit;
417
420
        futp->rank[k]=movePly[iniDepth].move[k].rank;
785
788
  bitMapRank[0]=0;
786
789
 
787
790
  bestMove = (struct moveType *)calloc(50, sizeof(moveType));
 
791
  /*bestMove = new moveType [50];*/
788
792
  if (bestMove==NULL)
789
 
    exit(0);
 
793
    exit(1);
790
794
 
791
795
  handStore[0][0]=0;
792
796
  handStore[0][1]=1;
820
824
  cardHand[0]='N'; cardHand[1]='E'; cardHand[2]='S'; cardHand[3]='W';
821
825
 
822
826
  winCards = (struct winCardType *)calloc(winSetSizeLimit+1, sizeof(winCardType));
 
827
  /*winCards = new winCardType[winSetSizeLimit+1];*/
823
828
  if (winCards==NULL) {
824
829
    winSetSizeLimit=5000000;
825
830
    winCards = (struct winCardType *)calloc(winSetSizeLimit+1, sizeof(winCardType));
 
831
        /*winCards = new winCardType[winSetSizeLimit+1];*/
826
832
    if (winCards==NULL)
827
 
      exit(0);
 
833
      exit(1);
828
834
    nodeSetSizeLimit=2500000;
829
835
    nodeSetFill=2000000;
830
836
    winSetFill=4000000;
831
837
  }   
832
838
 
833
839
  nodeCards = (struct nodeCardsType *)calloc(nodeSetSizeLimit+1, sizeof(nodeCardsType));
 
840
  /*nodeCards = new nodeCardsType[nodeSetSizeLimit+1];*/
834
841
  if (nodeCards==NULL)
835
 
    exit(0);
 
842
    exit(1);
836
843
  
837
844
  posSearch = (struct posSearchType *)calloc(lenSetSizeLimit+1, sizeof(posSearchType));
 
845
  /*posSearch = new posSearchType[lenSetSizeLimit+1];*/
838
846
  if (posSearch==NULL)
839
 
    exit(0);
 
847
    exit(1);
840
848
 
841
849
  ttStore = (struct ttStoreType *)calloc(SEARCHSIZE, sizeof(ttStoreType));
 
850
  /*ttStore = new ttStoreType[SEARCHSIZE];*/
842
851
  if (ttStore==NULL)
843
 
    exit(0);
 
852
    exit(1);
844
853
 
845
 
  rel = (relRanksType *)calloc(16385, sizeof(relRanksType));
 
854
  rel = (relRanksType *)calloc(16384, sizeof(relRanksType));
 
855
  /*rel = new relRanksType[16384];*/
846
856
  if (rel==NULL)
847
 
    exit(0);
 
857
    exit(1);
848
858
 
849
859
  return;
850
860
}
855
865
  int k, s, h, r, cardFound, currHand=0, order, m, temp1, temp2;
856
866
  unsigned short int ind;
857
867
  unsigned short int rankInSuit[4][4];
858
 
  int points[4], tricks;
 
868
  /*int points[4], tricks;
859
869
  int addNS, addEW, addMAX, trumpNS, trumpEW;
860
 
  struct gameInfo gm;
 
870
  struct gameInfo gm;*/
861
871
 
862
872
  #ifdef STAT
863
873
    fp2=fopen("stat.txt","w");
930
940
    trumpContract=FALSE;
931
941
  
932
942
  /*start: tricksest */
933
 
 
 
943
#if 0
934
944
  gm=game;
935
945
  if (game.leadRank!=0)
936
946
    gm.suit[gm.leadHand][gm.leadSuit]=
1011
1021
    estTricks[0]=13-tricks;
1012
1022
    estTricks[2]=13-tricks;
1013
1023
  }
1014
 
 
 
1024
#endif
 
1025
  estTricks[1]=6;
 
1026
  estTricks[3]=6;
 
1027
  estTricks[0]=7;
 
1028
  estTricks[2]=7;
1015
1029
  /*end: tricksest */
1016
1030
 
1017
1031
  #ifdef STAT
1051
1065
  }
1052
1066
 
1053
1067
  for (d=0; d<=49; d++) {
1054
 
    bestMove[d].suit=0;
 
1068
    /*bestMove[d].suit=0;*/
1055
1069
    bestMove[d].rank=0;
1056
 
    bestMove[d].weight=0;
1057
 
    bestMove[d].sequence=0;
 
1070
    /*bestMove[d].weight=0;
 
1071
    bestMove[d].sequence=0; 0315 */
1058
1072
  }
1059
1073
 
1060
1074
  if ((handStore[first][handRelFirst]==0)||
1121
1135
  for (s=0; s<=3; s++)
1122
1136
    iniRemovedRanks[s]=posPoint->removedRanks[s];
1123
1137
 
1124
 
 
1125
 
  for (d=0; d<=49; d++) {
 
1138
  /*for (d=0; d<=49; d++) {
1126
1139
    for (s=0; s<=3; s++)
1127
1140
      posPoint->winRanks[d][s]=0;
1128
 
  }
1129
 
 
 
1141
  }*/
1130
1142
 
1131
1143
  /* Initialize winning rank */
1132
1144
  for (s=0; s<=3; s++) {
1197
1209
      posPoint->length[h][s]=
1198
1210
            (unsigned char)CountOnes(posPoint->rankInSuit[h][s]);
1199
1211
 
 
1212
  #ifdef STAT
1200
1213
  for (d=0; d<=49; d++) {
1201
1214
    score1Counts[d]=0;
1202
1215
    score0Counts[d]=0;
1203
1216
    c1[d]=0;  c2[d]=0;  c3[d]=0;  c4[d]=0;  c5[d]=0;  c6[d]=0; c7[d]=0;
1204
1217
    c8[d]=0;
1205
1218
    no[d]=0;
1206
 
  }  
 
1219
  }
 
1220
  #endif
1207
1221
 
1208
1222
  if (!mtd) {
1209
1223
        lenSetSize=0;  
1360
1374
 
1361
1375
        return TRUE;
1362
1376
      }
1363
 
        if (!LaterTricksMIN(posPoint,hand,depth,target))
1364
 
          return FALSE;
 
1377
          if (!LaterTricksMIN(posPoint,hand,depth,target))
 
1378
                return FALSE;
1365
1379
    }
1366
1380
    else {
1367
1381
      quick=QuickTricks(posPoint, hand, depth, target);
1386
1400
          #endif
1387
1401
        return FALSE;
1388
1402
      }
1389
 
        if (LaterTricksMAX(posPoint,hand,depth,target))
1390
 
          return TRUE;
 
1403
          if (LaterTricksMAX(posPoint,hand,depth,target))
 
1404
                return TRUE;
1391
1405
    }
1392
1406
  }
1393
1407
  
1473
1487
      sopFound=FALSE;
1474
1488
      if (cardsP!=NULL) {
1475
1489
        sopP=CheckSOP(posPoint, cardsP, hand, 
1476
 
              target, &res, &scoreFlag);
 
1490
              target, tricks, &res, &scoreFlag);
1477
1491
        if (res) {
1478
1492
          sopFound=TRUE;
1479
1493
          cardsP=sopP;
1484
1498
        if (np==NULL)
1485
1499
          cardsP=NULL;
1486
1500
        else 
1487
 
          cardsP=FindSOP(posPoint, np, hand, target, &scoreFlag);
 
1501
          cardsP=FindSOP(posPoint, np, hand, target, tricks, &scoreFlag);
1488
1502
      }
1489
1503
      
1490
1504
      if ((cardsP!=NULL)&&(depth!=iniDepth)) {
1517
1531
              ReceiveTTstore(posPoint, cardsP, target, depth);
1518
1532
            else 
1519
1533
              ttCollect=FALSE;
1520
 
            }
 
1534
              }
1521
1535
          #endif 
1522
1536
          return TRUE;
1523
1537
          }
1591
1605
  else {
1592
1606
    moveExists=MoveGen(posPoint, depth);
1593
1607
    
1594
 
    /*#if 0*/
1595
1608
    if ((posPoint->handRelFirst==3)&&(depth>=29)&&(depth!=iniDepth)) {
1596
1609
      movePly[depth].current=0;
1597
1610
      mexists=TRUE;
1622
1635
            tempP=pp->first;
1623
1636
            sopFound=FALSE;
1624
1637
          if (tempP!=NULL) {
1625
 
             sopP=CheckSOP(posPoint, tempP, hfirst, target, &res, &scoreFlag);
 
1638
             sopP=CheckSOP(posPoint, tempP, hfirst, target, tricks, &res, &scoreFlag);
1626
1639
             if (res) {
1627
1640
               sopFound=TRUE;
1628
1641
               tempP=sopP;
1633
1646
            if (np==NULL)
1634
1647
              tempP=NULL;
1635
1648
            else 
1636
 
              tempP=FindSOP(posPoint, np, hfirst, target, &scoreFlag);
 
1649
              tempP=FindSOP(posPoint, np, hfirst, target, tricks, &scoreFlag);
1637
1650
          }
1638
1651
 
1639
1652
          if (tempP!=NULL) {
1673
1686
      if (ready)
1674
1687
        InsertSort(movePly[depth].last+1, depth);
1675
1688
    }
1676
 
    /*#endif*/
1677
1689
   
1678
1690
    movePly[depth].current=0;
1679
1691
    if (nodeTypeStore[hand]==MAXNODE) {
1847
1859
  r=movePly[depth].current;
1848
1860
 
1849
1861
  if (posPoint->handRelFirst==3)  {         /* This hand is last hand */
1850
 
    mo1=movePly[depth].move[r];
1851
 
    mo2=posPoint->move[depth+1];
1852
 
    if (mo1.suit==mo2.suit) {
1853
 
      if (mo1.rank>mo2.rank) {
1854
 
          posPoint->move[depth]=mo1;
 
1862
        mo1=movePly[depth].move[r];
 
1863
        mo2=posPoint->move[depth+1];
 
1864
        if (mo1.suit==mo2.suit) {
 
1865
          if (mo1.rank>mo2.rank) {
 
1866
            posPoint->move[depth]=mo1;
1855
1867
        posPoint->high[depth]=handStore[firstHand][3];
1856
 
        }
1857
 
        else {
1858
 
        posPoint->move[depth]=posPoint->move[depth+1];
 
1868
          }
 
1869
          else {
 
1870
                posPoint->move[depth]=posPoint->move[depth+1];
1859
1871
        posPoint->high[depth]=posPoint->high[depth+1];
 
1872
          }
1860
1873
        }
1861
 
    }
1862
 
    else if (trumpContract && (mo1.suit==trump)) {
1863
 
      posPoint->move[depth]=mo1;
 
1874
        else if (trumpContract && (mo1.suit==trump)) {
 
1875
          posPoint->move[depth]=mo1;
1864
1876
      posPoint->high[depth]=handStore[firstHand][3];
1865
 
    }  
 
1877
        }  
1866
1878
    else {
1867
1879
      posPoint->move[depth]=posPoint->move[depth+1];
1868
1880
      posPoint->high[depth]=posPoint->high[depth+1];
1931
1943
      (~bitMapRank[w]);
1932
1944
  }
1933
1945
  else {
1934
 
    mo1=movePly[depth].move[r];
1935
 
    mo2=posPoint->move[depth+1];
1936
 
    if (mo1.suit==mo2.suit) {
1937
 
      if (mo1.rank>mo2.rank) {
1938
 
          posPoint->move[depth]=mo1;
 
1946
        mo1=movePly[depth].move[r];
 
1947
        mo2=posPoint->move[depth+1];
 
1948
        if (mo1.suit==mo2.suit) {
 
1949
          if (mo1.rank>mo2.rank) {
 
1950
            posPoint->move[depth]=mo1;
1939
1951
        posPoint->high[depth]=handStore[firstHand][posPoint->handRelFirst];
1940
 
        }
1941
 
        else {
1942
 
          posPoint->move[depth]=posPoint->move[depth+1];
 
1952
          }
 
1953
          else {
 
1954
                posPoint->move[depth]=posPoint->move[depth+1];
1943
1955
        posPoint->high[depth]=posPoint->high[depth+1];
 
1956
          }
1944
1957
        }
1945
 
    }
1946
 
    else if (trumpContract && (mo1.suit==trump)) {
1947
 
        posPoint->move[depth]=mo1;
 
1958
        else if (trumpContract && (mo1.suit==trump)) {
 
1959
          posPoint->move[depth]=mo1;
1948
1960
      posPoint->high[depth]=handStore[firstHand][posPoint->handRelFirst];
1949
 
    }  
 
1961
        }  
1950
1962
    else {
1951
1963
      posPoint->move[depth]=posPoint->move[depth+1];
1952
1964
      posPoint->high[depth]=posPoint->high[depth+1];
2272
2284
        goto L1;
2273
2285
      }
2274
2286
    }
2275
 
    else {
2276
 
        if (!opps && trumpContract && (suit==trump)) {
2277
 
          sum=Max(posPoint->length[hand][suit],
2278
 
            posPoint->length[partner[hand]][suit]);
2279
 
          if (nodeTypeStore[hand]==MAXNODE) {
 
2287
        else {
 
2288
          if (!opps && trumpContract && (suit==trump)) {
 
2289
            sum=Max(posPoint->length[hand][suit],
 
2290
                          posPoint->length[partner[hand]][suit]);
 
2291
                if (nodeTypeStore[hand]==MAXNODE) {
2280
2292
          if ((posPoint->tricksMAX+sum>=target)&&
2281
 
              (sum>0)&&(depth>0)&&(depth!=iniDepth)) {
2282
 
                quick.res=TRUE;
2283
 
                quick.quickTricks=sum;
2284
 
                return quick;
2285
 
            }
2286
 
          }
2287
 
          else {
2288
 
            if ((posPoint->tricksMAX+(depth>>2)+1-sum<target)&&
2289
 
            (sum>0)&&(depth>0)&&(depth!=iniDepth)) {
2290
 
                quick.res=TRUE;
2291
 
                quick.quickTricks=sum;
2292
 
                return quick;
2293
 
            }
2294
 
          }
2295
 
        }
2296
 
        if (commPartner) {
 
2293
                    (sum>0)&&(depth>0)&&(depth!=iniDepth)) {
 
2294
                        quick.res=TRUE;
 
2295
                        quick.quickTricks=sum;
 
2296
                        return quick;
 
2297
                  }
 
2298
                }
 
2299
                else {
 
2300
                  if ((posPoint->tricksMAX+(depth>>2)+1-sum<target)&&
 
2301
                    (sum>0)&&(depth>0)&&(depth!=iniDepth)){
 
2302
                        quick.res=TRUE;
 
2303
                        quick.quickTricks=sum;
 
2304
                        return quick;
 
2305
                  }
 
2306
                }
 
2307
          }
 
2308
          if (commPartner) {
2297
2309
        currHand=partner[hand];
2298
2310
            other=0;
2299
2311
            for (h=0; h<=3; h++) 
2342
2354
          }
2343
2355
        }
2344
2356
      }
2345
 
    }
 
2357
        }
2346
2358
    if (posPoint->winner[suit].hand==hand) {
2347
2359
      /* Winner found in own hand */
2348
2360
      countLho=posPoint->length[lho[hand]][suit];
2845
2857
  if ((!trumpContract)||(posPoint->winner[trump].rank==0)) {
2846
2858
    found=FALSE;
2847
2859
    for (ss=0; ss<=3; ss++) {
 
2860
          if (posPoint->winner[ss].rank==0)
 
2861
            continue;
2848
2862
      hh=posPoint->winner[ss].hand;
2849
2863
      if (nodeTypeStore[hh]==MAXNODE) {
2850
2864
        if (posPoint->length[hand][ss]>0) {
2852
2866
          break;
2853
2867
        }
2854
2868
      }
2855
 
      else if ((posPoint->length[partner[hand]][ss]>0)&&
2856
 
                  (posPoint->length[hand][ss]>0)&&  /* Own side cannot unblock */
2857
 
              (posPoint->length[partner[hh]][ss]>0))
2858
 
        count++; 
 
2869
          else if ((posPoint->length[partner[hand]][ss]>0)&&
 
2870
                        (posPoint->length[hand][ss]>0)&&
 
2871
                        (posPoint->length[partner[hh]][ss]>0)) 
 
2872
          count++;
2859
2873
    }
2860
2874
    if (!found) {
2861
2875
      if (((posPoint->tricksMAX+(depth>>2)-Max(0,count-1))<target)
2870
2884
        return FALSE;
2871
2885
      }
2872
2886
    }
2873
 
    else {
2874
 
      for (ss=0; ss<=3; ss++) {
2875
 
          hh=posPoint->winner[ss].hand;
2876
 
          if (nodeTypeStore[hh]==MAXNODE)
 
2887
        else {
 
2888
          for (ss=0; ss<=3; ss++) {
 
2889
                hh=posPoint->winner[ss].hand;
 
2890
                if (nodeTypeStore[hh]==MAXNODE)
2877
2891
          sum+=Max(posPoint->length[hh][ss], posPoint->length[partner[hh]][ss]);
2878
 
        }
2879
 
        if ((posPoint->tricksMAX+sum<target)&&
2880
 
          (sum>0)&&(depth>0)&&(depth!=iniDepth)) {
 
2892
          }
 
2893
          if ((posPoint->tricksMAX+sum<target)&&
 
2894
                  (sum>0)&&(depth>0)&&(depth!=iniDepth)) {
2881
2895
            if ((posPoint->tricksMAX+(depth>>2)<target)) {
2882
2896
              for (ss=0; ss<=3; ss++) {
2883
2897
            if (nodeTypeStore[posPoint->winner[ss].hand]==MINNODE)  
2884
2898
              posPoint->winRanks[depth][ss]=bitMapRank[posPoint->winner[ss].rank];
2885
2899
            else
2886
2900
              posPoint->winRanks[depth][ss]=0;
2887
 
            }
2888
 
            return FALSE;
 
2901
                  }
 
2902
                  return FALSE;
2889
2903
        }
2890
2904
      }
2891
 
    } 
 
2905
        } 
2892
2906
  }
2893
2907
  else if ((posPoint->winner[trump].rank!=0) && 
2894
2908
    (nodeTypeStore[posPoint->winner[trump].hand]==MINNODE)) {
2895
2909
    if ((posPoint->length[hand][trump]==0)&&
2896
2910
      (posPoint->length[partner[hand]][trump]==0)) {
2897
 
      if (((posPoint->tricksMAX+(depth>>2)+1-Max(posPoint->length[lho[hand]][trump],
2898
 
        posPoint->length[rho[hand]][trump]))<target)
 
2911
          if (((posPoint->tricksMAX+(depth>>2)+1-
 
2912
                  Max(posPoint->length[lho[hand]][trump],
 
2913
                posPoint->length[rho[hand]][trump]))<target)
2899
2914
        &&(depth>0)&&(depth!=iniDepth)) {
2900
2915
        for (ss=0; ss<=3; ss++)
2901
2916
          posPoint->winRanks[depth][ss]=0;
2902
 
          return FALSE;
2903
 
      }
 
2917
            return FALSE;
 
2918
          }
2904
2919
    }    
2905
2920
    else if (((posPoint->tricksMAX+(depth>>2))<target)&&
2906
2921
      (depth>0)&&(depth!=iniDepth)) {
2923
2938
              bitMapRank[posPoint->secondBest[trump].rank] ;
2924
2939
            return FALSE;
2925
2940
        }
2926
 
        }
 
2941
          }
2927
2942
    }   
2928
2943
  }
2929
2944
  else {
2941
2956
        return FALSE;
2942
2957
      }
2943
2958
    }
2944
 
    /*found=FALSE;
2945
 
    for (ss=0; ss<=3; ss++) {
2946
 
        if ((ss!=trump)&&(posPoint->winner[ss].rank!=0)) {
2947
 
          hh=posPoint->winner[ss].hand;
2948
 
        if ((nodeTypeStore[hh]==MAXNODE)||
 
2959
        /*found=FALSE;
 
2960
        for (ss=0; ss<=3; ss++) {
 
2961
          if ((ss!=trump)&&(posPoint->winner[ss].rank!=0)) {
 
2962
            hh=posPoint->winner[ss].hand;
 
2963
                if ((nodeTypeStore[hh]==MAXNODE)||
2949
2964
          (posPoint->length[hand][ss]==0)||
2950
2965
          (posPoint->length[partner[hand]][ss]==0)) {
2951
 
            found=TRUE;
2952
 
            break;
 
2966
                  found=TRUE;
 
2967
                  break;
 
2968
                }
2953
2969
          }
2954
2970
        }
2955
 
    }
2956
 
    if (!found) {
2957
 
        sum=Max(posPoint->length[hand][trump], 
2958
 
          posPoint->length[partner[hand]][trump]);
2959
 
        if ((posPoint->tricksMAX+sum<target)&&(sum>0)
2960
 
          &&(depth>0)&&(depth!=iniDepth)) {
2961
 
          if (posPoint->tricksMAX+(depth>>2)<target) {
 
2971
        if (!found) {
 
2972
          sum=Max(posPoint->length[hand][trump], 
 
2973
                  posPoint->length[partner[hand]][trump]);
 
2974
          if ((posPoint->tricksMAX+sum<target)&&(sum>0)
 
2975
                &&(depth>0)&&(depth!=iniDepth)) {
 
2976
            if (posPoint->tricksMAX+(depth>>2)<target) {
2962
2977
          for (ss=0; ss<=3; ss++) {
2963
2978
            if (ss!=trump) {
2964
2979
              if (nodeTypeStore[posPoint->winner[ss].hand]==MINNODE)  
2965
2980
                posPoint->winRanks[depth][ss]=bitMapRank[posPoint->winner[ss].rank];
2966
2981
              else
2967
2982
                posPoint->winRanks[depth][ss]=0;
2968
 
                }
2969
 
                else
2970
 
                  posPoint->winRanks[depth][ss]=0;
 
2983
                        }
 
2984
                        else
 
2985
                          posPoint->winRanks[depth][ss]=0;
2971
2986
          }
2972
2987
          return FALSE;
2973
2988
        }
2974
 
        }
2975
 
    }*/
 
2989
          }
 
2990
        }*/
2976
2991
  }
2977
2992
  return TRUE;
2978
2993
}
2982
2997
  if ((!trumpContract)||(posPoint->winner[trump].rank==0)) {
2983
2998
    found=FALSE;
2984
2999
    for (ss=0; ss<=3; ss++) {
 
3000
          if (posPoint->winner[ss].rank==0)
 
3001
            continue;
2985
3002
      hh=posPoint->winner[ss].hand;
2986
3003
      if (nodeTypeStore[hh]==MINNODE) {
2987
3004
        if (posPoint->length[hand][ss]>0) {
2989
3006
          break;
2990
3007
        }
2991
3008
      }
2992
 
      else if ((posPoint->length[partner[hand]][ss]>0)&&
2993
 
                  (posPoint->length[hand][ss]>0)&&
2994
 
                  (posPoint->length[partner[hh]][ss]>0)) 
2995
 
        count++; 
 
3009
          else if ((posPoint->length[partner[hand]][ss]>0)&&
 
3010
                        (posPoint->length[hand][ss]>0)&&
 
3011
                        (posPoint->length[partner[hh]][ss]>0)) 
 
3012
          count++;
2996
3013
    }
2997
3014
    if (!found) {
2998
3015
      if (((posPoint->tricksMAX+1+Max(0,count-1))>=target)
3007
3024
        return TRUE;
3008
3025
      }
3009
3026
    }
3010
 
    else {
3011
 
      for (ss=0; ss<=3; ss++) {
3012
 
          hh=posPoint->winner[ss].hand;
3013
 
          if (nodeTypeStore[hh]==MINNODE)
 
3027
        else {
 
3028
          for (ss=0; ss<=3; ss++) {
 
3029
                hh=posPoint->winner[ss].hand;
 
3030
                if (nodeTypeStore[hh]==MINNODE)
3014
3031
          sum+=Max(posPoint->length[hh][ss], posPoint->length[partner[hh]][ss]);
3015
 
        }
3016
 
        if ((posPoint->tricksMAX+(depth>>2)+1-sum>=target)&&
3017
 
          (sum>0)&&(depth>0)&&(depth!=iniDepth)) {
3018
 
          if ((posPoint->tricksMAX+1>=target)) {
3019
 
            for (ss=0; ss<=3; ss++) {
 
3032
          }
 
3033
          if ((posPoint->tricksMAX+(depth>>2)+1-sum>=target)&&
 
3034
                  (sum>0)&&(depth>0)&&(depth!=iniDepth)) {
 
3035
            if ((posPoint->tricksMAX+1>=target)) {
 
3036
              for (ss=0; ss<=3; ss++) {
3020
3037
            if (nodeTypeStore[posPoint->winner[ss].hand]==MAXNODE)  
3021
3038
              posPoint->winRanks[depth][ss]=bitMapRank[posPoint->winner[ss].rank];
3022
3039
            else
3023
3040
              posPoint->winRanks[depth][ss]=0;
3024
 
            }
3025
 
            return TRUE;
 
3041
                  }
 
3042
                  return TRUE;
3026
3043
        }
3027
3044
      }
3028
 
    } 
 
3045
        } 
3029
3046
  }
3030
3047
  else if ((posPoint->winner[trump].rank!=0) &&
3031
3048
    (nodeTypeStore[posPoint->winner[trump].hand]==MAXNODE)) {
3059
3076
              bitMapRank[posPoint->winner[trump].rank] | 
3060
3077
            bitMapRank[posPoint->secondBest[trump].rank] ;
3061
3078
              return TRUE;
3062
 
          }
 
3079
            }
3063
3080
      }
3064
3081
    }
3065
3082
  }
3076
3093
        return TRUE;
3077
3094
      }
3078
3095
    }
3079
 
    /*found=FALSE;
3080
 
    for (ss=0; ss<=3; ss++) {
3081
 
        if ((ss!=trump)&&(posPoint->winner[ss].rank!=0)) {
3082
 
          hh=posPoint->winner[ss].hand;
3083
 
          if ((nodeTypeStore[hh]==MINNODE)||
 
3096
        /*found=FALSE;
 
3097
        for (ss=0; ss<=3; ss++) {
 
3098
          if ((ss!=trump)&&(posPoint->winner[ss].rank!=0)) {
 
3099
            hh=posPoint->winner[ss].hand;
 
3100
                if ((nodeTypeStore[hh]==MINNODE)||
3084
3101
          (posPoint->length[hand][ss]==0)||
3085
3102
          (posPoint->length[partner[hand]][ss]==0)) {
3086
 
            found=TRUE;
3087
 
            break;
 
3103
                  found=TRUE;
 
3104
                  break;
 
3105
                }
3088
3106
          }
3089
3107
        }
3090
 
    }
3091
 
    if (!found) {
3092
 
        sum=Max(posPoint->length[hand][trump], 
3093
 
          posPoint->length[partner[hand]][trump]);
3094
 
        if ((posPoint->tricksMAX+(depth>>2)+1-sum>=target)&&
3095
 
          (depth>0)&&(depth!=iniDepth)) {
3096
 
          if ((posPoint->tricksMAX+1>=target)&&(sum>0)) {
 
3108
        if (!found) {
 
3109
          sum=Max(posPoint->length[hand][trump], 
 
3110
                  posPoint->length[partner[hand]][trump]);
 
3111
          if ((posPoint->tricksMAX+(depth>>2)+1-sum>=target)&&
 
3112
            (depth>0)&&(depth!=iniDepth)) {
 
3113
            if ((posPoint->tricksMAX+1>=target)&&(sum>0)) {
3097
3114
          for (ss=0; ss<=3; ss++) {
3098
 
                if (ss!=trump) {
 
3115
                        if (ss!=trump) {
3099
3116
              if (nodeTypeStore[posPoint->winner[ss].hand]==MAXNODE)  
3100
3117
                posPoint->winRanks[depth][ss]=bitMapRank[posPoint->winner[ss].rank];
3101
3118
              else
3102
3119
                posPoint->winRanks[depth][ss]=0;
3103
 
                }
3104
 
                else
3105
 
                  posPoint->winRanks[depth][ss]=0;
 
3120
                        }
 
3121
                        else
 
3122
                          posPoint->winRanks[depth][ss]=0;
3106
3123
          }
3107
3124
          return TRUE;
3108
3125
        }
3109
 
        }
3110
 
    }*/
 
3126
          }
 
3127
        }*/
3111
3128
  }
3112
3129
  return FALSE;
3113
3130
}
3346
3363
        }
3347
3364
              
3348
3365
      if (winMove) {
3349
 
          if (((posPoint->winner[suit].hand==lho[first])&&(suitCountLH==1))
 
3366
                if (((posPoint->winner[suit].hand==lho[first])&&(suitCountLH==1))
3350
3367
          ||((posPoint->winner[suit].hand==rho[first])&&(suitCountRH==1)))
3351
3368
          weight=suitWeightDelta+40-(mp->rank);
3352
3369
        else if (posPoint->winner[suit].hand==first) {
3525
3542
                                    than the highest rank of the leading hand, then
3526
3543
                                    lho playing the lowest card will be the cheapest
3527
3544
                                    win */
3528
 
          else if (mp->rank > posPoint->move[depth+1].rank) {
 
3545
                else if (mp->rank > posPoint->move[depth+1].rank) {
3529
3546
          if (bitMapRank[mp->rank] < ll) 
3530
3547
            weight=75-(mp->rank);  /* If played card is lower than any of the cards of
3531
3548
                                                rho, it will be the cheapest win */
3532
3549
          else if (bitMapRank[mp->rank] > kk)
3533
3550
            weight=70-(mp->rank);  /* If played card is higher than any cards at partner
3534
 
                                                of the leading hand */ 
 
3551
                                                of the leading hand, rho can play low, under the
 
3552
                                    condition that he has a lower card than lho played */ 
3535
3553
          else {
3536
3554
            if (mp->sequence)
3537
3555
              weight=60-(mp->rank); 
3550
3568
      }
3551
3569
      else {
3552
3570
        if (!notVoidInSuit) {
3553
 
          if (trumpContract && (suit==trump))     
3554
 
            weight=15-(mp->rank)+suitAdd;  /* Ruffing is preferred, makes the trick
 
3571
                  if (trumpContract && (suit==trump)) {
 
3572
                    /*if (ll > bitMapRank[posPoint->move[depth+1].rank])
 
3573
                          weight=-10-(mp->rank)+suitAdd;
 
3574
                        else*/
 
3575
              weight=15-(mp->rank)+suitAdd;  /* Ruffing is preferred, makes the trick
3555
3576
                                                          costly for the opponents */
 
3577
                  }
3556
3578
          else
3557
3579
            weight=-(mp->rank)+suitAdd;
3558
3580
        }
3619
3641
          if (posPoint->high[depth+1]==first) {
3620
3642
            if (trumpContract && (suit==trump)) 
3621
3643
              weight=30-(mp->rank)+suitAdd; /* Ruffs partner's winner */
3622
 
            else
 
3644
            /*else if ((posPoint->length[partner[first]][suit]==1)&&
 
3645
                          (bitMapRank[mp->suit]>posPoint->rankInSuit[first][suit])&&
 
3646
                          (posPoint->rankInSuit[first][suit]>
 
3647
                           (posPoint->rankInSuit[lho[first]][suit] |
 
3648
                           posPoint->rankInSuit[rho[first]][suit])))
 
3649
                          weight=90-(mp->rank)+suitAdd;*/
 
3650
                        else
3623
3651
              weight=60-(mp->rank)+suitAdd;
3624
3652
          } 
3625
3653
          else if (WinningMove(mp, &(posPoint->move[depth+1])))
3896
3924
 
3897
3925
 
3898
3926
struct nodeCardsType * CheckSOP(struct pos * posPoint, struct nodeCardsType
3899
 
  * nodep, int first, int target, int * result, int *value) {
 
3927
  * nodep, int first, int target, int tricks, int * result, int *value) {
3900
3928
    /* Check SOP if it matches the
3901
3929
    current position. If match, pointer to the SOP node is returned and
3902
3930
    result is set to TRUE, otherwise pointer to SOP node is returned
3903
3931
    and result set to FALSE. */
3904
3932
 
3905
 
  if (nodep->lbound[first]==-1) {  /* This bound values for
3906
 
    this leading hand has not yet been determined */
3907
 
    *result=FALSE;
3908
 
    return nodep;
3909
 
  }     
3910
 
  else if ((posPoint->tricksMAX + nodep->lbound[first])>=target) {
3911
 
          *value=TRUE;
3912
 
          *result=TRUE;
3913
 
          return nodep;
3914
 
  }
3915
 
  else if ((posPoint->tricksMAX + nodep->ubound[first])<target) {
3916
 
          *value=FALSE;
3917
 
          *result=TRUE;
3918
 
          return nodep;
3919
 
  }
 
3933
  /* 07-04-22 */ 
 
3934
  if (nodeTypeStore[0]==MAXNODE) {
 
3935
    if (nodep->lbound[first]==-1) {  /* This bound values for
 
3936
      this leading hand has not yet been determined */
 
3937
      *result=FALSE;
 
3938
      return nodep;
 
3939
    }   
 
3940
    else if ((posPoint->tricksMAX + nodep->lbound[first])>=target) {
 
3941
            *value=TRUE;
 
3942
            *result=TRUE;
 
3943
            return nodep;
 
3944
    }
 
3945
    else if ((posPoint->tricksMAX + nodep->ubound[first])<target) {
 
3946
          *value=FALSE;
 
3947
          *result=TRUE;
 
3948
          return nodep;
 
3949
        }
 
3950
  }
 
3951
  else {
 
3952
    if (nodep->ubound[first]==-1) {  /* This bound values for
 
3953
      this leading hand has not yet been determined */
 
3954
      *result=FALSE;
 
3955
      return nodep;
 
3956
    }   
 
3957
    else if ((posPoint->tricksMAX + (tricks + 1 - nodep->ubound[first]))>=target) {
 
3958
            *value=TRUE;
 
3959
            *result=TRUE;
 
3960
            return nodep;
 
3961
    }
 
3962
    else if ((posPoint->tricksMAX + (tricks + 1 - nodep->lbound[first]))<target) {
 
3963
          *value=FALSE;
 
3964
          *result=TRUE;
 
3965
          return nodep;
 
3966
        }
 
3967
  }
 
3968
 
3920
3969
  *result=FALSE;
3921
3970
  return nodep;          /* No matching node was found */
3922
3971
}
3940
3989
 
3941
3990
struct nodeCardsType * FindSOP(struct pos * posPoint,
3942
3991
  struct winCardType * nodeP, int firstHand, 
3943
 
        int target, int * valp) {
 
3992
        int target, int tricks, int * valp) {
3944
3993
  struct nodeCardsType * sopP, * first;
3945
3994
  struct winCardType * np;
3946
3995
        
3951
4000
        /* Winning card fits position */
3952
4001
        first=np->first;
3953
4002
        if (first!=NULL) {
3954
 
          sopP=CheckSOP(posPoint, first, firstHand, target, &res, &val);
 
4003
          sopP=CheckSOP(posPoint, first, firstHand, target, tricks, &res, &val);
3955
4004
          *valp=val;
3956
4005
          if (res)
3957
4006
            return sopP;
4312
4361
              break;
4313
4362
            }
4314
4363
  orderTable.last=cind;
 
4364
  
 
4365
  /* 07-04-22 */
4315
4366
  if (scoreFlag) {
4316
 
    posPoint->ubound=tricks+1;
4317
 
    posPoint->lbound=target-posPoint->tricksMAX;
 
4367
    if (nodeTypeStore[0]==MAXNODE) {
 
4368
      posPoint->ubound=tricks+1;
 
4369
      posPoint->lbound=target-posPoint->tricksMAX;
 
4370
    }
 
4371
    else {
 
4372
        posPoint->ubound=tricks+1-target+posPoint->tricksMAX;
 
4373
        posPoint->lbound=0;
 
4374
    }
4318
4375
  }
4319
4376
  else {
4320
 
    posPoint->ubound=target-posPoint->tricksMAX-1;
4321
 
    posPoint->lbound=0;
 
4377
    if (nodeTypeStore[0]==MAXNODE) {
 
4378
      posPoint->ubound=target-posPoint->tricksMAX-1;
 
4379
      posPoint->lbound=0;
 
4380
    }
 
4381
    else {
 
4382
        posPoint->ubound=tricks+1;
 
4383
      posPoint->lbound=tricks+1-target+posPoint->tricksMAX+1;
 
4384
    }
4322
4385
  }     
4323
4386
 
4324
4387
  suitLengths=0; 
4325
4388
  for (ss=0; ss<=2; ss++)
4326
4389
    for (hh=0; hh<=3; hh++) {
4327
 
          suitLengths=suitLengths<<4;
4328
 
          suitLengths|=posPoint->length[hh][ss];
4329
 
        }
 
4390
        suitLengths=suitLengths<<4;
 
4391
        suitLengths|=posPoint->length[hh][ss];
 
4392
    }
4330
4393
  
4331
4394
  np=SearchAndInsert(rootnp[tricks], suitLengths, TRUE, &res);
4332
4395