Or() public method

public Or ( BitArray value ) : BitArray
value BitArray
return BitArray
Exemplo n.º 1
0
        static void Main()
        {
            //input
            int arraySize = int.Parse(Console.ReadLine());

            //get array
            int[] toSearch = new int[arraySize];

            for (int i = 0; i < arraySize; i++)
            {
                toSearch[i] = int.Parse(Console.ReadLine());
            }

            // variables
            BitArray sumFlags = new BitArray(arraySize);
            BitArray maxFlags = new BitArray(arraySize);

            int curSum = 0;
            int maxSum = toSearch.Sum();

            for (int curNumb = 0; curNumb < toSearch.Length; curNumb++)
            {
                // Step 1: Get Current Sum
                curSum += toSearch[curNumb];
                sumFlags.Set(curNumb, true);

                if (curSum > maxSum)
                {
                    // Store the Sum
                    maxSum = curSum;

                    // Flag the indexes
                    maxFlags.SetAll(false);
                    maxFlags.Or(sumFlags);
                }
                else
                {
                    if (curSum < 0)
                    {
                        // discard and start summing again
                        curSum = 0;
                        sumFlags.SetAll(false);
                    }
                    else
                    {
                        // keep going
                        continue;
                    }
                }
            }

            // output
            Console.WriteLine(maxSum);
        }
Exemplo n.º 2
0
        public void AddBitsOf(HasseFingerprint F)
        {
            BitArray fp2 = ((HasseFingerprint)F).fp;


            if (fp == null)
            {
                fp = new System.Collections.BitArray(fp2);
            }
            else
            {
                fp.Or(fp2);
            }
            this.bitCount = this.CountBits();
        }
 static public int Or(IntPtr l)
 {
     try {
         System.Collections.BitArray self = (System.Collections.BitArray)checkSelf(l);
         System.Collections.BitArray a1;
         checkType(l, 2, out a1);
         var ret = self.Or(a1);
         pushValue(l, true);
         pushValue(l, ret);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Exemplo n.º 4
0
	// use a switch if more than 5 alternatives and none starts with a resolver
	bool UseSwitch (Node p) {
		BitArray s1, s2;
		if (p.typ != Node.alt) return false;
		int nAlts = 0;
		s1 = new BitArray(tab.terminals.Count);
		while (p != null) {
			s2 = tab.Expected0(p.sub, curSy);
			// must not optimize with switch statement, if there are ll1 warnings
			if (Overlaps(s1, s2)) { return false; }
			s1.Or(s2);
			++nAlts;
			// must not optimize with switch-statement, if alt uses a resolver expression
			if (p.sub.typ == Node.rslv) return false;
			p = p.down;
		}
		return nAlts > 5;
	}
Exemplo n.º 5
0
        static void BitArrayDemo()
        {
            var bits1 = new BitArray(8);
            bits1.SetAll(true);
            bits1.Set(1, false);
            bits1[5] = false;
            bits1[7] = false;
            Console.Write("initialized: ");
            DisplayBits(bits1);
            Console.WriteLine();

            DisplayBits(bits1);
            bits1.Not();
            Console.Write(" not ");
            DisplayBits(bits1);
            Console.WriteLine();

            var bits2 = new BitArray(bits1);
            bits2[0] = true;
            bits2[1] = false;
            bits2[4] = true;
            DisplayBits(bits1);
            Console.Write(" or ");
            DisplayBits(bits2);
            Console.Write(" : ");
            bits1.Or(bits2);
            DisplayBits(bits1);
            Console.WriteLine();

            DisplayBits(bits2);
            Console.Write(" and ");
            DisplayBits(bits1);
            Console.Write(" : ");
            bits2.And(bits1);
            DisplayBits(bits2);
            Console.WriteLine();

            DisplayBits(bits1);
            Console.Write(" xor ");
            DisplayBits(bits2);
            bits1.Xor(bits2);
            Console.Write(" : ");
            DisplayBits(bits1);
            Console.WriteLine();
        }
        public void Or()
        {
            BitArray array1 = new BitArray(4);
            BitArray array2 = new BitArray(4);

            array1[0] = true;
            array1[1] = false;
            array1[2] = false;
            array1[3] = false;

            array2[0] = true;
            array2[1] = false;
            array2[2] = true;
            array2[3] = true;

            array1.Or(array2);

            Assert.AreEqual(true,  array1[0]);
            Assert.AreEqual(false, array1[1]);
            Assert.AreEqual(true,  array1[2]);
            Assert.AreEqual(true,  array1[3]);
        }
Exemplo n.º 7
0
        public ConfirmSignupGump( Mobile from, Mobile registrar, Tournament tourny, ArrayList players )
            : base(50, 50)
        {
            m_From = from;
            m_Registrar = registrar;
            m_Tournament = tourny;
            m_Players = players;

            m_From.CloseGump( typeof( AcceptTeamGump ) );
            m_From.CloseGump( typeof( AcceptDuelGump ) );
            m_From.CloseGump( typeof( DuelContextGump ) );
            m_From.CloseGump( typeof( ConfirmSignupGump ) );

            #region Rules
            Ruleset ruleset = tourny.Ruleset;
            Ruleset basedef = ruleset.Base;

            int height = 185 + 60 + 12;

            int changes = 0;

            BitArray defs;

            if ( ruleset.Flavors.Count > 0 )
            {
                defs = new BitArray( basedef.Options );

                for ( int i = 0; i < ruleset.Flavors.Count; ++i )
                    defs.Or( ((Ruleset)ruleset.Flavors[i]).Options );

                height += ruleset.Flavors.Count * 18;
            }
            else
            {
                defs = basedef.Options;
            }

            BitArray opts = ruleset.Options;

            for ( int i = 0; i < opts.Length; ++i )
            {
                if ( defs[i] != opts[i] )
                    ++changes;
            }

            height += (changes * 22);

            height += 10 + 22 + 25 + 25;

            if ( tourny.PlayersPerParticipant > 1 )
                height += 36 + (tourny.PlayersPerParticipant * 20);
            #endregion

            Closable = false;

            AddPage( 0 );

            //AddBackground( 0, 0, 400, 220, 9150 );
            AddBackground( 1, 1, 398, height, 3600 );
            //AddBackground( 16, 15, 369, 189, 9100 );

            AddImageTiled( 16, 15, 369, height - 29, 3604 );
            AddAlphaRegion( 16, 15, 369, height - 29 );

            AddImage( 215, -43, 0xEE40 );
            //AddImage( 330, 141, 0x8BA );

            StringBuilder sb = new StringBuilder();

            if ( tourny.TournyType == TournyType.FreeForAll )
            {
                sb.Append( "FFA" );
            }
            else if ( tourny.TournyType == TournyType.RandomTeam )
            {
                sb.Append( "Team" );
            }
            else if ( tourny.TournyType == TournyType.RedVsBlue )
            {
                sb.Append( "Red v Blue" );
            }
            else
            {
                for ( int i = 0; i < tourny.ParticipantsPerMatch; ++i )
                {
                    if ( sb.Length > 0 )
                        sb.Append( 'v' );

                    sb.Append( tourny.PlayersPerParticipant );
                }
            }

            if ( tourny.EventController != null )
                sb.Append( ' ' ).Append( tourny.EventController.Title );

            sb.Append( " Tournament Signup" );

            AddBorderedText( 22, 22, 294, 20, Center( sb.ToString() ), LabelColor32, BlackColor32 );
            AddBorderedText( 22, 50, 294, 40, "You have requested to join the tournament. Do you accept the rules?", 0xB0C868, BlackColor32 );

            AddImageTiled( 32, 88, 264, 1, 9107 );
            AddImageTiled( 42, 90, 264, 1, 9157 );

            #region Rules
            int y = 100;

            string groupText = null;

            switch ( tourny.GroupType )
            {
                case GroupingType.HighVsLow: groupText = "High vs Low"; break;
                case GroupingType.Nearest: groupText = "Closest opponent"; break;
                case GroupingType.Random: groupText = "Random"; break;
            }

            AddBorderedText( 35, y, 190, 20, String.Format( "Grouping: {0}", groupText ), LabelColor32, BlackColor32 );
            y += 20;

            string tieText = null;

            switch ( tourny.TieType )
            {
                case TieType.Random: tieText = "Random"; break;
                case TieType.Highest: tieText = "Highest advances"; break;
                case TieType.Lowest: tieText = "Lowest advances"; break;
                case TieType.FullAdvancement: tieText = ( tourny.ParticipantsPerMatch == 2 ? "Both advance" : "Everyone advances" ); break;
                case TieType.FullElimination: tieText = ( tourny.ParticipantsPerMatch == 2 ? "Both eliminated" : "Everyone eliminated" ); break;
            }

            AddBorderedText( 35, y, 190, 20, String.Format( "Tiebreaker: {0}", tieText ), LabelColor32, BlackColor32 );
            y += 20;

            string sdText = "Off";

            if ( tourny.SuddenDeath > TimeSpan.Zero )
            {
                sdText = String.Format( "{0}:{1:D2}", (int) tourny.SuddenDeath.TotalMinutes, tourny.SuddenDeath.Seconds );

                if ( tourny.SuddenDeathRounds > 0 )
                    sdText = String.Format( "{0} (first {1} rounds)", sdText, tourny.SuddenDeathRounds );
                else
                    sdText = String.Format( "{0} (all rounds)", sdText );
            }

            AddBorderedText( 35, y, 240, 20, String.Format( "Sudden Death: {0}", sdText ), LabelColor32, BlackColor32 );
            y += 20;

            y += 6;
            AddImageTiled( 32, y-1, 264, 1, 9107 );
            AddImageTiled( 42, y+1, 264, 1, 9157 );
            y += 6;

            AddBorderedText( 35, y, 190, 20, String.Format( "Ruleset: {0}", basedef.Title ), LabelColor32, BlackColor32 );
            y += 20;

            for ( int i = 0; i < ruleset.Flavors.Count; ++i, y += 18 )
                AddBorderedText( 35, y, 190, 20, String.Format( " + {0}", ((Ruleset)ruleset.Flavors[i]).Title ), LabelColor32, BlackColor32 );

            y += 4;

            if ( changes > 0 )
            {
                AddBorderedText( 35, y, 190, 20, "Modifications:", LabelColor32, BlackColor32 );
                y += 20;

                for ( int i = 0; i < opts.Length; ++i )
                {
                    if ( defs[i] != opts[i] )
                    {
                        string name = ruleset.Layout.FindByIndex( i );

                        if ( name != null ) // sanity
                        {
                            AddImage( 35, y, opts[i] ? 0xD3 : 0xD2 );
                            AddBorderedText( 60, y, 165, 22, name, LabelColor32, BlackColor32 );
                        }

                        y += 22;
                    }
                }
            }
            else
            {
                AddBorderedText( 35, y, 190, 20, "Modifications: None", LabelColor32, BlackColor32 );
                y += 20;
            }
            #endregion

            #region Team
            if ( tourny.PlayersPerParticipant > 1 )
            {
                y += 8;
                AddImageTiled( 32, y-1, 264, 1, 9107 );
                AddImageTiled( 42, y+1, 264, 1, 9157 );
                y += 8;

                AddBorderedText( 35, y, 190, 20, "Your Team", LabelColor32, BlackColor32 );
                y += 20;

                for ( int i = 0; i < players.Count; ++i, y += 20 )
                {
                    if ( i == 0 )
                        AddImage( 35, y, 0xD2 );
                    else
                        AddGoldenButton( 35, y, 1 + i );

                    AddBorderedText( 60, y, 200, 20, ((Mobile)players[i]).Name, LabelColor32, BlackColor32 );
                }

                for ( int i = players.Count; i < tourny.PlayersPerParticipant; ++i, y += 20 )
                {
                    if ( i == 0 )
                        AddImage( 35, y, 0xD2 );
                    else
                        AddGoldenButton( 35, y, 1 + i );

                    AddBorderedText( 60, y, 200, 20, "(Empty)", LabelColor32, BlackColor32 );
                }
            }
            #endregion

            y += 8;
            AddImageTiled( 32, y-1, 264, 1, 9107 );
            AddImageTiled( 42, y+1, 264, 1, 9157 );
            y += 8;

            AddRadio( 24, y, 9727, 9730, true, 1 );
            AddBorderedText( 60, y+5, 250, 20, "Yes, I wish to join the tournament.", LabelColor32, BlackColor32 );
            y += 35;

            AddRadio( 24, y, 9727, 9730, false, 2 );
            AddBorderedText( 60, y+5, 250, 20, "No, I do not wish to join.", LabelColor32, BlackColor32 );
            y += 35;

            y -= 3;
            AddButton( 314, y, 247, 248, 1, GumpButtonType.Reply, 0 );
        }
Exemplo n.º 8
0
        private void ComputeGlobalLiveSets()
        {
            bool changed = true;
            while (changed)
            {
                changed = false;

                for (int i = basicBlocks.Count - 1; i >= 0; i--)
                {
                    var block = extendedBlocks[i];

                    BitArray liveOut = new BitArray(registerCount);

                    foreach (var next in block.BasicBlock.NextBlocks)
                    {
                        liveOut.Or(extendedBlocks[next.Sequence].LiveIn);
                    }

                    BitArray liveIn = (BitArray)block.LiveOut.Clone();
                    liveIn.And(block.LiveKillNot);
                    liveIn.Or(block.LiveGen);

                    // compare them for any changes
                    if (!changed)
                        if (!block.LiveOut.AreSame(liveOut) || !block.LiveIn.AreSame(liveIn))
                            changed = true;

                    block.LiveOut = liveOut;
                    block.LiveIn = liveIn;
                }
            }
        }
Exemplo n.º 9
0
 void CheckRes(Node p, bool rslvAllowed)
 {
     while (p != null) {
     switch (p.typ) {
         case Node.alt:
             BitArray expected = new BitArray(terminals.Count);
             for (Node q = p; q != null; q = q.down)
                 expected.Or(Expected0(q.sub, curSy));
             BitArray soFar = new BitArray(terminals.Count);
             for (Node q = p; q != null; q = q.down) {
                 if (q.sub.typ == Node.rslv) {
                     BitArray fs = Expected(q.sub.next, curSy);
                     if (Sets.Intersect(fs, soFar))
                         ResErr(q.sub, "Warning: Resolver will never be evaluated. " +
                         "Place it at previous conflicting alternative.");
                     if (!Sets.Intersect(fs, expected) && !q.sub.resolverWasExtracted)
                         ResErr(q.sub, "Warning: Misplaced resolver: no LL(1) conflict.");
                 } else {
                     BitArray fs = Expected(q.sub, curSy);
                     if (q.sub.typ == Node.expectedConflict) {
                         BitArray remaining = Expected(q.down, curSy);
                         BitArray conflict = new BitArray(fs).And(remaining);
                         if (!Sets.Equals(conflict, MakeSetForConflictSymbols(q.sub.conflictSymbols)))
                             ResErr(q.sub, "Warning: Expected conflict does not match real conflict");
                     }
                     soFar.Or(fs);
                 }
                 CheckRes(q.sub, true);
             }
             break;
         case Node.iter: case Node.opt:
             if (p.sub.typ == Node.rslv) {
                 BitArray fs = First(p.sub.next);
                 BitArray fsNext = Expected(p.next, curSy);
                 if (!Sets.Intersect(fs, fsNext))
                     ResErr(p.sub, "Warning: Misplaced resolver: no LL(1) conflict.");
             } else if (p.sub.typ == Node.expectedConflict) {
                 BitArray fs = First(p.sub.next);
                 BitArray fsNext = Expected(p.next, curSy);
                 BitArray conflict = new BitArray(fs).And(fsNext);
                 if (!Sets.Equals(conflict, MakeSetForConflictSymbols(p.sub.conflictSymbols)))
                     ResErr(p.sub, "Warning: Expected conflict does not match real conflict");
             }
             CheckRes(p.sub, true);
             break;
         case Node.rslv:
             if (!rslvAllowed)
                 ResErr(p, "Warning: Misplaced resolver: no alternative.");
             break;
         case Node.expectedConflict:
             if (!rslvAllowed)
                 ResErr(p, "Warning: Misplaced expected conflict: no alternative.");
             break;
     }
     if (p.up) break;
     p = p.next;
     rslvAllowed = false;
     }
 }
Exemplo n.º 10
0
		public ReadyUpGump( Mobile from, DuelContext context ) : base( 50, 50 )
		{
			m_From = from;
			m_Context = context;

			Closable = false;
			AddPage( 0 );

			if ( context.Rematch )
			{
				int height = 25 + 20 + 10 + 22 + 25;

				AddBackground( 0, 0, 210, height, 9250 );
				AddBackground( 10, 10, 190, height - 20, 0xDAC );

				AddHtml( 35, 25, 140, 20, Center( "Rematch?" ), false, false );

				AddButton( 35, 55, 247, 248, 1, GumpButtonType.Reply, 0 );
				AddButton( 115, 55, 242, 241, 2, GumpButtonType.Reply, 0 );
			}
			else
			{
				#region Participants
				AddPage( 1 );

				ArrayList parts = context.Participants;

				int height = 25 + 20;

				for ( int i = 0; i < parts.Count; ++i )
				{
					Participant p = (Participant)parts[i];

					height += 4;

					if ( p.Players.Length > 1 )
						height += 22;

					height += (p.Players.Length * 22);
				}

				height += 10 + 22 + 25;

				AddBackground( 0, 0, 260, height, 9250 );
				AddBackground( 10, 10, 240, height - 20, 0xDAC );

				AddHtml( 35, 25, 190, 20, Center( "Participants" ), false, false );

				int y = 20 + 25;

				for ( int i = 0; i < parts.Count; ++i )
				{
					Participant p = (Participant)parts[i];

					y += 4;

					int offset = 0;

					if ( p.Players.Length > 1 )
					{
						AddHtml( 35, y, 176, 20, String.Format( "Team #{0}", i + 1 ), false, false );
						y += 22;
						offset = 10;
					}

					for ( int j = 0; j < p.Players.Length; ++j )
					{
						DuelPlayer pl = p.Players[j];

						string name = ( pl == null ? "(Empty)" : pl.Mobile.Name );

						AddHtml( 35 + offset, y, 166, 20, name, false, false );

						y += 22;
					}
				}

				y += 8;

				AddHtml( 35, y, 176, 20, "Continue?", false, false );

				y -= 2;

				AddButton( 102, y, 247, 248, 0, GumpButtonType.Page, 2 );
				AddButton( 169, y, 242, 241, 2, GumpButtonType.Reply, 0 );
				#endregion

				#region Rules
				AddPage( 2 );

				Ruleset ruleset = context.Ruleset;
				Ruleset basedef = ruleset.Base;

				height = 25 + 20 + 5 + 20 + 20 + 4;

				int changes = 0;

				BitArray defs;

				if ( ruleset.Flavors.Count > 0 )
				{
					defs = new BitArray( basedef.Options );

					for ( int i = 0; i < ruleset.Flavors.Count; ++i )
						defs.Or( ((Ruleset)ruleset.Flavors[i]).Options );

					height += ruleset.Flavors.Count * 18;
				}
				else
				{
					defs = basedef.Options;
				}

				BitArray opts = ruleset.Options;

				for ( int i = 0; i < opts.Length; ++i )
				{
					if ( defs[i] != opts[i] )
						++changes;
				}

				height += (changes * 22);

				height += 10 + 22 + 25;

				AddBackground( 0, 0, 260, height, 9250 );
				AddBackground( 10, 10, 240, height - 20, 0xDAC );

				AddHtml( 35, 25, 190, 20, Center( "Rules" ), false, false );

				AddHtml( 35, 50, 190, 20, String.Format( "Set: {0}", basedef.Title ), false, false );

				y = 70;

				for ( int i = 0; i < ruleset.Flavors.Count; ++i, y += 18 )
					AddHtml( 35, y, 190, 20, String.Format( " + {0}", ((Ruleset)ruleset.Flavors[i]).Title ), false, false );

				y += 4;

				if ( changes > 0 )
				{
					AddHtml( 35, y, 190, 20, "Modifications:", false, false );
					y += 20;

					for ( int i = 0; i < opts.Length; ++i )
					{
						if ( defs[i] != opts[i] )
						{
							string name = ruleset.Layout.FindByIndex( i );

							if ( name != null ) // sanity
							{
								AddImage( 35, y, opts[i] ? 0xD3 : 0xD2 );
								AddHtml( 60, y, 165, 22, name, false, false );
							}

							y += 22;
						}
					}
				}
				else
				{
					AddHtml( 35, y, 190, 20, "Modifications: None", false, false );
					y += 20;
				}

				y += 8;

				AddHtml( 35, y, 176, 20, "Continue?", false, false );

				y -= 2;

				AddButton( 102, y, 247, 248, 1, GumpButtonType.Reply, 0 );
				AddButton( 169, y, 242, 241, 3, GumpButtonType.Reply, 0 );
				#endregion
			}
		}
Exemplo n.º 11
0
		private void MessageRuleset( Mobile mob ) {
			if ( m_Ruleset == null ) {
				return;
			}

			Ruleset ruleset = m_Ruleset;
			Ruleset basedef = ruleset.Base;

			mob.SendMessage( "Ruleset: {0}", basedef.Title );

			BitArray defs;

			if ( ruleset.Flavors.Count > 0 )
			{
				defs = new BitArray( basedef.Options );

				for ( int i = 0; i < ruleset.Flavors.Count; ++i ) {
					defs.Or( ((Ruleset)ruleset.Flavors[i]).Options );

					mob.SendMessage( " + {0}", ((Ruleset)ruleset.Flavors[i]).Title );
				}
			}
			else
			{
				defs = basedef.Options;
			}

			int changes = 0;

			BitArray opts = ruleset.Options;

			for ( int i = 0; i < opts.Length; ++i )
			{
				if ( defs[i] != opts[i] ) {
					string name = ruleset.Layout.FindByIndex( i );

					if ( name != null ) // sanity
					{
						++changes;

						if ( changes == 1 ) {
							mob.SendMessage( "Modifications:" );
						}

						mob.SendMessage( "{0}: {1}", name, opts[i] ? "enabled" : "disabled" );
					}
				}
			}
		}
Exemplo n.º 12
0
Arquivo: Tab.cs Projeto: ggrov/tacny
	void CheckAlts(Node p) {
		BitArray s1, s2;
		while (p != null) {
			if (p.typ == Node.alt) {
				Node q = p;
				s1 = new BitArray(terminals.Count);
				while (q != null) { // for all alternatives
					s2 = Expected0(q.sub, curSy);
					CheckOverlap(s1, s2, 1);
					s1.Or(s2);
					CheckAlts(q.sub);
					q = q.down;
				}
			} else if (p.typ == Node.opt || p.typ == Node.iter) {
				if (DelSubGraph(p.sub)) LL1Error(4, null); // e.g. [[...]]
				else {
					s1 = Expected0(p.sub, curSy);
					s2 = Expected(p.next, curSy);
					CheckOverlap(s1, s2, 2);
				}
				CheckAlts(p.sub);
			} else if (p.typ == Node.any) {
				if (Sets.Elements(p.set) == 0) LL1Error(3, null);
				// e.g. {ANY} ANY or [ANY] ANY or ( ANY | ANY )
			}
			if (p.up) break;
			p = p.next;
		}
	}
Exemplo n.º 13
0
Arquivo: Tab.cs Projeto: ggrov/tacny
	//---------------------------------------------------------------------
	//  Symbol set computations
	//---------------------------------------------------------------------

	/* Computes the first set for the graph rooted at p */
	BitArray First0(Node p, BitArray mark) {
		BitArray fs = new BitArray(terminals.Count);
		while (p != null && !mark[p.n]) {
			mark[p.n] = true;
			switch (p.typ) {
				case Node.nt: {
					if (p.sym.firstReady) fs.Or(p.sym.first);
					else fs.Or(First0(p.sym.graph, mark));
					break;
				}
				case Node.t: case Node.wt: {
					fs[p.sym.n] = true; break;
				}
				case Node.any: {
					fs.Or(p.set); break;
				}
				case Node.alt: {
					fs.Or(First0(p.sub, mark));
					fs.Or(First0(p.down, mark));
					break;
				}
				case Node.iter: case Node.opt: {
					fs.Or(First0(p.sub, mark));
					break;
				}
			}
			if (!DelNode(p)) break;
			p = p.next;
		}
		return fs;
	}
Exemplo n.º 14
0
 void GenCond(BitArray s, Node p, bool allowExtractResolvers)
 {
     if (p.typ == Node.rslv) CopySourcePart(p.pos, 0);
     else if (p.typ == Node.alt && allowExtractResolvers) {
     List<Position> resolvers = new List<Position>();
     s = new BitArray(s.Length);
     for (Node node = p; node != null; node = node.down) {
         if (node.sub.typ == Node.rslv && node.sub.resolverWasExtracted) {
             resolvers.Add(node.sub.pos);
         } else {
             s.Or(tab.First(node.sub));
         }
     }
     GenCond(s, p, false);
     foreach (Position resolver in resolvers) {
         gen.Write(" || (");
         CopySourcePart(resolver, 0);
         gen.Write(")");
     }
     } else {
     int n = Sets.Elements(s);
     if (n == 0) gen.Write("false"); // happens if an ANY set matches no symbol
     else if (n <= maxTerm)
         foreach (Symbol sym in tab.terminals) {
             if (s[sym.n]) {
                 gen.Write("la.kind == {0}", sym.n);
                 --n;
                 if (n > 0) gen.Write(" || ");
             }
         }
     else
         gen.Write("StartOf({0})", NewCondSet(s));
     }
 }
Exemplo n.º 15
0
        // SwitchStatement
        protected internal override bool Walk(SwitchStatement node)
        {
            // The expression is evaluated always.
            // Then each case clause expression is evaluated until match is found.
            // Therefore, the effects of the case clause expressions accumulate.
            // Default clause is evaluated last (so all case clause expressions must
            // accumulate first)
            WalkNode(node.TestValue);

            // Flow all the cases, they all start with the same initial state
            int count;
            IList<SwitchCase> cases = node.Cases;
            if (cases != null && (count = cases.Count) > 0) {
                SwitchCase @default = null;
                // Save the initial state
                BitArray entry = _bits;
                // The state to progressively accumualte effects of the case clause expressions
                BitArray values = new BitArray(entry);
                // State to flow the case clause bodies.
                BitArray caseFlow = new BitArray(_bits.Length);
                // The state to accumulate results into
                BitArray result = new BitArray(_bits.Length, true);

                PushStatement(result);

                for (int i = 0; i < count; i++) {
                    if (cases[i].IsDefault) {
                        Debug.Assert(@default == null);

                        // postpone the default case
                        @default = cases[i];
                        continue;
                    }

                    // Set the state for the walking of the body
                    caseFlow.SetAll(false);
                    caseFlow.Or(values);

                    // Walk the body
                    _bits = caseFlow;
                    WalkNode(cases[i].Body);

                    // Accumulate the result into the overall case statement result.
                    result.And(caseFlow);
                }

                // Walk the default at the end.
                if (@default != null) {
                    // Initialize
                    caseFlow.SetAll(false);
                    caseFlow.Or(values);

                    // Walk the default body
                    _bits = caseFlow;
                    WalkNode(@default.Body);

                    // Accumulate.
                    result.And(caseFlow);

                    // If there's a default clause, exactly one case got executed.
                    // The final state is 'and' across all cases, stored in 'result'
                    entry.SetAll(false);
                    entry.Or(result);
                } else {
                    // In the absence of default clause, we may have executed case,
                    // but didn't have to, so the result is an 'and' between the cases
                    // and the initial state.
                    entry.And(result);
                }

                PopStatement();

                // Restore the original state.
                _bits = entry;
            }

            return false;
        }
Exemplo n.º 16
0
        // TryStatement
        protected internal override bool Walk(TryStatement node)
        {
            // The try body is guaranteed to be entered, but not completed,
            // the catch blocks are not guaranteed to be entered at all,
            // the finally block is guaranteed to be entered
            //
            // Any catch can be preceded by partial execution of try block,
            // so any 'damage' (deletes) the try block does must be affected
            // in the entry to the catch block. All catches have identical
            // starting situation.
            //
            // The finally can be preceded by partial execution of the try,
            // and at most one of the catches (any of them) so again, the
            // 'damage' the try and catch blocks do to the local state
            // affects the entry to the finally block.
            BitArray entry = _bits;
            _bits = new BitArray(_bits);

            // 1. Flow the body
            WalkNode(node.Body);
            entry.And(_bits);

            // 2. Flow the catch clauses, starting always with the initial state,
            //    but also including the 'damage' that try block could have done.
            int handlerCount;
            if (node.Handlers != null && (handlerCount = node.Handlers.Count) > 0) {
                for (int i = 0; i < handlerCount; i++) {
                    // Initialize the bits for flowing the catch clause
                    _bits.SetAll(false);
                    _bits.Or(entry);

                    // Flow the catch clause and propagate the 'damage' to the state we'll use for finally.
                    WalkNode(node.Handlers[i]);
                    entry.And(_bits);
                }
            }

            // 3. Restore the state to the original (including the effects the body and catch clauses had)
            _bits = entry;

            // 4. Flow the finally clause, if present.
            if (node.FinallyStatement != null) {
                WalkNode(node.FinallyStatement);
            }

            return false;
        }
Exemplo n.º 17
0
 void FindAS(Node p)
 {
     // find ANY sets
     Node a;
     while (p != null) {
     if (p.typ == Node.opt || p.typ == Node.iter) {
         FindAS(p.sub);
         a = LeadingAny(p.sub);
         if (a != null) Sets.Subtract(a.set, First(p.next));
     } else if (p.typ == Node.alt) {
         BitArray s1 = new BitArray(terminals.Count);
         Node q = p;
         while (q != null) {
             FindAS(q.sub);
             a = LeadingAny(q.sub);
             if (a != null)
                 Sets.Subtract(a.set, First(q.down).Or(s1));
             else
                 s1.Or(First(q.sub));
             q = q.down;
         }
     }
     if (p.up) break;
     p = p.next;
     }
 }
Exemplo n.º 18
0
		private bool UpdateEntrySet(BitArray entrySet, BitArray exitSet, BitArray useBeforeDef, BitArray notDef)
		{
			int card = entrySet.Cardinality();
			entrySet.Or(exitSet);
			entrySet.And(notDef);
			entrySet.Or(useBeforeDef);
			return entrySet.Cardinality() != card;
		}
Exemplo n.º 19
0
 BitArray MakeSetForConflictSymbols(List<Symbol> conflictSymbols)
 {
     BitArray arr = new BitArray(terminals.Count);
     foreach (Symbol sym in conflictSymbols) {
     if (sym.typ == Node.t)
         arr[sym.n] = true;
     else if (sym.typ == Node.nt) {
         Debug.Assert(sym.firstReady);
         arr.Or(sym.first);
     }
     }
     return arr;
 }
Exemplo n.º 20
0
        public static void Main()
        {
            Cons.WriteLine($"Chapter 10 - Collections...");

            //Play._Time(1);
            //Play._Time(2);

            //Collection Initializers
            var intList = new List <int>()
            {
                1, 2, 3, 4, 5
            };

            //Racers
            Racer GHill = new Racer(2, "Graham", "Hill", "UK", 10);
            Racer DHill = new Racer(7, "Dameon", "Hill", "UK", 14);

            var racers = new List <Racer>(10)
            {
                GHill, DHill
            };

            Cons.WriteLine($"{racers.Count} racers so far.");

            racers.Add(new Racer(24, "Michael", "Schumacher", "Germany", 91));
            racers.Insert(0, new Racer(22, "Ayrton", "Senna", "Brazil", 41));

            //Accessing elements
            var a1 = racers[0];

            Cons.WriteLine("Print list with a foreach loop.........................................");
            foreach (var r in racers)
            {
                Cons.WriteLine(r.ToString("N", null));
            }

            //Delagates again!
            Cons.WriteLine("Now using a delegate.........................................");
            racers.ForEach(Cons.WriteLine);
            Cons.WriteLine("Now using lambda to format.........................................");
            racers.ForEach(r => Cons.WriteLine($"{r:w}"));

            Racer R1 = new Racer(22, "Ayrton", "Senna", "Brazil", 41);

            if (!racers.Remove(R1))
            {
                Cons.WriteLine($"Racer {R1.Id} not found to remove.");
            }

            R1 = DHill;
            if (!racers.Remove(R1))
            {
                Cons.WriteLine($"Racer {DHill.Id} not found to remove.");
            }

            racers.Add(R1);
            //Using Find Predicate
            //int i2 = racers.FindIndex(new FindCountry("Finland").FindCountryPredicate);   This works but has a bugget, not my code!
            int i3 = racers.FindIndex(r => r.Country == "UK"); //Sane as line above and more likely to be used...

            i3 = racers.FindLastIndex(r => r.Country == "UK"); //Sane as line above and more likely to be used...

            var R2       = racers.FindLast(r => r.LastName == "Louder");
            var someWins = racers.FindAll(r => r.Wins < 20);

            someWins.Sort();

            var bigWiners = racers.FindAll(r => r.Wins > 20);

            bigWiners.Sort();

            racers.Sort(new RacerComp(RacerComp.CompareType.LastName));

            racers.Sort(new RacerComp(RacerComp.CompareType.Country));

            //Sort using delagte and Lambda expression.
            racers.Sort((r1, r2) => r2.Wins.CompareTo(r1.Wins));
            racers.Reverse();

            //Type Conversion...
            var rPeople = racers.ConvertAll <Person>(r => new Person(r.FirstName + ',' + r.LastName));

            //Read-Only Collections
            var roRacers = racers.AsReadOnly();

            //Queues
            var dm = new DocsManager();

            ProcessDocs.Start(dm);
            //Create docs and add too dm
            for (int i = 0; i < 100; i++)
            {
                var doc = new Doc("Doc" + i.ToString(), "AID" + new Random().Next(20).ToString());
                dm.AddDoc(doc);
                Console.WriteLine($"Added Document: {doc.Title} by {doc.Auther} to queue.");
                Thread.Sleep(new Random().Next(20));
            }

            Thread.Sleep(2000);
            ProcessDocs.Stop();

            //Stacks Quick one...
            var lets = new Stack <char>();

            lets.Push('A');
            lets.Push('B');
            lets.Push('C');

            foreach (var l in lets)
            {
                Cons.Write(l);
            }
            Cons.WriteLine();

            while (lets.Count > 0)
            {
                Cons.Write(lets.Pop());
            }
            Cons.WriteLine($"Next...");

            //Linked Lists...
            var pDM = new PDocManager();

            pDM.AddPDoc(new PDoc("Adoc", "AAAdams", 4));
            pDM.AddPDoc(new PDoc("Bdoc", "BBabs", 8));
            pDM.AddPDoc(new PDoc("Cdoc", "CCock", 4));
            pDM.AddPDoc(new PDoc("Ddoc", "AAAdams", 8));
            pDM.AddPDoc(new PDoc("Edoc", "CCock", 8));

            pDM.DisplayAllNodes();

            //Simple Sorted List
            var boots = new SortedList <int, string>();

            boots.Add(18, "Knee High");
            boots.Add(27, "Thigh Length");
            boots[12] = "Calfe";
            boots[6]  = "Ankle";

            foreach (var b in boots)
            {
                Cons.WriteLine($"{b.Key}, {b.Value}");
            }

            boots[27] = "Thigh High";

            foreach (var b in boots)
            {
                Cons.WriteLine($"{b.Key}, {b.Value}");
            }

            //What Next....for DCoates
            var employees = new Dictionary <EmployeeId, DicEmployee>();

            var idCat = new EmployeeId("A000001");
            var eCat  = new DicEmployee(idCat, "Cat", 100000.00m);

            employees.Add(idCat, eCat);

            var idAnt = new EmployeeId("A012345");
            var eAnt  = new DicEmployee(idAnt, "Ant", 23000.00m);

            employees.Add(idAnt, eAnt);

            var idBee = new EmployeeId("B000001");
            var eBee  = new DicEmployee(idBee, "Bee", 40000.00m);

            employees.Add(idBee, eBee);

            var idDog = new EmployeeId("A000002");
            var eDog  = new DicEmployee(idDog, "Dog", 10000.00m);

            employees.Add(idDog, eDog);

            foreach (var e in employees)
            {
                Cons.WriteLine(e.ToString());
            }

            while (true)
            {
                Cons.Write("Enter am Empolyee Id: (X to exit)>");
                var uIn = Cons.ReadLine();
                if (uIn.ToLower() == "x")
                {
                    break;
                }

                EmployeeId eId;
                try
                {
                    eId = new EmployeeId(uIn);

                    DicEmployee dEmp;
                    if (!employees.TryGetValue(eId, out dEmp))
                    {
                        Cons.WriteLine($"Employee with {eId} does not exist.");
                    }
                    else
                    {
                        Cons.WriteLine(dEmp);
                    }
                }
                catch (EmployeeIdException ee)
                {
                    Cons.WriteLine(ee.Message);
                }
            }

            //Lookups from System.core
            //Use the racers list from above

            var lookupRacers = racers.ToLookup(r => r.Country);

            foreach (var r in lookupRacers["UK"])
            {
                Cons.WriteLine($"name:{r.LastName}, {r.FirstName}");
            }
            //Nice but not sorted!

            //Sorted Dics....
            //Simple Sorted List
            var sdBoots = new SortedDictionary <int, string> {
                { 18, "Knee High" }, { 27, "Thigh Length" }
            };

            sdBoots[12] = "Calfe";
            sdBoots[6]  = "Ankle";

            foreach (var b in sdBoots)
            {
                Cons.WriteLine($"{b.Key}, {b.Value}");
            }

            //Sets...
            var allTeams = new HashSet <string>()
            {
                "Ferrari", "Lotus", "McLaren", "Honda", "BRM", "Aston Martin", "Red Bull", "Force India", "Sauber", "Williams"
            };
            var coTeams = new HashSet <string>()
            {
                "Ferrari", "Lotus", "McLaren", "Honda"
            };
            var oldTeams = new HashSet <string>()
            {
                "Ferrari", "Lotus", "BRM", "Aston Martin"
            };
            var newTeams = new HashSet <string>()
            {
                "Red Bull", "Force India", "Sauber"
            };

            var res = coTeams.Add("Williams");

            res = coTeams.Add("Williams");

            res = coTeams.IsSubsetOf(allTeams);
            res = allTeams.IsSupersetOf(coTeams);
            res = oldTeams.Overlaps(coTeams);
            res = newTeams.Overlaps(coTeams);

            var allTeams2 = new SortedSet <string>(coTeams);

            allTeams2.UnionWith(oldTeams);
            allTeams2.UnionWith(newTeams);

            res = allTeams2.SetEquals(allTeams);

            var tTeams = new SortedSet <string>(allTeams);

            tTeams.SymmetricExceptWith(oldTeams);
            var yTeams = new SortedSet <string>(allTeams);
            var yI     = new SortedSet <string>(yTeams.Intersect(oldTeams));

            //Observable Collections
            Cons.Clear();
            Cons.WriteLine("Observable Collections....");
            var data = new ObservableCollection <string>();

            data.CollectionChanged += Data_CollectionChanged;
            data.Add("First");
            data.Add("Second");
            data.Insert(1, "Three");
            data.Remove("Three");

            //Bits and bobs....
            Cons.WriteLine("Bits and Bobs....");
            var bitsA = new Col.BitArray(8);

            bitsA.SetAll(true);
            bitsA.Set(1, false);
            DisplayBits(bitsA);

            Cons.WriteLine();
            bitsA.Not();
            DisplayBits(bitsA);

            byte[] aI    = { 22 };
            var    bitsB = new Col.BitArray(aI);

            DisplayBits(bitsB);

            bitsA.Or(bitsB);
            DisplayBits(bitsA);

            //BitVector32 Struct
            var vBits = new Col.Specialized.BitVector32();
            int m1    = BitVector32.CreateMask();
            int m2    = BitVector32.CreateMask(m1);
            int m3    = BitVector32.CreateMask(m2);
            int m4    = BitVector32.CreateMask(m3);
            int m5    = BitVector32.CreateMask(128);

            vBits[m1] = true;
            vBits[m3] = true;
            vBits[m4] = true;
            vBits[m5] = true;

            Cons.WriteLine(vBits);

            int rec      = 0x88abcde;
            var vBitRSet = new BitVector32(rec);

            Cons.WriteLine(vBitRSet);

            //Immutable Collections
            ImmutabeThings.ImmutableTing1();

            Cons.ReadKey();
        }
Exemplo n.º 21
0
            public static void BitArray_Helper(Operator op)
            {
                BitArray ba2 = null;
                BitArray ba3 = null;
                BitArray ba4 = null;

                // []  Standard cases (1,1) (1,0) (0,0).
                ba2 = new BitArray(6, false);
                ba3 = new BitArray(6, false);

                ba2.Set(0, true);
                ba2.Set(1, true);

                ba3.Set(1, true);
                ba3.Set(2, true);

                switch (op)
                {
                    case Operator.Xor:
                        ba4 = ba2.Xor(ba3);
                        Assert.True(ba4.Get(0)); //"Err_8! Expected ba4.Get(0) to be true"
                        Assert.False(ba4.Get(1)); //"Err_9! Expected ba4.Get(1) to be false"
                        Assert.True(ba4.Get(2)); //"Err_10! Expected ba4.Get(2) to be true"
                        Assert.False(ba4.Get(4)); //"Err_11! Expected ba4.Get(4) to be false"
                        break;

                    case Operator.And:
                        ba4 = ba2.And(ba3);
                        Assert.False(ba4.Get(0)); //"Err_12! Expected ba4.Get(0) to be false"
                        Assert.True(ba4.Get(1)); //"Err_13! Expected ba4.Get(1) to be true"
                        Assert.False(ba4.Get(2)); //"Err_14! Expected ba4.Get(2) to be false"
                        Assert.False(ba4.Get(4)); //"Err_15! Expected ba4.Get(4) to be false"
                        break;

                    case Operator.Or:
                        ba4 = ba2.Or(ba3);
                        Assert.True(ba4.Get(0)); //"Err_16! Expected ba4.Get(0) to be true"
                        Assert.True(ba4.Get(1)); //"Err_17! Expected ba4.Get(1) to be true"
                        Assert.True(ba4.Get(2)); //"Err_18! Expected ba4.Get(2) to be true"
                        Assert.False(ba4.Get(4)); //"Err_19! Expected ba4.Get(4) to be false"
                        break;
                }


                // []  Size stress cases.
                ba2 = new BitArray(0x1000F, false);
                ba3 = new BitArray(0x1000F, false);

                ba2.Set(0x10000, true); // The bit for 1 (2^0).
                ba2.Set(0x10001, true); // The bit for 2 (2^1).

                ba3.Set(0x10001, true); // The bit for 2 (2^1).

                switch (op)
                {
                    case Operator.Xor:
                        ba4 = ba2.Xor(ba3);
                        Assert.True(ba4.Get(0x10000)); //"Err_20! Expected ba4.Get(0x10000) to be true"
                        Assert.False(ba4.Get(0x10001)); //"Err_21! Expected ba4.Get(0x10001) to be false"
                        Assert.False(ba4.Get(0x10002)); //"Err_22! Expected ba4.Get(0x10002) to be false"
                        Assert.False(ba4.Get(0x10004)); //"Err_23! Expected ba4.Get(0x10004) to be false"
                        break;

                    case Operator.And:
                        ba4 = ba2.And(ba3);
                        Assert.False(ba4.Get(0x10000)); //"Err_24! Expected ba4.Get(0x10000) to be false"
                        Assert.True(ba4.Get(0x10001)); //"Err_25! Expected ba4.Get(0x10001) to be true"
                        Assert.False(ba4.Get(0x10002)); //"Err_26! Expected ba4.Get(0x10002) to be false"
                        Assert.False(ba4.Get(0x10004)); //"Err_27! Expected ba4.Get(0x10004) to be false"
                        break;

                    case Operator.Or:
                        ba4 = ba2.Or(ba3);
                        Assert.True(ba4.Get(0x10000)); //"Err_28! Expected ba4.Get(0x10000) to be true"
                        Assert.True(ba4.Get(0x10001)); //"Err_29! Expected ba4.Get(0x10001) to be true"
                        Assert.False(ba4.Get(0x10002)); //"Err_30! Expected ba4.Get(0x10002) to be false"
                        Assert.False(ba4.Get(0x10004)); //"Err_31! Expected ba4.Get(0x10004) to be false"
                        break;
                }
            }
Exemplo n.º 22
0
Arquivo: Tab.cs Projeto: ggrov/tacny
	void CheckRes(Node p, bool rslvAllowed) {
		while (p != null) {
			switch (p.typ) {
				case Node.alt:
					BitArray expected = new BitArray(terminals.Count);
					for (Node q = p; q != null; q = q.down)
						expected.Or(Expected0(q.sub, curSy));
					BitArray soFar = new BitArray(terminals.Count);
					for (Node q = p; q != null; q = q.down) {
						if (q.sub.typ == Node.rslv) {
						  BitArray fs = Expected(q.sub.next, curSy);
							if (Sets.Intersect(fs, soFar))
								ResErr(q.sub, "Warning: Resolver will never be evaluated. " +
								"Place it at previous conflicting alternative.");
							if (!Sets.Intersect(fs, expected))
								ResErr(q.sub, "Warning: Misplaced resolver: no LL(1) conflict.");
						} else soFar.Or(Expected(q.sub, curSy));
						CheckRes(q.sub, true);
					}
					break;
				case Node.iter: case Node.opt:
					if (p.sub.typ == Node.rslv) {
						BitArray fs = First(p.sub.next);
						BitArray fsNext = Expected(p.next, curSy);
						if (!Sets.Intersect(fs, fsNext)) 
							ResErr(p.sub, "Warning: Misplaced resolver: no LL(1) conflict.");
					}
					CheckRes(p.sub, true);
					break;
				case Node.rslv:
					if (!rslvAllowed)
						ResErr(p, "Warning: Misplaced resolver: no alternative.");
					break;
			}
			if (p.up) break;
			p = p.next;
			rslvAllowed = false;
		}
	}
Exemplo n.º 23
0
        public TournamentBracketGump(Mobile from, Tournament tourny, TournyBracketGumpType type, ArrayList list, int page, object obj)
            : base(50, 50)
        {
            this.m_From = from;
            this.m_Tournament = tourny;
            this.m_Type = type;
            this.m_List = list;
            this.m_Page = page;
            this.m_Object = obj;
            this.m_PerPage = 12;

            switch ( type )
            {
                case TournyBracketGumpType.Index:
                    {
                        this.AddPage(0);
                        this.AddBackground(0, 0, 300, 300, 9380);

                        StringBuilder sb = new StringBuilder();

                        if (tourny.TournyType == TournyType.FreeForAll)
                        {
                            sb.Append("FFA");
                        }
                        else if (tourny.TournyType == TournyType.RandomTeam)
                        {
                            sb.Append("Team");
                        }
                        else if (tourny.TournyType == TournyType.RedVsBlue)
                        {
                            sb.Append("Red v Blue");
                        }
                        else
                        {
                            for (int i = 0; i < tourny.ParticipantsPerMatch; ++i)
                            {
                                if (sb.Length > 0)
                                    sb.Append('v');

                                sb.Append(tourny.PlayersPerParticipant);
                            }
                        }

                        if (tourny.EventController != null)
                            sb.Append(' ').Append(tourny.EventController.Title);

                        sb.Append(" Tournament Bracket");

                        this.AddHtml(25, 35, 250, 20, this.Center(sb.ToString()), false, false);

                        this.AddRightArrow(25, 53, this.ToButtonID(0, 4), "Rules");
                        this.AddRightArrow(25, 71, this.ToButtonID(0, 1), "Participants");

                        if (this.m_Tournament.Stage == TournamentStage.Signup)
                        {
                            TimeSpan until = (this.m_Tournament.SignupStart + this.m_Tournament.SignupPeriod) - DateTime.Now;
                            string text;
                            int secs = (int)until.TotalSeconds;

                            if (secs > 0)
                            {
                                int mins = secs / 60;
                                secs %= 60;

                                if (mins > 0 && secs > 0)
                                    text = String.Format("The tournament will begin in {0} minute{1} and {2} second{3}.", mins, mins == 1 ? "" : "s", secs, secs == 1 ? "" : "s");
                                else if (mins > 0)
                                    text = String.Format("The tournament will begin in {0} minute{1}.", mins, mins == 1 ? "" : "s");
                                else if (secs > 0)
                                    text = String.Format("The tournament will begin in {0} second{1}.", secs, secs == 1 ? "" : "s");
                                else
                                    text = "The tournament will begin shortly.";
                            }
                            else
                            {
                                text = "The tournament will begin shortly.";
                            }

                            this.AddHtml(25, 92, 250, 40, text, false, false);
                        }
                        else
                        {
                            this.AddRightArrow(25, 89, this.ToButtonID(0, 2), "Rounds");
                        }

                        break;
                    }
                case TournyBracketGumpType.Rules_Info:
                    {
                        Ruleset ruleset = tourny.Ruleset;
                        Ruleset basedef = ruleset.Base;

                        BitArray defs;

                        if (ruleset.Flavors.Count > 0)
                        {
                            defs = new BitArray(basedef.Options);

                            for (int i = 0; i < ruleset.Flavors.Count; ++i)
                                defs.Or(((Ruleset)ruleset.Flavors[i]).Options);
                        }
                        else
                        {
                            defs = basedef.Options;
                        }

                        int changes = 0;

                        BitArray opts = ruleset.Options;

                        for (int i = 0; i < opts.Length; ++i)
                        {
                            if (defs[i] != opts[i])
                                ++changes;
                        }

                        this.AddPage(0);
                        this.AddBackground(0, 0, 300, 60 + 18 + 20 + 20 + 20 + 8 + 20 + (ruleset.Flavors.Count * 18) + 4 + 20 + (changes * 22) + 6, 9380);

                        this.AddLeftArrow(25, 11, this.ToButtonID(0, 0));
                        this.AddHtml(25, 35, 250, 20, this.Center("Rules"), false, false);

                        int y = 53;

                        string groupText = null;

                        switch ( tourny.GroupType )
                        {
                            case GroupingType.HighVsLow:
                                groupText = "High vs Low";
                                break;
                            case GroupingType.Nearest:
                                groupText = "Closest opponent";
                                break;
                            case GroupingType.Random:
                                groupText = "Random";
                                break;
                        }

                        this.AddHtml(35, y, 190, 20, String.Format("Grouping: {0}", groupText), false, false);
                        y += 20;

                        string tieText = null;

                        switch ( tourny.TieType )
                        {
                            case TieType.Random:
                                tieText = "Random";
                                break;
                            case TieType.Highest:
                                tieText = "Highest advances";
                                break;
                            case TieType.Lowest:
                                tieText = "Lowest advances";
                                break;
                            case TieType.FullAdvancement:
                                tieText = (tourny.ParticipantsPerMatch == 2 ? "Both advance" : "Everyone advances");
                                break;
                            case TieType.FullElimination:
                                tieText = (tourny.ParticipantsPerMatch == 2 ? "Both eliminated" : "Everyone eliminated");
                                break;
                        }

                        this.AddHtml(35, y, 190, 20, String.Format("Tiebreaker: {0}", tieText), false, false);
                        y += 20;

                        string sdText = "Off";

                        if (tourny.SuddenDeath > TimeSpan.Zero)
                        {
                            sdText = String.Format("{0}:{1:D2}", (int)tourny.SuddenDeath.TotalMinutes, tourny.SuddenDeath.Seconds);

                            if (tourny.SuddenDeathRounds > 0)
                                sdText = String.Format("{0} (first {1} rounds)", sdText, tourny.SuddenDeathRounds);
                            else
                                sdText = String.Format("{0} (all rounds)", sdText);
                        }

                        this.AddHtml(35, y, 240, 20, String.Format("Sudden Death: {0}", sdText), false, false);
                        y += 20;

                        y += 8;

                        this.AddHtml(35, y, 190, 20, String.Format("Ruleset: {0}", basedef.Title), false, false);
                        y += 20;

                        for (int i = 0; i < ruleset.Flavors.Count; ++i, y += 18)
                            this.AddHtml(35, y, 190, 20, String.Format(" + {0}", ((Ruleset)ruleset.Flavors[i]).Title), false, false);

                        y += 4;

                        if (changes > 0)
                        {
                            this.AddHtml(35, y, 190, 20, "Modifications:", false, false);
                            y += 20;

                            for (int i = 0; i < opts.Length; ++i)
                            {
                                if (defs[i] != opts[i])
                                {
                                    string name = ruleset.Layout.FindByIndex(i);

                                    if (name != null) // sanity
                                    {
                                        this.AddImage(35, y, opts[i] ? 0xD3 : 0xD2);
                                        this.AddHtml(60, y, 165, 22, name, false, false);
                                    }

                                    y += 22;
                                }
                            }
                        }
                        else
                        {
                            this.AddHtml(35, y, 190, 20, "Modifications: None", false, false);
                            y += 20;
                        }

                        break;
                    }
                case TournyBracketGumpType.Participant_List:
                    {
                        this.AddPage(0);
                        this.AddBackground(0, 0, 300, 300, 9380);

                        if (this.m_List == null)
                            this.m_List = new ArrayList(tourny.Participants);

                        this.AddLeftArrow(25, 11, this.ToButtonID(0, 0));
                        this.AddHtml(25, 35, 250, 20, this.Center(String.Format("{0} Participant{1}", m_List.Count, m_List.Count == 1 ? "" : "s")), false, false);

                        int index, count, y;
                        this.StartPage(out index, out count, out y, 12);

                        for (int i = 0; i < count; ++i, y += 18)
                        {
                            TournyParticipant part = (TournyParticipant)this.m_List[index + i];
                            string name = part.NameList;

                            if (this.m_Tournament.TournyType != TournyType.Standard && part.Players.Count == 1)
                            {
                                PlayerMobile pm = part.Players[0] as PlayerMobile;

                                if (pm != null && pm.DuelPlayer != null)
                                    name = this.Color(name, pm.DuelPlayer.Eliminated ? 0x6633333 : 0x336666);
                            }

                            this.AddRightArrow(25, y, this.ToButtonID(2, index + i), name);
                        }

                        break;
                    }
                case TournyBracketGumpType.Participant_Info:
                    {
                        TournyParticipant part = obj as TournyParticipant;

                        if (part == null)
                            break;

                        this.AddPage(0);
                        this.AddBackground(0, 0, 300, 60 + 18 + 20 + (part.Players.Count * 18) + 20 + 20 + 160, 9380);

                        this.AddLeftArrow(25, 11, this.ToButtonID(0, 1));
                        this.AddHtml(25, 35, 250, 20, this.Center("Participants"), false, false);

                        int y = 53;

                        this.AddHtml(25, y, 200, 20, part.Players.Count == 1 ? "Players" : "Team", false, false);
                        y += 20;

                        for (int i = 0; i < part.Players.Count; ++i)
                        {
                            Mobile mob = (Mobile)part.Players[i];
                            string name = mob.Name;

                            if (this.m_Tournament.TournyType != TournyType.Standard)
                            {
                                PlayerMobile pm = mob as PlayerMobile;

                                if (pm != null && pm.DuelPlayer != null)
                                    name = this.Color(name, pm.DuelPlayer.Eliminated ? 0x6633333 : 0x336666);
                            }

                            this.AddRightArrow(35, y, this.ToButtonID(4, i), name);
                            y += 18;
                        }

                        this.AddHtml(25, y, 200, 20, String.Format("Free Advances: {0}", part.FreeAdvances == 0 ? "None" : part.FreeAdvances.ToString()), false, false);
                        y += 20;

                        this.AddHtml(25, y, 200, 20, "Log:", false, false);
                        y += 20;

                        StringBuilder sb = new StringBuilder();

                        for (int i = 0; i < part.Log.Count; ++i)
                        {
                            if (sb.Length > 0)
                                sb.Append("<br>");

                            sb.Append(part.Log[i]);
                        }

                        if (sb.Length == 0)
                            sb.Append("Nothing logged yet.");

                        this.AddHtml(25, y, 250, 150, this.Color(sb.ToString(), BlackColor32), false, true);

                        break;
                    }
                case TournyBracketGumpType.Player_Info:
                    {
                        this.AddPage(0);
                        this.AddBackground(0, 0, 300, 300, 9380);

                        this.AddLeftArrow(25, 11, this.ToButtonID(0, 3));
                        this.AddHtml(25, 35, 250, 20, this.Center("Participants"), false, false);

                        Mobile mob = obj as Mobile;

                        if (mob == null)
                            break;

                        Ladder ladder = Ladder.Instance;
                        LadderEntry entry = (ladder == null ? null : ladder.Find(mob));

                        this.AddHtml(25, 53, 250, 20, String.Format("Name: {0}", mob.Name), false, false);
                        this.AddHtml(25, 73, 250, 20, String.Format("Guild: {0}", mob.Guild == null ? "None" : mob.Guild.Name + " [" + mob.Guild.Abbreviation + "]"), false, false);
                        this.AddHtml(25, 93, 250, 20, String.Format("Rank: {0}", entry == null ? "N/A" : LadderGump.Rank(entry.Index + 1)), false, false);
                        this.AddHtml(25, 113, 250, 20, String.Format("Level: {0}", entry == null ? 0 : Ladder.GetLevel(entry.Experience)), false, false);
                        this.AddHtml(25, 133, 250, 20, String.Format("Wins: {0:N0}", entry == null ? 0 : entry.Wins), false, false);
                        this.AddHtml(25, 153, 250, 20, String.Format("Losses: {0:N0}", entry == null ? 0 : entry.Losses), false, false);

                        break;
                    }
                case TournyBracketGumpType.Round_List:
                    {
                        this.AddPage(0);
                        this.AddBackground(0, 0, 300, 300, 9380);

                        this.AddLeftArrow(25, 11, this.ToButtonID(0, 0));
                        this.AddHtml(25, 35, 250, 20, this.Center("Rounds"), false, false);

                        if (this.m_List == null)
                            this.m_List = new ArrayList(tourny.Pyramid.Levels);

                        int index, count, y;
                        this.StartPage(out index, out count, out y, 12);

                        for (int i = 0; i < count; ++i, y += 18)
                        {
                            PyramidLevel level = (PyramidLevel)this.m_List[index + i];

                            this.AddRightArrow(25, y, this.ToButtonID(3, index + i), "Round #" + (index + i + 1));
                        }

                        break;
                    }
                case TournyBracketGumpType.Round_Info:
                    {
                        this.AddPage(0);
                        this.AddBackground(0, 0, 300, 300, 9380);

                        this.AddLeftArrow(25, 11, this.ToButtonID(0, 2));
                        this.AddHtml(25, 35, 250, 20, this.Center("Rounds"), false, false);

                        PyramidLevel level = this.m_Object as PyramidLevel;

                        if (level == null)
                            break;

                        if (this.m_List == null)
                            this.m_List = new ArrayList(level.Matches);

                        this.AddRightArrow(25, 53, this.ToButtonID(5, 0), String.Format("Free Advance: {0}", level.FreeAdvance == null ? "None" : level.FreeAdvance.NameList));

                        this.AddHtml(25, 73, 200, 20, String.Format("{0} Match{1}", m_List.Count, m_List.Count == 1 ? "" : "es"), false, false);

                        int index, count, y;
                        this.StartPage(out index, out count, out y, 10);

                        for (int i = 0; i < count; ++i, y += 18)
                        {
                            TournyMatch match = (TournyMatch)this.m_List[index + i];

                            int color = -1;

                            if (match.InProgress)
                                color = 0x336666;
                            else if (match.Context != null && match.Winner == null)
                                color = 0x666666;

                            StringBuilder sb = new StringBuilder();

                            if (this.m_Tournament.TournyType == TournyType.Standard)
                            {
                                for (int j = 0; j < match.Participants.Count; ++j)
                                {
                                    if (sb.Length > 0)
                                        sb.Append(" vs ");

                                    TournyParticipant part = (TournyParticipant)match.Participants[j];
                                    string txt = part.NameList;

                                    if (color == -1 && match.Context != null && match.Winner == part)
                                        txt = this.Color(txt, 0x336633);
                                    else if (color == -1 && match.Context != null)
                                        txt = this.Color(txt, 0x663333);

                                    sb.Append(txt);
                                }
                            }
                            else if (this.m_Tournament.EventController != null || this.m_Tournament.TournyType == TournyType.RandomTeam || this.m_Tournament.TournyType == TournyType.RedVsBlue)
                            {
                                for (int j = 0; j < match.Participants.Count; ++j)
                                {
                                    if (sb.Length > 0)
                                        sb.Append(" vs ");

                                    TournyParticipant part = (TournyParticipant)match.Participants[j];
                                    string txt;

                                    if (this.m_Tournament.EventController != null)
                                        txt = String.Format("Team {0} ({1})", this.m_Tournament.EventController.GetTeamName(j), part.Players.Count);
                                    else if (this.m_Tournament.TournyType == TournyType.RandomTeam)
                                        txt = String.Format("Team {0} ({1})", j + 1, part.Players.Count);
                                    else
                                        txt = String.Format("Team {0} ({1})", j == 0 ? "Red" : "Blue", part.Players.Count);

                                    if (color == -1 && match.Context != null && match.Winner == part)
                                        txt = this.Color(txt, 0x336633);
                                    else if (color == -1 && match.Context != null)
                                        txt = this.Color(txt, 0x663333);

                                    sb.Append(txt);
                                }
                            }
                            else if (this.m_Tournament.TournyType == TournyType.FreeForAll)
                            {
                                sb.Append("Free For All");
                            }

                            string str = sb.ToString();

                            if (color >= 0)
                                str = this.Color(str, color);

                            this.AddRightArrow(25, y, this.ToButtonID(5, index + i + 1), str);
                        }

                        break;
                    }
                case TournyBracketGumpType.Match_Info:
                    {
                        TournyMatch match = obj as TournyMatch;

                        if (match == null)
                            break;

                        int ct = (this.m_Tournament.TournyType == TournyType.FreeForAll ? 2 : match.Participants.Count);

                        this.AddPage(0);
                        this.AddBackground(0, 0, 300, 60 + 18 + 20 + 20 + 20 + (ct * 18) + 6, 9380);

                        this.AddLeftArrow(25, 11, this.ToButtonID(0, 5));
                        this.AddHtml(25, 35, 250, 20, this.Center("Rounds"), false, false);

                        this.AddHtml(25, 53, 250, 20, String.Format("Winner: {0}", match.Winner == null ? "N/A" : match.Winner.NameList), false, false);
                        this.AddHtml(25, 73, 250, 20, String.Format("State: {0}", match.InProgress ? "In progress" : match.Context != null ? "Complete" : "Waiting"), false, false);
                        this.AddHtml(25, 93, 250, 20, String.Format("Participants:"), false, false);

                        if (this.m_Tournament.TournyType == TournyType.Standard)
                        {
                            for (int i = 0; i < match.Participants.Count; ++i)
                            {
                                TournyParticipant part = (TournyParticipant)match.Participants[i];

                                this.AddRightArrow(25, 113 + (i * 18), this.ToButtonID(6, i), part.NameList);
                            }
                        }
                        else if (this.m_Tournament.EventController != null || this.m_Tournament.TournyType == TournyType.RandomTeam || this.m_Tournament.TournyType == TournyType.RedVsBlue)
                        {
                            for (int i = 0; i < match.Participants.Count; ++i)
                            {
                                TournyParticipant part = (TournyParticipant)match.Participants[i];

                                if (this.m_Tournament.EventController != null)
                                    this.AddRightArrow(25, 113 + (i * 18), this.ToButtonID(6, i), String.Format("Team {0} ({1})", m_Tournament.EventController.GetTeamName(i), part.Players.Count));
                                else if (this.m_Tournament.TournyType == TournyType.RandomTeam)
                                    this.AddRightArrow(25, 113 + (i * 18), this.ToButtonID(6, i), String.Format("Team {0} ({1})", i + 1, part.Players.Count));
                                else
                                    this.AddRightArrow(25, 113 + (i * 18), this.ToButtonID(6, i), String.Format("Team {0} ({1})", i == 0 ? "Red" : "Blue", part.Players.Count));
                            }
                        }
                        else if (this.m_Tournament.TournyType == TournyType.FreeForAll)
                        {
                            this.AddHtml(25, 113, 250, 20, "Free For All", false, false);
                        }

                        break;
                    }
            }
        }
Exemplo n.º 24
0
Arquivo: Tab.cs Projeto: ggrov/tacny
	void FindAS(Node p) { // find ANY sets
		Node a;
		while (p != null) {
			if (p.typ == Node.opt || p.typ == Node.iter) {
				FindAS(p.sub);
				a = LeadingAny(p.sub);
				if (a != null) Sets.Subtract(a.set, First(p.next));
			} else if (p.typ == Node.alt) {
				BitArray s1 = new BitArray(terminals.Count);
				Node q = p;
				while (q != null) {
					FindAS(q.sub);
					a = LeadingAny(q.sub);
					if (a != null)
						Sets.Subtract(a.set, First(q.down).Or(s1));
					else
						s1.Or(First(q.sub));
					q = q.down;
				}
			}

			// Remove alternative terminals before ANY, in the following
			// examples a and b must be removed from the ANY set:
			// [a] ANY, or {a|b} ANY, or [a][b] ANY, or (a|) ANY, or
			// A = [a]. A ANY
			if (DelNode(p)) {
				a = LeadingAny(p.next);
				if (a != null) {
					Node q = (p.typ == Node.nt) ? p.sym.graph : p.sub;
					Sets.Subtract(a.set, First(q));
				}
			}

			if (p.up) break;
			p = p.next;
		}
	}
Exemplo n.º 25
0
        public Genome MakeChild(Genome other, BitArray mask)
        {
            BitArray leftCopy = new BitArray(this.genome);
            BitArray rightCopy = new BitArray(other.genome);
            BitArray maskCopy = new BitArray(mask);

            leftCopy.And(maskCopy);
            rightCopy.And(maskCopy.Not());

            //BitArray temp2 = new BitArray(right.And(mask.Not()));
            return new Genome(leftCopy.Or(rightCopy));
        }
Exemplo n.º 26
0
 public void GetTargetStates(Action a, out BitArray targets, out Symbol endOf, out bool ctx)
 {
     // compute the set of target states
     targets = new BitArray(maxStates); endOf = null;
     ctx = false;
     for (Target t = a.target; t != null; t = t.next) {
     int stateNr = t.state.nr;
     if (stateNr <= lastSimState) targets[stateNr] = true;
     else targets.Or(MeltedSet(stateNr));
     if (t.state.endOf != null)
         if (endOf == null || endOf == t.state.endOf)
             endOf = t.state.endOf;
         else
             errors.SemErr("Tokens " + endOf.name + " and " + t.state.endOf.name + " cannot be distinguished");
     if (t.state.ctx) {
         ctx = true;
         // The following check seems to be unnecessary. It reported an error
         // if a symbol + context was the prefix of another symbol, e.g.
         //   s1 = "a" "b" "c".
         //   s2 = "a" CONTEXT("b").
         // But this is ok.
         // if (t.state.endOf != null) {
         //   Console.WriteLine("Ambiguous context clause");
         //	 errors.count++;
         // }
     }
     }
 }
Exemplo n.º 27
0
        // IfStmt
        public override bool Walk(IfStatement node) {
            BitArray result = new BitArray(_bits.Length, true);
            BitArray save = _bits;

            _bits = new BitArray(_bits.Length);

            foreach (IfStatementTest ist in node.Tests) {
                // Set the initial branch value to bits
                _bits.SetAll(false);
                _bits.Or(save);

                // Flow the test first
                ist.Test.Walk(this);
                // Flow the body
                ist.Body.Walk(this);
                // Intersect
                result.And(_bits);
            }

            // Set the initial branch value to bits
            _bits.SetAll(false);
            _bits.Or(save);

            if (node.ElseStatement != null) {
                // Flow the else_
                node.ElseStatement.Walk(this);
            }

            // Intersect
            result.And(_bits);

            _bits = save;

            // Remember the result
            _bits.SetAll(false);
            _bits.Or(result);
            return false;
        }
Exemplo n.º 28
0
        private ContingencyTableNode MakeContabLeafList(Varset variables, BitArray records)
        {
            Varset variablesCp = new Varset(variables);
            if (variablesCp.Equals(zero))
            {
                int count = 0;
                for (int i = 0; i < records.Count; i++)
                {
                    if (records[i])
                    {
                        count += 1;
                    }
                }
                return new ContingencyTableNode(count, 0, 1);
            }

            int firstIndex = variables.FindFirst();
            int cardinality = network.GetCardinality(firstIndex);
            ContingencyTableNode ct = new ContingencyTableNode(0, cardinality, 0);
            variablesCp.Set(firstIndex, false);
            Varset remainingVariables = new Varset(variablesCp);
            for (int k = 0; k < cardinality; k++)
            {
                BitArray r = new BitArray(recordCount);
                r = r.Or(records);
                r = r.And(consistentRecords[firstIndex][k]);

                int count = 0;
                for (int i = 0; i < r.Count; i++)
                {
                    if (r[i])
                    {
                        count += 1;
                    }
                }
                if (count > 0)
                {
                    ContingencyTableNode child = MakeContabLeafList(remainingVariables, r);
                    ct.SetChild(k, child);
                    ct.LeafCount += child.LeafCount;
                }
            }
            return ct;
        }
Exemplo n.º 29
0
        // TryStmt
        public override bool Walk(TryStatement node) {
            BitArray save = _bits;
            _bits = new BitArray(_bits);

            // Flow the body
            node.Body.Walk(this);

            if (node.Else != null) {
                // Else is flown only after completion of Try with same bits
                node.Else.Walk(this);
            }


            if (node.Handlers != null) {
                foreach (TryStatementHandler tsh in node.Handlers) {
                    // Restore to saved state
                    _bits.SetAll(false);
                    _bits.Or(save);

                    // Flow the test
                    if (tsh.Test != null) {
                        tsh.Test.Walk(this);
                    }

                    // Define the target
                    if (tsh.Target != null) {
                        tsh.Target.Walk(_fdef);
                    }

                    // Flow the body
                    tsh.Body.Walk(this);
                }
            }

            _bits = save;

            if (node.Finally != null) {
                // Flow finally - this executes no matter what
                node.Finally.Walk(this);
            }

            return false;
        }
Exemplo n.º 30
0
            public static void BitArray_OrTest_Negative()
            {
                // []  ArgumentException, length of arrays is different
                BitArray ba2 = new BitArray(11, false);
                BitArray ba3 = new BitArray(6, false);

                Assert.Throws<ArgumentException>(delegate { ba2.Or(ba3); }); //"Err_35! wrong exception thrown."

                // []  ArgumentNullException, null.
                ba2 = new BitArray(6, false);
                ba3 = null;

                Assert.Throws<ArgumentNullException>(delegate { ba2.Or(ba3); }); //"Err_36! wrong exception thrown."
            }
Exemplo n.º 31
0
 void CheckAlts(Node p)
 {
     BitArray s1, s2;
     while (p != null) {
     if (p.typ == Node.alt) {
         List<Node> alts = new List<Node>();
         for (Node q = p; q != null; q = q.down)
             alts.Add(q);
         alts.Reverse(); // check alternatives backwards so that conflicts are
         // detected at first alternative
         s1 = new BitArray(terminals.Count);
         foreach (Node q in alts) {
             s2 = Expected0(q.sub, curSy);
             if (q.sub.typ != Node.expectedConflict)
                 CheckOverlap(s1, s2, 1, q);
             s1.Or(s2);
             CheckAlts(q.sub);
         }
     } else if (p.typ == Node.opt || p.typ == Node.iter) {
         if (DelSubGraph(p.sub)) LL1Error(4, null, p); // e.g. [[...]]
         else if (p.sub.typ != Node.expectedConflict) {
             s2 = Expected(p.next, curSy);
             if (p.sub.typ == Node.alt) {
                 // resolver extraction is possible here
                 s1 = new BitArray(terminals.Count);
                 for (Node q = p.sub; q != null; q = q.down) {
                     if (q.sub.typ == Node.rslv) {
                         if (Sets.Intersect(s2, Expected(q.sub, curSy)))
                             q.sub.resolverWasExtracted = true;
                     } else {
                         s1.Or(Expected0(q.sub, curSy));
                     }
                 }
             } else {
                 s1 = Expected0(p.sub, curSy);
             }
             CheckOverlap(s1, s2, 2, p);
         }
         CheckAlts(p.sub);
     } else if (p.typ == Node.any) {
         if (Sets.Elements(p.set) == 0) LL1Error(3, null, p);
         // e.g. {ANY} ANY or [ANY] ANY or ( ANY | ANY )
     }
     if (p.up) break;
     p = p.next;
     }
 }
Exemplo n.º 32
0
        public AcceptTeamGump(Mobile from, Mobile requested, Tournament tourny, Mobile registrar, ArrayList players)
            : base(50, 50)
        {
            this.m_From = from;
            this.m_Requested = requested;
            this.m_Tournament = tourny;
            this.m_Registrar = registrar;
            this.m_Players = players;

            this.m_Active = true;

            #region Rules
            Ruleset ruleset = tourny.Ruleset;
            Ruleset basedef = ruleset.Base;

            int height = 185 + 35 + 60 + 12;

            int changes = 0;

            BitArray defs;

            if (ruleset.Flavors.Count > 0)
            {
                defs = new BitArray(basedef.Options);

                for (int i = 0; i < ruleset.Flavors.Count; ++i)
                    defs.Or(((Ruleset)ruleset.Flavors[i]).Options);

                height += ruleset.Flavors.Count * 18;
            }
            else
            {
                defs = basedef.Options;
            }

            BitArray opts = ruleset.Options;

            for (int i = 0; i < opts.Length; ++i)
            {
                if (defs[i] != opts[i])
                    ++changes;
            }

            height += (changes * 22);

            height += 10 + 22 + 25 + 25;
            #endregion

            this.Closable = false;

            this.AddPage(0);

            this.AddBackground(1, 1, 398, height, 3600);

            this.AddImageTiled(16, 15, 369, height - 29, 3604);
            this.AddAlphaRegion(16, 15, 369, height - 29);

            this.AddImage(215, -43, 0xEE40);

            StringBuilder sb = new StringBuilder();

            if (tourny.TournyType == TournyType.FreeForAll)
            {
                sb.Append("FFA");
            }
            else if (tourny.TournyType == TournyType.RandomTeam)
            {
                sb.Append(tourny.ParticipantsPerMatch);
                sb.Append("-Team");
            }
            else if (tourny.TournyType == TournyType.RedVsBlue)
            {
                sb.Append("Red v Blue");
            }
            else
            {
                for (int i = 0; i < tourny.ParticipantsPerMatch; ++i)
                {
                    if (sb.Length > 0)
                        sb.Append('v');

                    sb.Append(tourny.PlayersPerParticipant);
                }
            }

            if (tourny.EventController != null)
                sb.Append(' ').Append(tourny.EventController.Title);

            sb.Append(" Tournament Invitation");

            this.AddBorderedText(22, 22, 294, 20, this.Center(sb.ToString()), LabelColor32, BlackColor32);

            this.AddBorderedText(22, 50, 294, 40,
                String.Format("You have been asked to partner with {0} in a tournament. Do you accept?", from.Name),
                0xB0C868, BlackColor32);

            this.AddImageTiled(32, 88, 264, 1, 9107);
            this.AddImageTiled(42, 90, 264, 1, 9157);

            #region Rules
            int y = 100;

            string groupText = null;

            switch ( tourny.GroupType )
            {
                case GroupingType.HighVsLow:
                    groupText = "High vs Low";
                    break;
                case GroupingType.Nearest:
                    groupText = "Closest opponent";
                    break;
                case GroupingType.Random:
                    groupText = "Random";
                    break;
            }

            this.AddBorderedText(35, y, 190, 20, String.Format("Grouping: {0}", groupText), LabelColor32, BlackColor32);
            y += 20;

            string tieText = null;

            switch ( tourny.TieType )
            {
                case TieType.Random:
                    tieText = "Random";
                    break;
                case TieType.Highest:
                    tieText = "Highest advances";
                    break;
                case TieType.Lowest:
                    tieText = "Lowest advances";
                    break;
                case TieType.FullAdvancement:
                    tieText = (tourny.ParticipantsPerMatch == 2 ? "Both advance" : "Everyone advances");
                    break;
                case TieType.FullElimination:
                    tieText = (tourny.ParticipantsPerMatch == 2 ? "Both eliminated" : "Everyone eliminated");
                    break;
            }

            this.AddBorderedText(35, y, 190, 20, String.Format("Tiebreaker: {0}", tieText), LabelColor32, BlackColor32);
            y += 20;

            string sdText = "Off";

            if (tourny.SuddenDeath > TimeSpan.Zero)
            {
                sdText = String.Format("{0}:{1:D2}", (int)tourny.SuddenDeath.TotalMinutes, tourny.SuddenDeath.Seconds);

                if (tourny.SuddenDeathRounds > 0)
                    sdText = String.Format("{0} (first {1} rounds)", sdText, tourny.SuddenDeathRounds);
                else
                    sdText = String.Format("{0} (all rounds)", sdText);
            }

            this.AddBorderedText(35, y, 240, 20, String.Format("Sudden Death: {0}", sdText), LabelColor32, BlackColor32);
            y += 20;

            y += 6;
            this.AddImageTiled(32, y - 1, 264, 1, 9107);
            this.AddImageTiled(42, y + 1, 264, 1, 9157);
            y += 6;

            this.AddBorderedText(35, y, 190, 20, String.Format("Ruleset: {0}", basedef.Title), LabelColor32, BlackColor32);
            y += 20;

            for (int i = 0; i < ruleset.Flavors.Count; ++i, y += 18)
                this.AddBorderedText(35, y, 190, 20, String.Format(" + {0}", ((Ruleset)ruleset.Flavors[i]).Title), LabelColor32, BlackColor32);

            y += 4;

            if (changes > 0)
            {
                this.AddBorderedText(35, y, 190, 20, "Modifications:", LabelColor32, BlackColor32);
                y += 20;

                for (int i = 0; i < opts.Length; ++i)
                {
                    if (defs[i] != opts[i])
                    {
                        string name = ruleset.Layout.FindByIndex(i);

                        if (name != null) // sanity
                        {
                            this.AddImage(35, y, opts[i] ? 0xD3 : 0xD2);
                            this.AddBorderedText(60, y, 165, 22, name, LabelColor32, BlackColor32);
                        }

                        y += 22;
                    }
                }
            }
            else
            {
                this.AddBorderedText(35, y, 190, 20, "Modifications: None", LabelColor32, BlackColor32);
                y += 20;
            }
            #endregion

            y += 8;
            this.AddImageTiled(32, y - 1, 264, 1, 9107);
            this.AddImageTiled(42, y + 1, 264, 1, 9157);
            y += 8;

            this.AddRadio(24, y, 9727, 9730, true, 1);
            this.AddBorderedText(60, y + 5, 250, 20, "Yes, I will join them.", LabelColor32, BlackColor32);
            y += 35;

            this.AddRadio(24, y, 9727, 9730, false, 2);
            this.AddBorderedText(60, y + 5, 250, 20, "No, I do not wish to fight.", LabelColor32, BlackColor32);
            y += 35;

            this.AddRadio(24, y, 9727, 9730, false, 3);
            this.AddBorderedText(60, y + 5, 270, 20, "No, most certainly not. Do not ask again.", LabelColor32, BlackColor32);
            y += 35;

            y -= 3;
            this.AddButton(314, y, 247, 248, 1, GumpButtonType.Reply, 0);

            Timer.DelayCall(TimeSpan.FromSeconds(15.0), new TimerCallback(AutoReject));
        }
Exemplo n.º 33
0
 public static void Or(BitArray b1, BitArray b2)
 {
     if (b1.Length > b2.Length)
     {
         b2.Length = b1.Length;
     }
     else if (b2.Length > b1.Length)
     {
         b1.Length = b2.Length;
     }
     b1.Or(b2);
 }