private DealResult PrepareDealResult(Contract contract)
{
// Count card values
var southNorthPoints = this.southNorthPlayersCardsTaken.Sum(card => card.GetValue(contract.Type));
var eastWestPoints = this.eastWestPlayersCardsTaken.Sum(card => card.GetValue(contract.Type));
// "last 10" rule
if (this.southNorthTeamTakesLastHand == true)
{
southNorthPoints += 10;
}
else if (this.southNorthTeamTakesLastHand == false)
{
eastWestPoints += 10;
}
// Belotes
southNorthPoints += 20 * this.southNorthBelotes;
eastWestPoints += 20 * this.eastWestBelotes;
// No trump
if (contract.Type == ContractType.NoTrumps)
{
southNorthPoints *= 2;
eastWestPoints *= 2;
}
// No tricks for one of the teams?
var noTricksForOneOfTheTeams = this.southNorthPlayersCardsTaken.Count == 0 || this.eastWestPlayersCardsTaken.Count == 0;
if (this.southNorthPlayersCardsTaken.Count == 0)
{
if (contract.Type == ContractType.NoTrumps)
{
eastWestPoints += NoTrumpNoTricksValue;
}
else
{
eastWestPoints += 90;
}
}
else if (this.eastWestPlayersCardsTaken.Count == 0)
{
if (contract.Type == ContractType.NoTrumps)
{
southNorthPoints += NoTrumpNoTricksValue;
}
else
{
southNorthPoints += 90;
}
}
// Card combinations
// TODO: Count points from card combinations
// Check if contract is kept and for hanging points
var hangingPoints = 0;
var contractNotKept = false;
if (contract.PlayerPosition == PlayerPosition.South || contract.PlayerPosition == PlayerPosition.North)
{
if (southNorthPoints < eastWestPoints)
{
// Contract not kept
contractNotKept = true;
eastWestPoints += southNorthPoints;
southNorthPoints = 0;
}
else if (southNorthPoints == eastWestPoints)
{
// "Hanging" points
hangingPoints = southNorthPoints;
southNorthPoints = 0;
}
}
else
{
if (eastWestPoints < southNorthPoints)
{
// Contract not kept
contractNotKept = true;
southNorthPoints += eastWestPoints;
eastWestPoints = 0;
}
else if (southNorthPoints == eastWestPoints)
{
// "Hanging" points
hangingPoints = eastWestPoints;
eastWestPoints = 0;
}
}
// Round points
southNorthPoints = contract.RoundPoints(southNorthPoints, southNorthPoints > eastWestPoints);
eastWestPoints = contract.RoundPoints(eastWestPoints, eastWestPoints > southNorthPoints);
hangingPoints = contract.RoundPoints(hangingPoints, false);
// Double and re-double
bool isGameDoubled = contract.IsReDoubled || contract.IsDoubled;
if (DoublesDoNotCountWhenNoTricks && noTricksForOneOfTheTeams)
{
isGameDoubled = false;
}
if (isGameDoubled)
{
var weight = contract.IsReDoubled ? 4 : 2;
if (southNorthPoints > eastWestPoints)
{
southNorthPoints = weight * (southNorthPoints + eastWestPoints);
eastWestPoints = 0;
}
else if (eastWestPoints > southNorthPoints)
{
southNorthPoints = 0;
eastWestPoints = weight * (southNorthPoints + eastWestPoints);
}
else
{
hangingPoints = southNorthPoints + eastWestPoints + hangingPoints;
hangingPoints *= weight;
southNorthPoints = 0;
eastWestPoints = 0;
}
}
// Final result
var result = new DealResult(true, contract, southNorthPoints, eastWestPoints, hangingPoints, contractNotKept, noTricksForOneOfTheTeams);
return result;
}