Ejemplo n.º 1
0
        private int GetTricksTaken()
        {
            int count = _tricks.Sum(t => t.Winner.GetSide() == Declarer.GetSide() ? 1 : 0);

            return(count - 6);
            //Todo: limit to positive numbers ???
        }
Ejemplo n.º 2
0
        public override string ToString()
        {
            //Declarers (x) made x tricks, defenders (y) made y tricks.
            //The contract was (not) made by/plus x/y tricks under/over
            //
            StringBuilder sb = new StringBuilder();

            sb.Append(string.Format("Declarers ({0}) made {1} trick{2}.  ",
                                    Declarer.GetSide(), TricksTaken, TricksTaken == 1 ? "" : "s"));
            sb.AppendLine(string.Format("Defenders ({0}) made {1} trick{2}.",
                                        Declarer.GetSide().OtherSide(), TricksDefeated, TricksDefeated == 1 ? "" : "s"));
            if (MadeContract)
            {
                if (TricksOverContract == 0)
                {
                    sb.AppendLine(string.Format("The contract({0}) was made exactly.", Contract));
                }
                else
                {
                    sb.AppendLine(string.Format("The contract({0}) was made with {1} overtrick{2}.",
                                                Contract, TricksOverContract, TricksOverContract == 1 ? "" : "s"));
                }
            }
            else
            {
                sb.AppendLine(string.Format("The contract({0}) was defeated by {1} undertrick{2}.",
                                            Contract, TricksUnderContract, TricksUnderContract == 1 ? "" : "s"));
            }
            //FIXME - display better, give totals, make sure it is correct
            sb.AppendLine(string.Format("Points for Declarer: Contract:{0} OverTricks:{1} Level Bonus:{2} Insults:{3}",
                                        ContractScore, GetOverTrickPoints(), GetLevelBonus(), GetInsult()));
            sb.AppendLine(string.Format("Points for Defender {0}", GetPenalties()));
            return(sb.ToString());
        }
Ejemplo n.º 3
0
        public override void TransferStateTo(Visitor targetVisitor)
        {
            base.TransferStateTo(targetVisitor);
            Declarer target = targetVisitor as Declarer;

            if (target == null)
            {
                return;
            }
            target.scope       = this.scope;
            target.targetFor   = this.targetFor;
            target.localLabels = this.localLabels;
            target.labelList   = this.labelList;
        }
Ejemplo n.º 4
0
        public void HandlePropertyBeingDereferenced(IType propertySource, string propertyName)
        {
            if (QueryableCollection != null && CollectionProperties.IsCollectionProperty(propertyName))
            {
                // propertyName refers to something like collection.size...
                return;
            }
            if (propertySource.IsComponentType)
            {
                // property name is a sub-path of a component...
                return;
            }

            IQueryable persister = Queryable;

            if (persister != null)
            {
                try
                {
                    Declarer propertyDeclarer = persister.GetSubclassPropertyDeclarer(propertyName);

                    if (Log.IsInfoEnabled())
                    {
                        Log.Info("handling property dereference [{0} ({1}) -> {2} ({3})]", persister.EntityName, ClassAlias, propertyName, propertyDeclarer);
                    }
                    if (propertyDeclarer == Declarer.SubClass)
                    {
                        _dereferencedBySubclassProperty = true;
                        _includeSubclasses = true;
                    }
                    else if (propertyDeclarer == Declarer.SuperClass)
                    {
                        _dereferencedBySuperclassProperty = true;
                    }
                }
                catch (QueryException ex)
                {
                    // ignore it; the incoming property could not be found so we
                    // cannot be sure what to do here.  At the very least, the
                    // safest is to simply not apply any dereference toggling...
                    Log.Debug(ex, "Unable to find property {0}, no dereference will be handled for it.", propertyName);
                }
            }
        }
Ejemplo n.º 5
0
 public override Statement VisitResourceUse(ResourceUse resourceUse){
   if (resourceUse == null) return null;
   Scope savedScope = this.scope;
   Scope scope = this.scope = resourceUse.ScopeForTemporaryVariable = new BlockScope(savedScope, resourceUse.Body);
   this.AddToAllScopes(this.scope);
   Declarer declarer = new Declarer(this.ErrorHandler);
   declarer.VisitResourceUse(resourceUse, scope);
   resourceUse.ResourceAcquisition = (Statement)this.Visit(resourceUse.ResourceAcquisition);
   resourceUse.Body = this.VisitBlock(resourceUse.Body);
   this.scope = savedScope;
   return resourceUse;
 }
Ejemplo n.º 6
0
 public override Statement VisitAcquire(Acquire acquire){
   if (@acquire == null) return null;
   if (@acquire.Condition != null)
     @acquire.ConditionFunction = new Construct(new Literal(SystemTypes.ThreadConditionDelegate, SystemTypes.Type), new ExpressionList(new AnonymousNestedFunction(null, new Block(new StatementList(new Return(@acquire.Condition))))));
   Scope savedScope = this.scope;
   Scope scope = this.scope = @acquire.ScopeForTemporaryVariable = new BlockScope(savedScope, @acquire.Body);
   this.AddToAllScopes(this.scope);
   Declarer declarer = new Declarer(this.ErrorHandler);
   declarer.VisitAcquire(@acquire, scope);
   @acquire.Target = (Statement) this.Visit(@acquire.Target);
   @acquire.Condition = this.VisitExpression(@acquire.Condition);
   @acquire.ConditionFunction = this.VisitExpression(@acquire.ConditionFunction);
   @acquire.Body = this.VisitBlock(@acquire.Body);
   this.scope = savedScope;
   return @acquire;
 }
Ejemplo n.º 7
0
 public override Statement VisitFixed(Fixed Fixed){
   if (Fixed == null) return null;
   Scope savedScope = this.scope;
   BlockScope scope = Fixed.ScopeForTemporaryVariables = new BlockScope(savedScope, Fixed.Body);
   scope.MembersArePinned = true;
   this.scope = scope;
   this.AddToAllScopes(scope);
   Declarer declarer = new Declarer(this.ErrorHandler);
   declarer.VisitFixed(Fixed, scope);
   Statement result = base.VisitFixed(Fixed);
   this.scope = savedScope;
   return result;
 }