public void FullSizePointRectangleHasTheRightNumberOfPoints() { var upperLeft = SgfPoint.Parse("aa"); var lowerRight = SgfPoint.Parse("ZZ"); var rectangle = new SgfPointRectangle(upperLeft, lowerRight); Assert.AreEqual(2704, rectangle.Count()); }
public void ToStringSerializesRectangularPointRectangleProperly() { var upperLeft = SgfPoint.Parse("aa"); var lowerRight = SgfPoint.Parse("ZZ"); var rectangle = new SgfPointRectangle(upperLeft, lowerRight); Assert.AreEqual("aa:ZZ", rectangle.ToString()); }
public void NormalSgfPointIsParsedCorrectly() { var point = SgfPoint.Parse("Ce"); Assert.AreEqual(28, point.Column); Assert.AreEqual(4, point.Row); Assert.IsFalse(point.IsInherentlyPass); }
public void SgfPointEqualityOperatorIsCorrectlyEvaluated() { var first = SgfPoint.Parse("fO"); var second = SgfPoint.Parse("fO"); var third = SgfPoint.Parse("aa"); Assert.IsTrue(first == second); Assert.IsTrue(first != third); }
public void SgfPointEqualityIsCorrectlyEvaluated() { var first = SgfPoint.Parse("fO"); var second = SgfPoint.Parse("fO"); var third = SgfPoint.Parse("aa"); Assert.IsTrue(first.Equals(second)); Assert.IsFalse(first.Equals(third)); }
public void SinglePointRectangleIsProperlyCreated() { var single = new SgfPoint(12, 2); var rectangle = new SgfPointRectangle(single); Assert.AreEqual(single, rectangle.UpperLeft); Assert.AreEqual(single, rectangle.LowerRight); Assert.AreEqual(1, rectangle.Count()); Assert.AreEqual(single, rectangle.First()); }
public void SgfPointsAreCorrectlySerialized() { var firstPoint = SgfPoint.Parse("Ce"); var secondPoint = SgfPoint.Parse("ZZ"); var thirdPoint = SgfPoint.Parse("aa"); var fourthPoint = SgfPoint.Parse("fO"); Assert.AreEqual("Ce", firstPoint.ToString()); Assert.AreEqual("ZZ", secondPoint.ToString()); Assert.AreEqual("aa", thirdPoint.ToString()); Assert.AreEqual("fO", fourthPoint.ToString()); }
public void MultiplePointsAreProperlyEnumerated() { var upperLeft = new SgfPoint(10, 5); var lowerRight = new SgfPoint(11, 6); var rectangle = new SgfPointRectangle(upperLeft, lowerRight); var enumerated = rectangle.ToList(); Assert.AreEqual(4, enumerated.Count); Assert.AreEqual(upperLeft, enumerated.First()); Assert.AreEqual(new SgfPoint(11, 5), enumerated[1]); Assert.AreEqual(new SgfPoint(10, 6), enumerated[2]); Assert.AreEqual(lowerRight, enumerated.Last()); }
public void ComplexPointRectanglePointsCanBeCompressed() { var rectangles = new SgfPointRectangle[] { new SgfPointRectangle(SgfPoint.Parse("jd"), SgfPoint.Parse("jg")), new SgfPointRectangle(SgfPoint.Parse("kn"), SgfPoint.Parse("lq")), new SgfPointRectangle(SgfPoint.Parse("pn"), SgfPoint.Parse("pq")), }; var allPoints = rectangles.SelectMany(pr => pr.ToList()).ToArray(); SgfPointCompressor compressor = new SgfPointCompressor(allPoints); var pointRectangles = compressor.CompressPoints(); var decompressedPoints = pointRectangles.SelectMany(pr => pr.ToList()); Assert.AreEqual(0, allPoints.Except(decompressedPoints).Count()); Assert.AreEqual(0, pointRectangles.Except(rectangles).Count()); }
public void TtPointIsRecognizedAsPassForSmallerGameBoard() { var point = SgfPoint.Parse("tt"); Assert.IsTrue(point.IsPass(new GameBoardSize(19))); }
public void ToStringSerializesPointProperly() { var point = SgfPoint.Parse("cc"); Assert.AreEqual("cc", point.ToString()); }
/// <summary> /// Converts SGF point to Position /// </summary> /// <param name="sgfPoint">SGF point</param> /// <param name="size">Game board size is used for reversing Y coordinates.</param> /// <returns>Position</returns> internal static Position FromSgfPoint(SgfPoint sgfPoint, GameBoardSize size) => new Position(sgfPoint.Column, size.Height - sgfPoint.Row - 1);
public void SgfPointPassIsCorrectlyParsed() { var point = SgfPoint.Parse(string.Empty); Assert.IsTrue(point.IsInherentlyPass); }
public void ArgumentNullThrownForNullSgfPointParseAttempt() { SgfPoint.Parse(null); }
/// <summary> /// Converts a SGF tree branch to GameTreeNode /// </summary> /// <param name="branch">Branch</param> /// <returns>Game tree node</returns> private GameTreeNode ConvertBranch(SgfGameTree branch, GameBoardSize boardSize) { GameTreeNode root = null; GameTreeNode current = null; foreach (var node in branch.Sequence) { GameTreeNode newNode = null; if (node["W"] != null) { SgfPoint point = node["W"].Value <SgfPoint>(); //add white move newNode = new GameTreeNode(Move.PlaceStone(StoneColor.White, Position.FromSgfPoint(point, boardSize))); } else if (node["B"] != null) { SgfPoint point = node["B"].Value <SgfPoint>(); //add black move newNode = new GameTreeNode(Move.PlaceStone(StoneColor.Black, Position.FromSgfPoint(point, boardSize))); } else { //add non-move newNode = new GameTreeNode(Move.NoneMove); } if (node["AW"] != null) { //add white moves var property = node["AW"]; var pointRectangles = property.SimpleValues <SgfPointRectangle>(); newNode.AddWhite.AddRange(GetPositionsFromPointRectangles(pointRectangles, boardSize)); } if (node["AB"] != null) { var property = node["AB"]; var pointRectangles = property.SimpleValues <SgfPointRectangle>(); newNode.AddBlack.AddRange(GetPositionsFromPointRectangles(pointRectangles, boardSize)); } if (node["C"] != null) { var property = node["C"]; var comment = property.Value <string>(); newNode.Comment = comment; } // Fill in all markup properties ParseAndFillMarkupProperties(node, newNode, boardSize); if (current == null) { root = newNode; } else { current.Branches.AddNode(newNode); } current = newNode; } //create root if none were found if (root == null) { root = new GameTreeNode(Move.NoneMove); current = root; } //add branches foreach (var child in branch.Children) { var rootOfBranch = ConvertBranch(child, boardSize); current.Branches.AddNode(rootOfBranch); } return(root); }
private SgfPointRectangle ExpandFromPoint(SgfPoint point) { var topEdge = point.Row; var bottomEdge = point.Row; var leftEdge = point.Column; var rightEdge = point.Column; _unusedPoints.Remove(point); Queue <ExpandDirection> availableExpandDirections = new Queue <ExpandDirection>(ExpandDirections); while (availableExpandDirections.Any()) { var direction = availableExpandDirections.Dequeue(); bool expanded = false; //try to expand if (direction.Y != 0) { var checkedRow = direction.Y < 0 ? topEdge - 1 : bottomEdge + 1; if (checkedRow >= 0 && checkedRow <= 52) { var expandable = true; //check direction for expansion for (int checkedColumn = leftEdge; checkedColumn <= rightEdge; checkedColumn++) { if (!_unusedPoints.Contains(new SgfPoint(checkedColumn, checkedRow))) { expandable = false; break; } } if (expandable) { //mark points as used for (int checkedColumn = leftEdge; checkedColumn <= rightEdge; checkedColumn++) { _unusedPoints.Remove(new SgfPoint(checkedColumn, checkedRow)); } //expand boundary if (direction.Y < 0) { topEdge--; } else if (direction.Y > 0) { bottomEdge++; } expanded = true; } } } else if (direction.X != 0) { var checkedColumn = direction.X < 0 ? leftEdge - 1 : rightEdge + 1; if (checkedColumn >= 0 && checkedColumn <= 52) { var expandable = true; //check direction for expansion for (int checkedRow = topEdge; checkedRow <= bottomEdge; checkedRow++) { if (!_unusedPoints.Contains(new SgfPoint(checkedColumn, checkedRow))) { expandable = false; break; } } if (expandable) { //mark points as used for (int checkedRow = topEdge; checkedRow <= bottomEdge; checkedRow++) { _unusedPoints.Remove(new SgfPoint(checkedColumn, checkedRow)); } //expand boundary if (direction.X < 0) { leftEdge--; } else if (direction.X > 0) { rightEdge++; } expanded = true; } } } if (expanded) { availableExpandDirections.Enqueue(direction); } } return(new SgfPointRectangle(new SgfPoint(leftEdge, topEdge), new SgfPoint(rightEdge, bottomEdge))); }
public void TtPointIsNotRecognizedAsPassInherently() { var point = SgfPoint.Parse("tt"); Assert.IsFalse(point.IsInherentlyPass); }
public void TtPointIsNotRecognizedAsPassForLargeGameBoard() { var point = SgfPoint.Parse("tt"); Assert.IsFalse(point.IsPass(new GameBoardSize(50))); }
public void InvalidPointCantBeParsed() { SgfPoint.Parse("12"); }