Skip to content

Commit

Permalink
historical commit dds 2.4.2
Browse files Browse the repository at this point in the history
  • Loading branch information
bohag authored and hostilefork committed Nov 25, 2014
1 parent 0615820 commit 4c34c7a
Show file tree
Hide file tree
Showing 7 changed files with 551 additions and 188 deletions.
281 changes: 155 additions & 126 deletions DLL-dds_241_r.rtf → DLL-dds_242_s.rtf

Large diffs are not rendered by default.

340 changes: 340 additions & 0 deletions DLL-dds_242_s.txt

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CFLAGS=-g -Wall -O2
CFLAGS=-g -Wall -O2 -std=c99 -fopenmp
PREFIX=/usr/local

all: libdds.a python
Expand Down
101 changes: 44 additions & 57 deletions dds.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

/* DDS 2.4.1 A bridge double dummy solver. */
/* DDS 2.4.2 A bridge double dummy solver. */
/* Copyright (C) 2006-2014 by Bo Haglund */
/* Cleanups and porting to Linux and MacOSX (C) 2006 by Alex Martelli. */
/* The code for calculation of par score / contracts is based upon the */
Expand Down Expand Up @@ -6054,40 +6054,39 @@ int STDCALL CalcAllTables(struct ddTableDeals *dealsp, int mode, int trumpFilter
lastBoardIndex[MAXNOOFBOARDS>>2], okey=FALSE, count=0;
struct boards bo;
struct solvedBoards solved;
int tables;

int Par(struct ddTableResults * tablep, struct parResults *presp, int vulnerable);

for (k=0; k<5; k++) {
if (!trumpFilter[k]) {
okey=TRUE;
count++;
count++;
}
}

if (!okey)
return -201;

switch (count) {
case 1: tables=50; break;
case 2: tables=25; break;
case 3: tables=16; break;
case 4: tables=12; break;
case 5: tables=10; break;
default: tables=10;
case 1: if (dealsp->noOfTables > 50) return 202; break;
case 2: if (dealsp->noOfTables > 25) return 202; break;
case 3: if (dealsp->noOfTables > 16) return 202; break;
case 4: if (dealsp->noOfTables > 12) return 202; break;
case 5: if (dealsp->noOfTables > 10) return 202; break;
}

ind=0;
ind=0;
resp->noOfBoards=0;

for (m=0; m<tables; m++) {
for (m=0; m<dealsp->noOfTables; m++) {
for (tr=4; tr>=0; tr--) {
if (!trumpFilter[tr]) {
for (first=0; first<=3; first++) {
for (h=0; h<=3; h++)
for (s=0; s<=3; s++)
bo.deals[ind].remainCards[h][s]=dealsp->deals[m].cards[h][s];
bo.deals[ind].first=first;
bo.deals[ind].trump=tr;
bo.deals[ind].first=first;
bo.deals[ind].trump=tr;
for (k=0; k<=2; k++) {
bo.deals[ind].currentTrickRank[k]=0;
bo.deals[ind].currentTrickSuit[k]=0;
Expand All @@ -6099,7 +6098,7 @@ int STDCALL CalcAllTables(struct ddTableDeals *dealsp, int mode, int trumpFilter
lastIndex=ind;
lastBoardIndex[m]=ind;
ind++;
}
}
}
}
}
Expand All @@ -6108,23 +6107,23 @@ int STDCALL CalcAllTables(struct ddTableDeals *dealsp, int mode, int trumpFilter

res=SolveAllBoards4(&bo, &solved);
if (res==1) {
resp->noOfBoards+=solved.noOfBoards;
for (ind=0; ind<=lastIndex; ind++) {
for (k=0; k<=lastIndex; k++) {
if (ind<=lastBoardIndex[k]) {
resp->results[k].resTable[bo.deals[ind].trump][rho[bo.deals[ind].first]]=
13-solved.solvedBoard[ind].score[0];
13-solved.solvedBoard[ind].score[0];
break;
}
}
}

if ((mode > -1) && (mode < 4)) {
/* Calculate par */
for (k=0; k<tables; k++) {
rs=Par(&(resp->results[k]), &(presp->presults[k]), mode);
/* vulnerable 0: None 1: Both 2: NS 3: EW */

if (rs!=1)
for (k=0; k<dealsp->noOfTables; k++) {
rs=Par(&(resp->results[k]), &(presp->presults[k]), mode);
/* vulnerable 0: None 1: Both 2: NS 3: EW */
if (rs!=1)
return rs;
}
}
Expand All @@ -6137,34 +6136,21 @@ int STDCALL CalcAllTablesPBN(struct ddTableDealsPBN *dealsp, int mode, int trump
struct ddTablesRes *resp, struct allParResults *presp) {
int res, k;
struct ddTableDeals dls;
int tables, count=0;

int ConvertFromPBN(char * dealBuff, unsigned int remainCards[4][4]);

for (k=0; k<5; k++) {
if (!trumpFilter[k]) {
count++;
}
}

switch (count) {
case 1: tables=50; break;
case 2: tables=25; break;
case 3: tables=16; break;
case 4: tables=12; break;
case 5: tables=10; break;
default: tables=10;
}

for (k=0; k<tables; k++)
for (k=0; k<dealsp->noOfTables; k++)
if (ConvertFromPBN(dealsp->deals[k].cards, dls.deals[k].cards)!=1)
return -99;

dls.noOfTables=dealsp->noOfTables;

res=CalcAllTables(&dls, mode, trumpFilter, resp, presp);

return res;
}


int ConvertFromPBN(char * dealBuff, unsigned int remainCards[4][4]) {
int bp=0, first, card, hand, handRelFirst, suitInHand, h, s;
int IsCard(char cardChar);
Expand Down Expand Up @@ -6240,6 +6226,7 @@ int ConvertFromPBN(char * dealBuff, unsigned int remainCards[4][4]) {
return 1;
}


int IsCard(char cardChar) {
switch (cardChar) {
case '2':
Expand Down Expand Up @@ -6336,7 +6323,7 @@ int STDCALL SolveAllBoards(struct boardsPBN *bop, struct solvedBoards *solvedp)
bo.deals[k].currentTrickRank[i]=bop->deals[k].currentTrickRank[i];
}
if (ConvertFromPBN(bop->deals[k].remainCards, bo.deals[k].remainCards)!=1)
return -99;
return -99;
}

res=SolveAllBoards1(&bo, solvedp);
Expand Down Expand Up @@ -6572,7 +6559,8 @@ int Par(struct ddTableResults * tablep, struct parResults *presp, int vulnerable
tt = (t1 > t2) ? t1 : t2;

tu_max=0;
for (m=4; m>=0; m--) {

for (m=0; m<=4; m++) {
t3 = ((dr+i) % 2 == 0) ? tablep->resTable[denom_conv[m]][0] : tablep->resTable[denom_conv[m]][1];
t4 = ((dr+i) % 2 == 0) ? tablep->resTable[denom_conv[m]][2] : tablep->resTable[denom_conv[m]][3];
tu = (t3 > t4) ? t3 : t4;
Expand Down Expand Up @@ -6641,9 +6629,9 @@ int Par(struct ddTableResults * tablep, struct parResults *presp, int vulnerable
strcat(presp->parContractsString[i], buff);

if (denom_max < par_denom[i])
max_lower = par_tricks[i] - tu_max - 1/*2*/;
max_lower = par_tricks[i] - tu_max - 1;
else
max_lower = par_tricks[i] - tu_max /*- 1*/;
max_lower = par_tricks[i] - tu_max;

/* max_lower is the maximal contract lowering, otherwise opponent contract is
higher. It is already known that par_score is high enough to make
Expand All @@ -6659,7 +6647,6 @@ int Par(struct ddTableResults * tablep, struct parResults *presp, int vulnerable
else
sc1 = -rawscore(-1, par_tricks[i] - max_lower - tu_max + 1, isvul);
/* Score for undertricks needed to beat the tentative lower par contract.*/
/*sc2 = rawscore(par_denom[i], par_tricks[i] - max_lower, isvul);*/
if (sc2 < sc1)
break;
else
Expand Down Expand Up @@ -6732,7 +6719,7 @@ int Par(struct ddTableResults * tablep, struct parResults *presp, int vulnerable

tu_max=0;

for (m=4; m>=0; m--) {
for (m=0; m<=4; m++) {
t3 = ((dr+i) % 2 == 0) ? tablep->resTable[denom_conv[m]][0] : tablep->resTable[denom_conv[m]][1];
t4 = ((dr+i) % 2 == 0) ? tablep->resTable[denom_conv[m]][2] : tablep->resTable[denom_conv[m]][3];
tu = (t3 > t4) ? t3 : t4;
Expand All @@ -6747,10 +6734,10 @@ int Par(struct ddTableResults * tablep, struct parResults *presp, int vulnerable

strcat(presp->parContractsString[i], buff);

if (denom_max < par_denom[i])
max_lower = 9 - tu_max - 1/*2*/;
if (denom_max < j)
max_lower = 9 - tu_max - 1;
else
max_lower = 9 - tu_max /*- 1*/;
max_lower = 9 - tu_max;

/* max_lower is the maximal contract lowering, otherwise opponent contract is
higher. It is already known that par_score is high enough to make
Expand All @@ -6761,12 +6748,11 @@ int Par(struct ddTableResults * tablep, struct parResults *presp, int vulnerable
sc2 = rawscore(par_denom[i], par_tricks[i], isvul);
/* Score for making the tentative lower par contract. */
while (max_lower > 0) {
if (denom_max < par_denom[i])
sc1 = -rawscore(-1, par_tricks[i] - max_lower - tu_max, isvul);
if (denom_max < j)
sc1 = -rawscore(-1, 9/*par_tricks[i] + 1*/ - max_lower - tu_max, isvul);
else
sc1 = -rawscore(-1, par_tricks[i] - max_lower - tu_max + 1, isvul);
sc1 = -rawscore(-1, 9 - max_lower - tu_max + 1, isvul);
/* Score for undertricks needed to beat the tentative lower par contract.*/
/* sc2 = rawscore(par_denom[i], par_tricks[i] - max_lower, isvul);*/
if (sc2 < sc1)
break;
else
Expand Down Expand Up @@ -6808,7 +6794,8 @@ int Par(struct ddTableResults * tablep, struct parResults *presp, int vulnerable
IniSidesString(dr, i, t1, t2, buff);

tu_max=0;
for (m=4; m>=0; m--) {
/*for (m=4; m>=0; m--) {*/
for (m=0; m<=4; m++) {
t3 = ((dr+i) % 2 == 0) ? tablep->resTable[denom_conv[m]][0] : tablep->resTable[denom_conv[m]][1];
t4 = ((dr+i) % 2 == 0) ? tablep->resTable[denom_conv[m]][2] : tablep->resTable[denom_conv[m]][3];
tu = (t3 > t4) ? t3 : t4;
Expand All @@ -6823,10 +6810,10 @@ int Par(struct ddTableResults * tablep, struct parResults *presp, int vulnerable

strcat(presp->parContractsString[i], buff);

if (denom_max < par_denom[i])
max_lower = 8 - tu_max - 1/*2*/;
if (denom_max < j)
max_lower = 8 - tu_max - 1;
else
max_lower = 8 - tu_max /*- 1*/;
max_lower = 8 - tu_max;

/* max_lower is the maximal contract lowering, otherwise opponent contract is
higher. It is already known that par_score is high enough to make
Expand All @@ -6837,10 +6824,10 @@ int Par(struct ddTableResults * tablep, struct parResults *presp, int vulnerable
sc2 = rawscore(par_denom[i], par_tricks[i], isvul);
/* Score for making the tentative lower par contract. */
while (max_lower > 0) {
if (denom_max < par_denom[i])
sc1 = -rawscore(-1, par_tricks[i] - max_lower - tu_max, isvul);
if (denom_max < j)
sc1 = -rawscore(-1, 8 - max_lower - tu_max, isvul);
else
sc1 = -rawscore(-1, par_tricks[i] - max_lower - tu_max + 1, isvul);
sc1 = -rawscore(-1, 8 - max_lower - tu_max + 1, isvul);
/* Score for undertricks needed to beat the tentative lower par contract.*/

if (sc2 < sc1)
Expand Down
5 changes: 4 additions & 1 deletion dll.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

/* end of portability-macros section */

#define DDS_VERSION 20401 /* Version 2.4.1. Allowing for 2 digit
#define DDS_VERSION 20402 /* Version 2.4.2. Allowing for 2 digit
minor versions */

#define PBN
Expand Down Expand Up @@ -298,6 +298,7 @@ struct ddTableDeal {
};

struct ddTableDeals {
int noOfTables;
struct ddTableDeal deals[MAXNOOFBOARDS>>2];
};

Expand All @@ -306,6 +307,7 @@ struct ddTableDealPBN {
};

struct ddTableDealsPBN {
int noOfTables;
struct ddTableDealPBN deals[MAXNOOFBOARDS>>2];
};

Expand All @@ -314,6 +316,7 @@ struct ddTableResults {
};

struct ddTablesRes {
int noOfBoards;
struct ddTableResults results[MAXNOOFBOARDS>>2];
};

Expand Down
4 changes: 2 additions & 2 deletions readme.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
DDS 2.4.0, Bo Haglund 2014-01-09
DDS 2.4.2, Bo Haglund 2014-01-09

For Win32, DDS compiles with Visual C++ 2010 and 2012 Express editions
and the TDM-GCC/Mingw port of gcc.
Expand Down Expand Up @@ -54,7 +54,7 @@ The possible configurens thus are:
2) "PBN": Support for SolveBoardPBN and CalcDDtablePBN.
3) None of these definitions: No support for any of the above 3 functions.

Staying with the previous configuration might be needed when 2.4.0 is to replace an
Staying with the previous configuration might be needed when 2.4.2 is to replace an
older 2.x.y version, and the application using DDS cannot handle a changed interface.


Expand Down
6 changes: 5 additions & 1 deletion release_notes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -426,5 +426,9 @@ For Windows users, adding readable version information of the DDS DLL file.

Release Notes DDS 2.4.1
-----------------------
Updates of functions CalcAllTables and CalcAllTablesPBN for improved performance.
Updates of functions CalcAllTables and CalcAllTablesPBN for improved performance.


Release Notes DDS 2.4.2
-----------------------
Fixing bugs in CalcAllTables, CalcAllTablesPBN and CalcPar.

0 comments on commit 4c34c7a

Please sign in to comment.