예제 #1
0
        private DealResult PrepareDealResult()
        {
            // TODO: Evaluate game result and don't forget the "last 10" rule and announcements
            var result = new DealResult();

            return result;
        }
        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;
        }
 public void EndOfDeal(DealResult dealResult)
 {
 }
 public virtual void EndOfDeal(DealResult dealResult)
 {
 }
예제 #5
0
        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);
        }
 public override void EndOfDeal(DealResult dealResult)
 {
     Console.WriteLine("{0} - {1} (contract kept: {2}, no tricks: {3})", dealResult.SouthNorthPoints, dealResult.EastWestPoints, !dealResult.ContractNotKept, dealResult.NoTricksForOneOfTheTeams);
     Console.ReadKey(false);
 }
예제 #7
0
        private DealResult PrepareDealResult(Contract contract)
        {
            var southNorthCardPointsSum = this.southNorthPlayersCardsTaken.Sum(card => card.GetValue(contract.Type));
            var eastWestCardPointsSum = this.eastWestPlayersCardsTaken.Sum(card => card.GetValue(contract.Type));
            var noTricksForOneOfTheTeams = this.southNorthPlayersCardsTaken.Count == 0 || this.eastWestPlayersCardsTaken.Count == 0;

            // "last 10" rule
            if (this.southNorthTeamTakesLastHand == true)
            {
                southNorthCardPointsSum += 10;
            }
            else if (this.southNorthTeamTakesLastHand == false)
            {
                eastWestCardPointsSum += 10;
            }

            // Belotes
            southNorthCardPointsSum += 20 * this.southNorthBelotes;
            eastWestCardPointsSum += 20 * this.eastWestBelotes;

            // TODO: Count announcements

            var result = new DealResult(true, contract, southNorthCardPointsSum / 10, eastWestCardPointsSum / 10, noTricksForOneOfTheTeams);
            return result;
        }
예제 #8
0
 public void EndOfDeal(DealResult dealResult)
 {
     //throw new NotImplementedException();
 }