Add() public méthode

Adds an object to the end of the List.
public Add ( System valueToInsert ) : bool
valueToInsert System The value to insert in the array list.
Résultat bool
Exemple #1
0
        /// <summary>  Adds a card to the unpaired stack data structure in score and rating sorted
        /// order
        ///
        /// </summary>
        /// <param name="card"> Card to add
        /// </param>
        public virtual void  addCardSorted(Card card)
        {
            System.Collections.IEnumerator iterator = unpairedStack.ListIterator();

            object[] obj = unpairedStack.ListSelection();

            System.Collections.ArrayList lst = new System.Collections.ArrayList();

            lst.AddRange(obj);
            Card temp;

            for (int i = 0; i < lst.Count; i++)
            {
                temp = (Card)lst[i];
                if (temp.pairingScore < card.pairingScore || (temp.pairingScore == card.pairingScore && temp.player.rating < card.player.rating))
                {
                    lst.Insert(i - 1, card);
                    //iterator.previous();
                    //iterator.add(card);
                    return;
                }
            }

            unpairedStack.Add(card);

            //UPGRADE_TODO: Method 'java.util.ListIterator.hasNext' was converted to 'System.Collections.IEnumerator.MoveNext' which has a different behavior. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1073_javautilListIteratorhasNext"'
            while (iterator.MoveNext())
            {
                //UPGRADE_TODO: Method 'java.util.ListIterator.next' was converted to 'System.Collections.IEnumerator.Current' which has a different behavior. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1073_javautilListIteratornext"'
                temp = (Card)iterator.Current;
                if (temp.pairingScore < card.pairingScore || (temp.pairingScore == card.pairingScore && temp.player.rating < card.player.rating))
                {
                    //UPGRADE_ISSUE: Method 'java.util.ListIterator.previous' was not converted. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1000_javautilListIteratorprevious"'
                    //iterator.previous();
                    //UPGRADE_ISSUE: Method 'java.util.ListIterator.add' was not converted. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1000_javautilListIteratoradd_javalangObject"'
                    //iterator.add(card);
                    return;
                }
            }
            //we never added, so just append
            //unpairedStack.Add(card);
        }
Exemple #2
0
        /// <summary>  Pair the next round. Returns false if no legal pairing seems possible of
        ///
        /// </summary>
        /// <returns>    Description of the Return Value
        /// </returns>
        public virtual bool pairNextRound()
        {
            Pairing pairing;

            prepareNextRound();
            int lastscore = -1;

            while (!unpairedStack.IsEmpty())
            {
                currentPlayer = (Card)unpairedStack.RemoveFirst();
                //get highest rated unpaired player
                pairing = pairCurrentPlayer();
                //try to pair
                if (pairing != null)
                {
                    //we found a pairing
                    pairedStack.Add(pairing);                     //add the pairing to the paired stack
                    if (debug)
                    {
                        System.Console.Out.WriteLine("got pairing");
                    }
                    continue;
                    //continue with next player
                }
                //current player was not pairable
                //forget list of failed pairings for the current player since a previous pairing will have to be undone to continue
                currentPlayer.alreadyTried.Clear();
                unpairedStack.Insert(0, currentPlayer);
                //replace this player back to the front of the unpaired stack
                if (pairedStack.IsEmpty())
                {
                    //no pairings to undo
                    if (!pairdown)
                    {
                        pairdown = true;
                        continue;                         //just try to repair everyone
                    }
                    //huge honking error here!! We can't pair!
                    if (debug)
                    {
                        System.Console.Out.WriteLine("No legal pairings!");
                    }
                    return(false);
                }
                pairing = (Pairing)pairedStack.RemoveLast();
                //undo the more recent pairing
                if (debug)
                {
                    System.Console.Out.WriteLine("Undoing pairing " + pairing.playerToPair.pairingNumber + ":" + pairing.opponent.pairingNumber);
                }
                //The playerToPair is still the currentPlayer being processed, so mark this opponent as already tried for pairing

                pairing.PlayerToPair.alreadyTried.Add(pairing.Opponent);
                //pairing.PlayerToPair.alreadyTried.add(pairing.opponent);
                //The opponent may have already gone through some pairing attempts, but since we are breaking this pairing we must forget them all
                pairing.opponent.alreadyTried.Clear();
                addCardSorted(pairing.opponent);
                //replace the failed opponent pairing onto the unpaired stack in score and rating order

                /*
                 * The playerToPair from the last pairing is the highest rated player of the highest
                 * score group yet unpaired. So we push it back on to the front of unpairedStack so it will
                 * come right off again at the top of this loop. The difference is that the opponent from
                 * the broken pairing is now marked as alreadyTried and so a different pairing will be
                 * attempted
                 */
                unpairedStack.Insert(0, pairing.playerToPair);
            }
            //yeah! We found a complete set of pairings!
            finalizePairings();
            //update the pairing cards
            return(true);
            //indicate we successfully paired
        }