Ejemplo n.º 1
0
        public void fixStrategy()
        {
            Console.Write("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
            for (int i = 1; i <= StrategyNum; i++)
            {
                if (Strategies[i].GetType() == typeof(DistanceStrategy))
                {
                    DistanceStrategy strategy = (DistanceStrategy)Strategies[i];
                    int result = rnd.Next(0, 99);
                    if (result > strategy.Probability)
                    {
                        continue;
                    }
                    seat A = Locate(strategy.StudentA), B = Locate(strategy.StudentB);

                    Console.WriteLine(A.RelateStudent.Name + " " + B.RelateStudent.Name);

                    int tryout = 0;
                    while (!strategy.Varify())
                    {
                        if (tryout > 40)
                        {
                            if (strategy.Pattern == DistanceStrategy.Seperate)
                            {
                                continue;
                            }
                            Force(A, B);
                            continue;
                        }
                        tryout++;
                        Location pos  = RandomPick();
                        seat     temp = Room[pos.RowX - 1, pos.ColY - 1];

                        A.swap(temp);

                        A = temp;
                    }
                    A.Lock();
                }
            }
            for (int i = 0; i < lout.Rows; i++)
            {
                for (int j = 0; j < lout.Colums; j++)
                {
                    Room[i, j].Unlock();
                }
            }
        }
Ejemplo n.º 2
0
 public void Force(seat A, seat B)
 {
     int[] arrange = new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8 };
     int[] posRow  = new[] { 0, -1, -1, -1, 0, 0, 1, 1, 1 };
     int[] posCol  = new[] { 0, 1, 0, -1, 1, -1, 1, 0, -1 };
     for (int i = 1; i <= 8; i++)
     {
         int tar  = rnd.Next(1, 8);
         int temp = arrange[i];
         arrange[i]   = arrange[tar];
         arrange[tar] = temp;
     }
     for (int i = 1; i <= 8; i++)
     {
         if (LegalCheck(A.Row + posRow[i], A.Col + posCol[i]))
         {
             Room[A.Row + posRow[i], A.Col + posCol[i]].swap(B);
         }
     }
 }
Ejemplo n.º 3
0
        private void Setup()
        {
            Room = new seat[lout.Rows, lout.Colums];
            for (int i = 0; i < lout.Rows; i++)
            {
                for (int j = 0; j < lout.Colums; j++)
                {
                    Room[i, j] = new seat
                    {
                        Height = stuHei,
                        Width  = stuWid,
                        HorizontalAlignment = HorizontalAlignment.Left,
                        VerticalAlignment   = VerticalAlignment.Top,
                        Row = i + 1,
                        Col = j + 1
                    };

                    int temp = GetAbs(i + 1, j + 1);


                    Room[i, j].Setup(Students[temp]);
                    if (Students[temp] != null)
                    {
                        Students[temp].SetPosition(i + 1, j + 1);
                    }

                    if (!lout.Filling[i + 1, j + 1]) //如果当前位置应为空,则将位置标记,当有正常位置为空时调换
                    {
                        Room[i, j].IsEnabled = false;
                    }
                    else if (Students[temp] == null)
                    {
                        seat tempSeat = WrongPlace();
                        tempSeat.swap(Room[i, j], false);
                        Room[i, j].RelateStudent.SetPosition(i + 1, j + 1);
                    }

                    if (i == 0 && j == 0)
                    {
                        Room[i, j].Margin = new Thickness(initWid, initHei, 0, 0);
                    }
                    else
                    {
                        if (i == 0)
                        {
                            Room[i, j].Margin =
                                new Thickness(Room[i, j - 1].Margin.Left + Room[i, j - 1].body.Width + gapWid, initHei,
                                              0,
                                              0);
                        }
                        else if (j == 0)
                        {
                            Room[i, j].Margin = new Thickness(initWid,
                                                              Room[i - 1, j].Margin.Top + Room[i - 1, j].body.Height + gapHei, 0, 0);
                        }
                        else
                        {
                            Room[i, j].Margin =
                                new Thickness(Room[0, j - 1].Margin.Left + Room[0, j - 1].body.Width + gapWid,
                                              Room[i, 0].Margin.Top, 0, 0);
                        }
                    }

                    Board.Children.Add(Room[i, j]);
                    init.IsEnabled = false;
                }
            }
        }