public void ChooseLine() { var twoShot = SearchForTwoShot(); var oneShot = SearchForOneShot(); var second = SearchForSecondLine(); if (twoShot == null && oneShot == null) { if (second != null) { ChosenLine = second; } else { ChooseRandom(); } } else if (twoShot != null) { ChosenLine = twoShot; } else { ChosenLine = oneShot; } }
private int IsSquare(LineStructure line1, LineStructure line2, bool isVertical, List <LineStructure> lineList, List <Point> pointList) { var point1 = new Point(line1.X1, line1.Y1); var point2 = new Point(line1.X2, line1.Y2); var point3 = new Point(line2.X1, line2.Y1); var point4 = new Point(line2.X2, line2.Y2); var counter = 0; if (isVertical) { foreach (var element in lineList) { if (element.Y1 == element.Y2) { if (IsPointsOfLine(element, point1, point3) && IsLineColored(element)) { counter++; } else if (IsPointsOfLine(element, point2, point4) && IsLineColored(element)) { counter++; } } } } else { foreach (var element in lineList) { if (element.X1 == element.X2) { if (IsPointsOfLine(element, point1, point3) && IsLineColored(element)) { counter++; } else if (IsPointsOfLine(element, point2, point4) && IsLineColored(element)) { counter++; } } } } if (counter != 2) { return(0); } pointList.Add(MinPoint(point1, point2, point3, point4)); return(1); }
public void ChooseLine_ShouldChooseOneShotLine() { var lineList = new List <LineStructure> { new LineStructure() { X1 = 0, Y1 = 0, X2 = 10, Y2 = 0, StrokeColor = red }, new LineStructure() { X1 = 10, Y1 = 0, X2 = 20, Y2 = 0, StrokeColor = blue }, new LineStructure() { X1 = 0, Y1 = 10, X2 = 10, Y2 = 10, StrokeColor = red }, new LineStructure() { X1 = 10, Y1 = 10, X2 = 20, Y2 = 10, StrokeColor = blue }, new LineStructure() { X1 = 0, Y1 = 20, X2 = 10, Y2 = 20, StrokeColor = red }, new LineStructure() { X1 = 0, Y1 = 0, X2 = 0, Y2 = 10, StrokeColor = white }, new LineStructure() { X1 = 10, Y1 = 0, X2 = 10, Y2 = 10, StrokeColor = white }, new LineStructure() { X1 = 20, Y1 = 0, X2 = 20, Y2 = 10, StrokeColor = white }, new LineStructure() { X1 = 10, Y1 = 10, X2 = 10, Y2 = 20, StrokeColor = blue } }; var expected = new LineStructure() { X1 = 0, Y1 = 10, X2 = 0, Y2 = 20, StrokeColor = white }; lineList.Add(expected); var ai = new Ai(10, 10) { LineList = lineList }; ai.ChooseLine(); var actual = ai.ChosenLine; Assert.AreEqual(expected, actual, "The chosen line is not the 'One shot' line!"); }
protected bool IsVerticalLine(LineStructure line) { if (line.X1 == line.X2) { return(true); } return(false); }
public void CheckStateTest_ShouldReturn1() { var lineList = new List <LineStructure> { new LineStructure() { X1 = 0, Y1 = 0, X2 = 10, Y2 = 0, StrokeColor = _red }, new LineStructure() { X1 = 10, Y1 = 0, X2 = 20, Y2 = 0, StrokeColor = _blue }, new LineStructure() { X1 = 0, Y1 = 10, X2 = 10, Y2 = 10, StrokeColor = _red }, new LineStructure() { X1 = 10, Y1 = 10, X2 = 20, Y2 = 10, StrokeColor = _blue }, new LineStructure() { X1 = 0, Y1 = 20, X2 = 10, Y2 = 20, StrokeColor = _red }, new LineStructure() { X1 = 0, Y1 = 0, X2 = 0, Y2 = 10, StrokeColor = _white }, new LineStructure() { X1 = 10, Y1 = 0, X2 = 10, Y2 = 10, StrokeColor = _white }, new LineStructure() { X1 = 20, Y1 = 0, X2 = 20, Y2 = 10, StrokeColor = _blue }, new LineStructure() { X1 = 10, Y1 = 10, X2 = 10, Y2 = 20, StrokeColor = _blue } }; var refLine = new LineStructure() { X1 = 0, Y1 = 10, X2 = 0, Y2 = 20, StrokeColor = _white }; var stateChecker = new StateChecker() { GameHeight = 10, GameWidth = 10 }; int actual = stateChecker.CheckState(refLine, lineList).Item2; int expected = 1; Assert.IsTrue(actual == expected); }
private void ChooseRandom() { var size = LineList.Count; do { ChosenLine = LineList[_random.Next(size - 1)]; } while (IsLineColored(ChosenLine)); }
protected bool AreEqualLines(LineStructure line1, LineStructure line2) { if (line1.X1 == line2.X1 && line1.Y1 == line2.Y1 && line1.X2 == line2.X2 && line1.Y2 == line2.Y2 || line1.X1 == line2.X2 && line1.Y1 == line2.Y2 && line1.X2 == line2.X1 && line1.Y2 == line2.Y1) { return(true); } return(false); }
protected bool IsLineColored(LineStructure line) { if (BrushCompare(line.StrokeColor, BlackBrushCode) || BrushCompare(line.StrokeColor, WhiteBrushCode)) { return(false); } return(true); }
private int CheckBrush(LineStructure refLine) { foreach (var line in LineList) { if (AreEqualLines(refLine, line) && IsLineColored(line)) { return(1); } } return(0); }
private bool FindLine(LineStructure refLine) { foreach (var line in LineList) { if (AreEqualLines(refLine, line)) { return(true); } } return(false); }
private LineStructure CreateLineStructureBasedOnRefs(int x1, int x2, int y1, int y2) { var line = new LineStructure { X1 = x1, Y1 = y1, X2 = x2, Y2 = y2 }; return(line); }
protected LineStructure MoveRight(LineStructure line) { var newLine = new LineStructure { X1 = line.X1 + GameWidth, X2 = line.X2 + GameWidth, Y1 = line.Y1, Y2 = line.Y2 }; return(newLine); }
private LineStructure ConvertLineToLineStructure(Line line) { var lineStructure = new LineStructure { X1 = (int)line.X1, Y1 = (int)line.Y1, X2 = (int)line.X2, Y2 = (int)line.Y2 }; return(lineStructure); }
protected LineStructure MoveDown(LineStructure line) { var newLine = new LineStructure { X1 = line.X1, X2 = line.X2, Y1 = line.Y1 + GameHeight, Y2 = line.Y2 + GameHeight }; return(newLine); }
private bool IsPointsOfLine(LineStructure line, Point p1, Point p2) { var lineP1 = new Point(line.X1, line.Y1); var lineP2 = new Point(line.X2, line.Y2); if (lineP1.Equals(p1) && lineP2.Equals(p2) || lineP1.Equals(p2) && lineP2.Equals(p1)) { return(true); } return(false); }
private bool CheckNeighbours(LineStructure refLine) { int counter1; int counter2; Tuple <List <LineStructure>, List <LineStructure> > neighbourList; neighbourList = IsVerticalLine(refLine) ? CreateNeighbourLineListVerticalCase(refLine) : CreateNeighbourLineListHorizontalCase(refLine); counter1 = SearchForColoredLines(neighbourList.Item1); counter2 = SearchForColoredLines(neighbourList.Item2); if (counter1 > 1 || counter2 > 1) { return(false); } return(counter1 == 1 || counter2 == 1); }
public Tuple <List <Point>, int> CheckState(LineStructure refLine, List <LineStructure> lineList) { Tuple <List <Point>, int> result; var pointList = new List <Point>(); var counter = 0; if (IsVerticalLine(refLine)) { foreach (var element in lineList) { if (AreEqualLines(MoveLeft(refLine), element) && IsLineColored(element)) { counter += IsSquare(refLine, element, true, lineList, pointList); } else if (AreEqualLines(MoveRight(refLine), element) && IsLineColored(element)) { counter += IsSquare(refLine, element, true, lineList, pointList); } } } else { foreach (var element in lineList) { if (AreEqualLines(MoveUp(refLine), element) && IsLineColored(element)) { counter += IsSquare(refLine, element, false, lineList, pointList); } else if (AreEqualLines(MoveDown(refLine), element) && IsLineColored(element)) { counter += IsSquare(refLine, element, false, lineList, pointList); } } } result = new Tuple <List <Point>, int>(pointList, counter); return(result); }
CreateNeighbourLineListHorizontalCase(LineStructure refLine) { List <LineStructure> lineListUp; List <LineStructure> lineListDown; var upperTop = MoveUp(refLine); var upperLeft = CreateLineStructureBasedOnRefs(upperTop.X1, refLine.X1, upperTop.Y1, refLine.Y1); var upperRight = CreateLineStructureBasedOnRefs(upperTop.X2, refLine.X2, upperTop.Y2, refLine.Y2); var lowerBottom = MoveDown(refLine); var lowerLeft = CreateLineStructureBasedOnRefs(refLine.X1, lowerBottom.X1, refLine.Y1, lowerBottom.Y1); var lowerRight = CreateLineStructureBasedOnRefs(refLine.X2, lowerBottom.X2, refLine.Y2, lowerBottom.Y2); lineListUp = new List <LineStructure> { upperTop, upperLeft, upperRight }; lineListDown = new List <LineStructure> { lowerBottom, lowerLeft, lowerRight }; return(new Tuple <List <LineStructure>, List <LineStructure> >(lineListUp, lineListDown)); }
CreateNeighbourLineListVerticalCase(LineStructure refLine) { List <LineStructure> lineListLeft; List <LineStructure> lineListRight; var leftSide = MoveLeft(refLine); var leftTop = CreateLineStructureBasedOnRefs(leftSide.X1, refLine.X1, leftSide.Y1, refLine.Y1); var leftBottom = CreateLineStructureBasedOnRefs(leftSide.X2, refLine.X2, leftSide.Y2, refLine.Y2); var rightSide = MoveRight(refLine); var rightTop = CreateLineStructureBasedOnRefs(refLine.X1, rightSide.X1, refLine.Y1, rightSide.Y1); var rightBottom = CreateLineStructureBasedOnRefs(refLine.X2, rightSide.X2, refLine.Y2, rightSide.Y2); lineListLeft = new List <LineStructure> { leftSide, leftTop, leftBottom }; lineListRight = new List <LineStructure> { rightSide, rightTop, rightBottom }; return(new Tuple <List <LineStructure>, List <LineStructure> >(lineListLeft, lineListRight)); }
public void ChooseLine_ShouldChooseRandom() { var lineList = new List <LineStructure> { new LineStructure() { X1 = 0, Y1 = 0, X2 = 10, Y2 = 0, StrokeColor = red }, new LineStructure() { X1 = 10, Y1 = 0, X2 = 20, Y2 = 0, StrokeColor = blue }, new LineStructure() { X1 = 0, Y1 = 20, X2 = 10, Y2 = 20, StrokeColor = red }, new LineStructure() { X1 = 0, Y1 = 0, X2 = 0, Y2 = 10, StrokeColor = blue }, new LineStructure() { X1 = 20, Y1 = 0, X2 = 20, Y2 = 10, StrokeColor = red }, new LineStructure() { X1 = 0, Y1 = 10, X2 = 0, Y2 = 20, StrokeColor = red } }; var expected1 = new LineStructure() { X1 = 0, Y1 = 10, X2 = 10, Y2 = 10, StrokeColor = white }; var expected2 = new LineStructure() { X1 = 10, Y1 = 10, X2 = 20, Y2 = 10, StrokeColor = white }; var expected3 = new LineStructure() { X1 = 10, Y1 = 0, X2 = 10, Y2 = 10, StrokeColor = white }; var expected4 = new LineStructure() { X1 = 10, Y1 = 10, X2 = 10, Y2 = 20, StrokeColor = white }; lineList.Add(expected1); lineList.Add(expected2); lineList.Add(expected3); lineList.Add(expected4); var ai = new Ai(10, 10) { LineList = lineList }; ai.ChooseLine(); var actual = ai.ChosenLine; Assert.IsTrue(expected1.Equals(actual) || expected2.Equals(actual) || expected3.Equals(actual) || expected4.Equals(actual), "The chosen line is not a white line."); }
private bool CompareLineToLineStruct(Line line, LineStructure lineStructure) { return(line.X1 == lineStructure.X1 && line.X2 == lineStructure.X2 && line.Y1 == lineStructure.Y1 && line.Y2 == lineStructure.Y2); }
private bool ChooseSecond(LineStructure line) { return(CheckNeighbours(line)); }