Esempio n. 1
0
        public TekAreaDef Normalized()
        {
            TekAreaDef result = new TekAreaDef(this);

            result.ComputeDeltas();
            result.Shift(-result.xMin, -result.yMin);
            result.ComputeSize();
            return(result);
        }
Esempio n. 2
0
 public TekAreaDef(TekAreaDef value)
 {
     initLists();
     foreach (Point point in value.Points)
     {
         Points.Add(new Point(point.X, point.Y));
     }
     Update();
     _Description = value.Description;
 }
Esempio n. 3
0
        private List <TekField> GetAreaFields(Point TopLeft, TekAreaDef sArea)
        {
            List <TekField> fields = new List <TekField>();

            for (int i = 0; i < sArea.PointCount; i++)
            {
                Point P = sArea.GetPoint(i);
                fields.Add(Board.Fields[TopLeft.Y + P.Y, TopLeft.X + P.X]);
            }
            return(fields);
        }
Esempio n. 4
0
 private void AddAlternatives(TekAreaDef value)
 {
     value.TemplateArea = true;
     foreach (TekAreaDef val in value.GetAlternatives())
     {
         if (!val.IsInList(values))
         {
             values.Add(val);
         }
     }
 }
Esempio n. 5
0
        public TekAreaDef FlipHorizontal()
        {
            TekAreaDef result = new TekAreaDef(String.Format("{0} hori flip", Description));

            for (int i = 0; i < Points.Count; i++)
            {
                Point P = Points[i];
                result.AddPoint(new Point(xMax - P.X, P.Y));
            }
            return(result.Normalized());
        }
Esempio n. 6
0
        public TekAreaDef Rotate90()
        {
            TekAreaDef result = new TekAreaDef(String.Format("{0} rot 90", Description), this.Points[0]);

            foreach (Point value in this.Deltas)
            {
                result.Deltas.Add(new Point(-value.Y, value.X));
                Point p = result.Deltas.ElementAt(result.Deltas.Count - 1);
                result.AddPoint(new Point(this.Points[0].X + p.X, this.Points[0].Y + p.Y));
            }
            return(result.Normalized());
        }
Esempio n. 7
0
        public List <TekAreaDef> GetAlternatives()
        {
            List <TekAreaDef> result   = new List <TekAreaDef>();
            TekAreaDef        thisArea = this.Normalized();

            thisArea.TemplateArea = this.TemplateArea;
            AddAlternative(thisArea, result);
            // rotations
            AddAlternative(this.Rotate90(), result);
            AddAlternative(this.Rotate180(), result);
            AddAlternative(this.Rotate180().Rotate90(), result);
            return(result);
        }
Esempio n. 8
0
 public bool canFit(Point TopLeft, TekAreaDef sArea)
 {
     if (TopLeft.X + sArea.xSize > Board.Cols || TopLeft.Y + sArea.ySize > Board.Rows)
     {
         return(false);
     }
     foreach (TekField field in GetAreaFields(TopLeft, sArea))
     {
         if (field.Area != null)
         {
             return(false);
         }
     }
     return(true);
 }
Esempio n. 9
0
        public List <TekAreaDef> AreasFromTemplate(TekAreaDef template)
        {
            List <TekAreaDef> result = new List <TekAreaDef>();
            int index0 = values.IndexOf(template);

            if (index0 != -1 && values.ElementAt(index0).TemplateArea)
            {
                result.Add(template);
                for (int i = index0 + 1; i < values.Count && !values.ElementAt(i).TemplateArea; i++)
                {
                    result.Add(values.ElementAt(i));
                }
            }
            return(result);
        }
Esempio n. 10
0
        public bool Equals(TekAreaDef other)
        {
            TekAreaDef N1 = this.Normalized();
            TekAreaDef N2 = other.Normalized();

            if (N1.Points.Count != N2.Points.Count)
            {
                return(false);
            }
            foreach (Point P1 in N1.Points)
            {
                if (!N2.Points.Contains(P1))
                {
                    return(false);
                }
            }
            return(true);
        }
Esempio n. 11
0
        public bool AddRandomArea()
        {
            // find next open area
            List <Point> areaPoints = FirstEmptyArea();

            if (areaPoints.Count == 1) // one point only
            {
                AddAreaToBoard(areaPoints.ElementAt(0), StandardAreas.GetValue(0));
                return(true);
            }
            int nPoints = areaPoints.Count >= Const.MAXTEK ? Const.MAXTEK : areaPoints.Count;

            List <TekAreaDef> possibleMatches = StandardAreas.FittingAreas(areaPoints, nPoints);

            while (nPoints > 0)
            {
                if (possibleMatches.Count > 0)
                { // there is at least one match, but we still should check it fits in case the fields are already occupied
                    int   index0 = R.Next(0, possibleMatches.Count), index;
                    Point topLeft = TopLeftPoint(areaPoints);
                    index = index0;
                    do
                    {
                        TekAreaDef area = possibleMatches.ElementAt(index);
                        if (canFit(topLeft, area))
                        {
                            AddAreaToBoard(topLeft, area);
                            return(true);
                        }
                        else
                        {
                            index = (index + 1) % possibleMatches.Count;
                        }
                    } while (index != index0);
                    return(false);
                }
                if (--nPoints > 0)
                {
                    possibleMatches = StandardAreas.FittingAreas(areaPoints, nPoints);
                }
            }
            return(false);
        }
Esempio n. 12
0
        private void AddAlternative(TekAreaDef area, List <TekAreaDef> list)
        // note: includes mirror images as well
        {
            if (!area.IsInList(list))
            {
                list.Add(area);
            }
            TekAreaDef area2 = area.FlipHorizontal();

            if (!area2.IsInList(list))
            {
                list.Add(area2);
            }
            area2 = area.FlipVertical();
            if (!area2.IsInList(list))
            {
                list.Add(area2);
            }
        }
Esempio n. 13
0
        public TekAreaDef GetValue(int i, int nFields)
        {
            int        j      = i;
            TekAreaDef result = null;

            foreach (TekAreaDef value in values)
            {
                if (value.PointCount != nFields)
                {
                    continue;
                }
                if (j == 0)
                {
                    result = value;
                    break;
                }
                j--;
            }
            return(result);
        }
Esempio n. 14
0
 private void AddAreaToBoard(Point TopLeft, TekAreaDef sArea)
 {
     UpdateArea(Board.DefineArea(GetAreaFields(TopLeft, sArea)));
 }