summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoremkael <emkael@tlen.pl>2016-06-03 14:02:45 +0200
committeremkael <emkael@tlen.pl>2016-06-03 14:02:45 +0200
commitdfe4c3b00198172c0f4bee6b26ce3962c69e4ccd (patch)
treee9fcc3567f12df3fbe970d0b601649788ab08418 /src
parent734b29bb02802fd5a03359a1e77aff2c8f28fe9a (diff)
* lowest from equal contracts as par contract
Diffstat (limited to 'src')
-rw-r--r--src/ParScore.cs47
1 files changed, 42 insertions, 5 deletions
diff --git a/src/ParScore.cs b/src/ParScore.cs
index 5032ea1..068be90 100644
--- a/src/ParScore.cs
+++ b/src/ParScore.cs
@@ -123,11 +123,13 @@ namespace BCDD
return nsPlaying ? nsHighest.Validate() : ewHighest.Validate();
}
ParContract highest = nsHighest.Higher(ewHighest) ? nsHighest : ewHighest;
+ ParContract otherSideHighest = nsHighest.Higher(ewHighest) ? ewHighest : nsHighest;
nsPlaying = ('N'.Equals(highest.Declarer) || 'S'.Equals(highest.Declarer));
bool defenseVulnerability = this.determineVulnerability(vulnerability, nsPlaying ? 'E' : 'N');
ParContract highestDefense = highest.GetDefense(ddTable, defenseVulnerability);
if (highestDefense != null)
{
+ // Highest contract has profitable defense
return highestDefense.Validate();
}
int denominationIndex = Array.IndexOf(BCalcWrapper.DENOMINATIONS, highest.Denomination);
@@ -151,13 +153,36 @@ namespace BCDD
{
ParContract contract = new ParContract(level, BCalcWrapper.DENOMINATIONS[i], BCalcWrapper.PLAYERS[player], false, 0);
contract.Score = contract.CalculateScore(ddTable[player, i], vulnerable);
- if (scoreSquared < contract.Score * highest.Score)
+ if (otherSideHighest.Higher(contract))
{
- possibleOptimums.Add(contract.GetDefense(ddTable, defenseVulnerability) ?? contract);
+ // Contract is lower than other side's contract
+ break;
}
- else
+ if (highest.Score * contract.Score > 0)
{
- break;
+ // Contract makes
+ if (Math.Abs(contract.Score) >= Math.Abs(highest.Score))
+ {
+ // Contract is profitable
+ ParContract defense = contract.GetDefense(ddTable, defenseVulnerability);
+ if (defense != null && (contract.Score * contract.Score > contract.Score * defense.Score))
+ {
+ // Contract has defense
+ possibleOptimums.Add(defense);
+ // So lower contracts will too.
+ break;
+ }
+ else
+ {
+ // Contract does not have defense
+ possibleOptimums.Add(contract);
+ }
+ }
+ else
+ {
+ // Contract is not profitable
+ break;
+ }
}
level--;
}
@@ -165,10 +190,22 @@ namespace BCDD
}
foreach (ParContract contract in possibleOptimums)
{
- if (Math.Abs(contract.Score) > Math.Abs(highest.Score) || (contract.Score == highest.Score && contract.Higher(highest)))
+ if ((Math.Abs(contract.Score) > Math.Abs(highest.Score)))
{
+ // Contract is more profitable
highest = contract;
}
+ else
+ {
+ if (contract.Score == highest.Score)
+ {
+ if (highest.Higher(contract))
+ {
+ // Equally profitable, but lower
+ highest = contract;
+ }
+ }
+ }
}
return highest.Validate();
}