Exemplo n.º 1
0
        public static void findPlace(Player x)
        {
            //Console.WriteLine ("findPlace(" + x.Number + ")");
            Player y = start;
            while (true) {
                // Volgende in layer is niet groter dan x
                if (y.Next.Score <= x.Score) {
                    y = y.Next;

                // Zo niet, ga naar onder
                } else {
                    // Onderste laag is bereikt
                    if (y.Down == null) {
                        addBetween (y, x, y.Next);
                        addSkips (x);
                        return;
                    // Ga verder naar onder
                    } else {
                        //if (y.Number != -2) {
                            y.Rank++;
                        //}
                        y = y.Down;
                    }
                }
            }
        }
Exemplo n.º 2
0
 public static void addBetween(Player w, Player x, Player y)
 {
     //Console.WriteLine ("addBetween(" + w.Number + ", " + x.Number + ", " + y.Number + ")");
     x.Previous = w;
     x.Next = y;
     y.Previous = x;
     w.Next = x;
 }
Exemplo n.º 3
0
 public static void addPlayer(int playerNumber, int score)
 {
     //Console.WriteLine ("addPlayer(" + playerNumber + ", " + score + ")");
     Player x = new Player (playerNumber, score);
     x.Rank = 1;
     playerList [playerNumber] = x;
     findPlace (x);
     players++;
 }
Exemplo n.º 4
0
        public static void addSkips(Player x)
        {
            //Console.WriteLine ("addSkips(" + x.Number + ")");
            while (layerUp ()) {
                Player z = new Player (x.Number, x.Score);
                Player y = predecessorUp (x);
                addBetween (y, z, y.Next);
                z.Down = x;
                x.Up = z;

                calculateRank (z);
                x = z;
            }
        }
Exemplo n.º 5
0
        public static void calculateRank(Player x)
        {
            //Console.WriteLine ("calculateRank(" + x.Number + ")");
            Player layerDown = x.Down;
            int i = layerDown.Rank;

            while (layerDown.Next.Up == null) {
                i += layerDown.Next.Rank;
                layerDown = layerDown.Next;
            }
            x.Rank =
                i;
            //if (x.Previous.Number != -2) {
                x.Previous.Rank -= i;
            //}
        }
Exemplo n.º 6
0
        public static void printPart(int playerNumber)
        {
            //Console.WriteLine ("printPart(" + playerNumber + ")");
            Player x = playerList [playerNumber];

            Player[] list = new Player[10];
            int i = 0;
            while (x.Next.Number != -1 && i < 5) {
                x = x.Next;
                list [4 - i] = x;
                i++;
            }
            i = 0;
            x = playerList [playerNumber];
            list [5] = x;
            while (x.Previous.Number != -2 && i < 4) {
                x = x.Previous;
                list [6 + i] = x;
                i++;

            }
            foreach (Player p in list) {
                if (p != null) {
                    Console.WriteLine (p.Number);
                }
            }
        }
Exemplo n.º 7
0
 public static Player predecessorUp(Player x)
 {
     //Console.WriteLine ("predecessorUp(" + x.Number + ")");
     Player y = x.Previous;
     while (y.Up == null && y.Number != -1) {
         y = y.Previous;
     }
     return y.Up;
 }
Exemplo n.º 8
0
        public static void Main(string[] args)
        {
            Player prevL = null;
            Player prevR = null;

            for (int i = 0; i < 1000; i++) {

                Player L = new Player (-2, -1);
                Player R = new Player (-1, 10000000);
                L.Rank = 1;

                if (i == 0) {
                    start = L;
                } else {
                    prevL.Down = L;
                    prevR.Down = R;
                }

                L.Up = prevL;
                R.Up = prevR;

                L.Next = R;
                R.Previous = L;

                prevL = L;
                prevR = R;
            }

            players = 0;
            string s;
            while ((s = Console.ReadLine ()) != null && !s.Equals("")) {
                parse (s);
            }
        }