/// <summary> /// Method used to Recognize Fire /// </summary> /// <param name="shape">Shape to recognize</param> /// <returns>List of Fire symbols found</returns> public List <RecognizedShape> Recognize(IShape shape) { _temp = new List <RecognizedShape>(); _trianglesfound = new List <int[]>(); foreach (MagicPoint pnt in shape.Points) { foreach (int pnt1 in pnt.Connections) { foreach (int pnt2 in pnt.Connections) { if (pnt1 != pnt2) { if (shape.Points[pnt1].Connections.Contains(pnt2)) { foreach (int[] array in _trianglesfound) { if (!array.Contains(pnt.ID) && !array.Contains(pnt1) && !array.Contains(pnt2)) { _recShape = new RecognizedShape(this); _tempArray = new int[3]; _tempArray[0] = pnt.ID; _tempArray[1] = pnt1; _tempArray[2] = pnt2; _trianglesfound.Add(_tempArray); _recShape.Points = _tempArray; _tempArray = new int[3]; _tempArray[0] = pnt.ID; _tempArray[1] = pnt.ID; _tempArray[2] = pnt1; _recShape.OriginCon = _tempArray; _tempArray = new int[3]; _tempArray[0] = pnt1; _tempArray[1] = pnt2; _tempArray[2] = pnt2; _recShape.OriginCon = _tempArray; _temp.Add(_recShape); break; } } } } } } } return(_temp); }
/// <summary> /// A method used to compare Recognized Shapes /// </summary> /// <param name="ShapeA">First Shape</param> /// <param name="ShapeB">Second Shape</param> /// <returns></returns> public static List <RecognizedShape> Compare(RecognizedShape ShapeA, RecognizedShape ShapeB) { List <RecognizedShape> shapes = new List <RecognizedShape>(); shapes.Add(ShapeA); shapes.Add(ShapeB); int ConsA = 0; int ConsB = 0; foreach (int i in ShapeA.OriginCon) { ConsA++; } foreach (int i in ShapeB.OriginCon) { ConsB++; } Dictionary <int, List <int> > Connects = new Dictionary <int, List <int> >(); List <int> temp = new List <int>(); //Check which Shape is Larger if (ShapeA.Points.Count() >= ShapeB.Points.Count() && ConsA >= ConsB) { foreach (int pnt in ShapeA.Points) { temp = new List <int>(); for (int i = 0; i < ShapeA.OriginCon.Count(); i++) { if (ShapeA.OriginCon[i] == pnt) { temp.Add(ShapeA.DestCon[i]); } } for (int i = 0; i < ShapeA.DestCon.Count(); i++) { if (ShapeA.DestCon[i] == pnt) { temp.Add(ShapeA.OriginCon[i]); } } Connects.Add(pnt, temp); } bool consumed = true; //Check whether each point is unique foreach (int pnt in ShapeA.Points) { if (consumed) { if (!ShapeB.Points.Contains(pnt)) { consumed = false; } else { if (Connects.ContainsKey(pnt)) { for (int index = 0; index < ShapeB.OriginCon.Count(); index++) { if (!Connects[ShapeB.OriginCon[index]].Contains(ShapeB.DestCon[index])) { consumed = false; } } } } } } //if there is no unique pieces of ShapeB, Remove it if (consumed) { shapes.Remove(ShapeB); } } else if (ShapeA.Points.Count() <= ShapeB.Points.Count() && ConsA <= ConsB) { bool consumed = true; foreach (int pnt in ShapeB.Points) { temp = new List <int>(); for (int i = 0; i < ShapeB.OriginCon.Count(); i++) { if (ShapeB.OriginCon[i] == pnt) { temp.Add(ShapeB.DestCon[i]); } } for (int i = 0; i < ShapeB.DestCon.Count(); i++) { if (ShapeB.DestCon[i] == pnt) { temp.Add(ShapeB.OriginCon[i]); } } Connects.Add(pnt, temp); } //Check whether each point is unique foreach (int pnt in ShapeB.Points) { if (consumed) { if (!ShapeA.Points.Contains(pnt)) { consumed = false; } else { if (Connects.ContainsKey(pnt)) { for (int index = 0; index < ShapeA.OriginCon.Count(); index++) { if (!Connects[ShapeA.OriginCon[index]].Contains(ShapeA.DestCon[index])) { consumed = false; } } } } } } //if there is no unique pieces of ShapeA, Remove it if (consumed) { shapes.Remove(ShapeA); } } return(shapes); }
/// <summary> /// Recognizes Tertiary Shapes in a magic shape /// </summary> /// <param name="_shpe">Magic Shape</param> /// <param name="TerShape">Tertiary shape to be identified</param> /// <param name="_rshapes">Recognized shapes found from Secondary recognition</param> /// <returns>Recognized shapes with Tertiary shape</returns> public List <RecognizedShape> RecognizeTertiary(IShape _shpe, ITertiaryShape TerShape, List <RecognizedShape> _rshapes) { bool found1 = false; bool found2 = false; List <RecognizedShape> involvedShape1s = new List <RecognizedShape>(); List <RecognizedShape> involvedShape2s = new List <RecognizedShape>(); // Check if Tertiary Shape's required Shapes are in the Ishape foreach (RecognizedShape rshape in _rshapes) { if (rshape.DefinedShape == TerShape.shape1) { found1 = true; involvedShape1s.Add(rshape); } if (rshape.DefinedShape == TerShape.shape2) { found2 = true; involvedShape2s.Add(rshape); } } if (found1 && found2) { //Check that the required Shapes are touching or connected, if so add Tertiary shape to list of recognized shape RecognizedShape _rshape = new RecognizedShape(TerShape); List <int> usedR2 = new List <int>(); int sh2 = 0; bool secondary = false; for (int sh1 = 0; sh1 < involvedShape1s.Count; sh1++) { for (sh2 = 0; sh2 < involvedShape2s.Count; sh2++) { if (!usedR2.Contains(sh2)) { secondary = false; foreach (int pnt in involvedShape1s[sh1].Points) { if (!secondary) { if (involvedShape2s[sh2].Points.Contains(pnt)) { secondary = true; } } if (!secondary) { foreach (int con in _shpe.Points[pnt]._connections) { if (involvedShape2s[sh2].Points.Contains(con)) { secondary = true; } } } } if (secondary) { _rshape.Points = involvedShape1s[sh1].Points; _rshape.OriginCon = involvedShape1s[sh1].OriginCon; _rshape.DestCon = involvedShape1s[sh1].DestCon; _rshape.Points.Concat(involvedShape2s[sh2].Points); _rshape.OriginCon.Concat(involvedShape2s[sh2].OriginCon); _rshape.DestCon.Concat(involvedShape2s[sh2].DestCon); _rshapes.Remove(involvedShape2s[sh2]); _rshapes.Remove(involvedShape1s[sh1]); _rshapes.Add(_rshape); usedR2.Add(sh2); sh2 = -1; sh1++; } } } } } return(_rshapes); }