Пример #1
0
        internal void SetMatrix(AdaptiveSelector.CpeMatrix cpeMatrix)
        {
            labelBlank.Visibility = System.Windows.Visibility.Collapsed;
            int    cols      = cpeMatrix.GetColumnCount();
            int    rows      = cpeMatrix.GetRowCount();
            double colWidth  = this.Width / (cols - 1);
            double rowHeight = this.Height / (rows - 1);

            ColumnDefinition cd;
            RowDefinition    rd;

            for (int x = 0; x < cols; x++)
            {
                cd       = new ColumnDefinition();
                cd.Width = new GridLength(colWidth, GridUnitType.Star);
                mainGrid.ColumnDefinitions.Add(cd);
            }
            for (int x = 0; x < rows; x++)
            {
                rd        = new RowDefinition();
                rd.Height = new GridLength(rowHeight, GridUnitType.Star);
                mainGrid.RowDefinitions.Add(rd);
            }

            SingleItemBox box;
            CellRange     c;

            for (int y = 0; y < rows; y++)
            {
                for (int x = 0; x < cols; x++)
                {
                    c = cpeMatrix.GetCellByIndex(y, x);
                    Console.WriteLine(String.Format("Making item '{0}' at x={1};y={2};", c.CellNumber, x, y));
                    box = new SingleItemBox(c);
                    box.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch;
                    box.VerticalAlignment   = System.Windows.VerticalAlignment.Stretch;
                    box.Name = "box_" + c.CellNumber;
                    Grid.SetColumn(box, x);
                    Grid.SetRow(box, y);
                    _workaround[c.CellNumber] = box;
                    mainGrid.Children.Add(box);
                }
            }
        }
Пример #2
0
        public override CellRange SelectNextCell(CpeMatrix matrix, double cpe1, double cpe2, List <int> ignoreCells, int failedAttempts)
        {
            CellRange        current       = matrix.GetCellByCpe(cpe1, cpe2);
            int              x             = current.Xindex;
            int              y             = current.Yindex;
            List <CellRange> possibleCells = new List <CellRange>();

            if (Math.Abs(cpe1 - cpe2) >= Threshold)
            {
                if (cpe1 > cpe2)
                {
                    //focus on CPE2
                    x = current.Xindex;
                    y = current.Yindex;
                    x = Math.Min(x + 1, matrix.GetColumnCount() - 1);
                }
                else
                {
                    //focus on CPE1
                    x = current.Xindex;
                    y = current.Yindex;
                    y = Math.Min(y + 1, matrix.GetRowCount() - 1);
                }
            }
            else
            {
                //focus on both
                x = current.Xindex;
                y = current.Yindex;
                x = Math.Min(x + 1, matrix.GetColumnCount() - 1);
                y = Math.Min(y + 1, matrix.GetRowCount() - 1);
            }


            if (ignoreCells != null)
            {
                possibleCells = matrix.GetCellsByIndex(y, x, failedAttempts);
                foreach (CellRange cr in possibleCells)
                {
                    if (!ignoreCells.Contains(cr.CellNumber))
                    {
                        return(cr.Copy());
                    }
                }
                return(null);
            }
            return(matrix.GetCellByIndex(y, x));

            /*
             * //then move appropriately
             * if (Math.Abs(cpe1 - cpe2) >= Threshold)
             * {
             *  if (cpe1 > cpe2)
             *  {
             *      //focus on CPE2
             *      int x = current.Xindex;
             *      int y = current.Yindex;
             *      x = Math.Min(x + 1, matrix.GetColumnCount() - 1);
             *      return matrix.GetCellByIndex(y, x);
             *  }
             *  else
             *  {
             *      //focus on CPE1
             *      int x = current.Xindex;
             *      int y = current.Yindex;
             *      y = Math.Min(y + 1, matrix.GetRowCount() - 1);
             *      return matrix.GetCellByIndex(y, x);
             *  }
             * }
             * else
             * {
             *  //focus on both
             *  int x = current.Xindex;
             *  int y = current.Yindex;
             *  x = Math.Min(x + 1, matrix.GetColumnCount()-1);
             *  y = Math.Min(y + 1, matrix.GetRowCount()-1);
             *  return matrix.GetCellByIndex(y, x);
             * }
             * return null;*/
        }
Пример #3
0
        public override CellRange SelectNextCell(CpeMatrix matrix, double cpe1, double cpe2, List<int> ignoreCells, int failedAttempts)
        {
            CellRange current = matrix.GetCellByCpe(cpe1, cpe2);
            int x = current.Xindex;
            int y = current.Yindex;
            List<CellRange> possibleCells = new List<CellRange>();
            if (Math.Abs(cpe1 - cpe2) >= Threshold)
            {
                if (cpe1 > cpe2)
                {
                    //focus on CPE2
                    x = current.Xindex;
                    y = current.Yindex;
                    x = Math.Min(x + 1, matrix.GetColumnCount() - 1);
                    
                }
                else
                {
                    //focus on CPE1
                    x = current.Xindex;
                    y = current.Yindex;
                    y = Math.Min(y + 1, matrix.GetRowCount() - 1);
                    
                }
            }
            else
            {
                //focus on both
                x = current.Xindex;
                y = current.Yindex;
                x = Math.Min(x + 1, matrix.GetColumnCount() - 1);
                y = Math.Min(y + 1, matrix.GetRowCount() - 1);
                
            }


            if (ignoreCells != null)
            {
                possibleCells = matrix.GetCellsByIndex(y, x, failedAttempts);
                foreach (CellRange cr in possibleCells)
                {
                    if (!ignoreCells.Contains(cr.CellNumber))
                        return cr.Copy();
                }
                return null;
            }
            return matrix.GetCellByIndex(y, x);
            /*
            //then move appropriately
            if (Math.Abs(cpe1 - cpe2) >= Threshold)
            {
                if (cpe1 > cpe2)
                {
                    //focus on CPE2
                    int x = current.Xindex;
                    int y = current.Yindex;
                    x = Math.Min(x + 1, matrix.GetColumnCount() - 1);
                    return matrix.GetCellByIndex(y, x);
                }
                else
                {
                    //focus on CPE1
                    int x = current.Xindex;
                    int y = current.Yindex;
                    y = Math.Min(y + 1, matrix.GetRowCount() - 1);
                    return matrix.GetCellByIndex(y, x);
                }
            }
            else
            { 
                //focus on both
                int x = current.Xindex;
                int y = current.Yindex;
                x = Math.Min(x + 1, matrix.GetColumnCount()-1);
                y = Math.Min(y + 1, matrix.GetRowCount()-1);
                return matrix.GetCellByIndex(y, x);
            }
            return null;*/
        }
Пример #4
0
        public override CellRange SelectNextCell(CpeMatrix matrix, double cpe1, double cpe2, List <int> ignoreCells, int failedAttempts)
        {
            CellRange current;

            if (ignoreCells != null)
            {
                current = matrix.GetCellByCpe(cpe1, cpe2);
                List <CellRange> possibleCells;// = matrix.GetCellsByCpe(cpe1, cpe2, failedAttempts);
                if (Math.Abs(cpe1 - cpe2) >= Threshold)
                {
                    if (cpe1 > cpe2)
                    {
                        //focus on CPE2
                        int x = current.Xindex;
                        int y = current.Yindex;
                        x             = Math.Max(x - 1, 0);
                        possibleCells = matrix.GetCellsByIndex(y, x, failedAttempts);
                    }
                    else
                    {
                        //focus on CPE1
                        int x = current.Xindex;
                        int y = current.Yindex;
                        y             = Math.Max(y - 1, 0);
                        possibleCells = matrix.GetCellsByIndex(y, x, failedAttempts);
                    }
                }
                else
                {
                    //focus on both
                    int x = current.Xindex;
                    int y = current.Yindex;
                    x             = Math.Max(x - 1, 0);
                    y             = Math.Max(y - 1, 0);
                    possibleCells = matrix.GetCellsByIndex(y, x, failedAttempts);
                }
                //go through each possible cell looking for those not already ignored.
                foreach (CellRange cr in possibleCells)
                {
                    if (!ignoreCells.Contains(cr.CellNumber))
                    {
                        return(cr.Copy());
                    }
                }
                return(null);
            }
            current = matrix.GetCellByCpe(cpe1, cpe2);
            //then move appropriately
            if (Math.Abs(cpe1 - cpe2) >= Threshold)
            {
                if (cpe1 > cpe2)
                {
                    //focus on CPE2
                    int x = current.Xindex;
                    int y = current.Yindex;
                    x = Math.Max(x - 1, 0);
                    return(matrix.GetCellByIndex(y, x));
                }
                else
                {
                    //focus on CPE1
                    int x = current.Xindex;
                    int y = current.Yindex;
                    y = Math.Max(y - 1, 0);
                    return(matrix.GetCellByIndex(y, x));
                }
            }
            else
            {
                //focus on both
                int x = current.Xindex;
                int y = current.Yindex;
                x = Math.Max(x - 1, 0);
                y = Math.Max(y - 1, 0);
                return(matrix.GetCellByIndex(y, x));
            }
            return(null);
        }
Пример #5
0
 public override CellRange SelectNextCell(CpeMatrix matrix, double cpe1, double cpe2, List<int> ignoreCells, int failedAttempts)
 {
     CellRange current;
     if (ignoreCells != null)
     {
         current = matrix.GetCellByCpe(cpe1, cpe2);
         List<CellRange> possibleCells;// = matrix.GetCellsByCpe(cpe1, cpe2, failedAttempts);
         if (Math.Abs(cpe1 - cpe2) >= Threshold)
         {
             if (cpe1 > cpe2)
             {
                 //focus on CPE2
                 int x = current.Xindex;
                 int y = current.Yindex;
                 x = Math.Max(x - 1, 0);
                 possibleCells = matrix.GetCellsByIndex(y, x, failedAttempts);
             }
             else
             {
                 //focus on CPE1
                 int x = current.Xindex;
                 int y = current.Yindex;
                 y = Math.Max(y - 1, 0);
                 possibleCells = matrix.GetCellsByIndex(y, x, failedAttempts);
             }
         }
         else
         {
             //focus on both
             int x = current.Xindex;
             int y = current.Yindex;
             x = Math.Max(x - 1, 0);
             y = Math.Max(y - 1, 0);
             possibleCells = matrix.GetCellsByIndex(y, x, failedAttempts);
         }
         //go through each possible cell looking for those not already ignored.
         foreach (CellRange cr in possibleCells)
         {
             if (!ignoreCells.Contains(cr.CellNumber))
                 return cr.Copy();
         }
         return null;
     }
     current = matrix.GetCellByCpe(cpe1, cpe2);
     //then move appropriately
     if (Math.Abs(cpe1 - cpe2) >= Threshold)
     {
         if (cpe1 > cpe2)
         {
             //focus on CPE2
             int x = current.Xindex;
             int y = current.Yindex;
             x = Math.Max(x - 1, 0);
             return matrix.GetCellByIndex(y, x);
         }
         else
         {
             //focus on CPE1
             int x = current.Xindex;
             int y = current.Yindex;
             y = Math.Max(y - 1, 0);
             return matrix.GetCellByIndex(y, x);
         }
     }
     else
     { 
         //focus on both
         int x = current.Xindex;
         int y = current.Yindex;
         x = Math.Max(x - 1, 0);
         y = Math.Max(y - 1, 0);
         return matrix.GetCellByIndex(y, x);
     }
     return null;
 }