public void FieldRunner() { var field = new CellsField(); field.Fill(10, 10); var a = field.GetCellAt(5, 5); Cell b = null; foreach (var c in a.RunSide(SquareNodeSides.Right)) { b = ( Cell )c; } Assert.AreEqual(field.GetCellAt(9, 5), b); }
public void CellsIntegration() { var cells = new CellsField(); cells.Fill(3, 3); var field = InitByConf(new [, ] { { 1, 0, 0 }, { 1, 1, 0 }, { 0, 1, 1 } }, 3, 3, cells); Assert.IsNotNull(cells.GetCellAt(0, 0).Spot); Assert.IsNotNull(cells.GetCellAt(2, 2).Spot); Assert.AreEqual(cells.GetCellAt(0, 0), field[0, 0].GetCell()); }
public void FieldDirections() { var field = new CellsField(); field.Fill(10, 10); var a = field.GetCellAt(5, 5); var b = field.GetCellAt(5, 6); Assert.AreEqual(b.Y, (a.GetBottomNode() as Cell).Y); b = field.GetCellAt(5, 4); Assert.AreEqual(b.Y, (a.GetTopNode() as Cell).Y); b = field.GetCellAt(4, 5); Assert.AreEqual(b.X, (a.GetLeftNode() as Cell).X); b = field.GetCellAt(6, 5); Assert.AreEqual(b.X, (a.GetRightNode() as Cell).X); }
public Spot[ , ] InitByConf(int[ , ] fieldConf, int w, int h, CellsField cells = null) { Spot[ , ] field = new Spot[h, w]; for (int x = 0; x < h; x++) { for (int y = 0; y < w; y++) { var value = fieldConf[y, x]; if (value > 0) { var spot = new Spot(); field[x, y] = spot; if (x > 0) { var left = field[x - 1, y]; if (left != null) { spot.CreateLinkWith(left); } } if (y > 0) { var top = field[x, y - 1]; if (top != null) { spot.CreateLinkWith(top); } } if (cells != null) { cells.GetCellAt(x, y).SetSpot(spot); } } } } return(field); }
public void SpotMove2() { var cells = new CellsField(); cells.Fill(3, 6); var field = InitByConf(new [, ] { { 1, 0, 0 }, { 1, 1, 1 }, { 1, 0, 0 }, { 1, 0, 0 }, { 1, 0, 0 }, { 1, 0, 0 } }, 6, 3, cells); //a //b c d //e // //y //z var a = field[0, 0]; var b = field[0, 1]; var c = field[1, 1]; var d = field[2, 1]; var e = field[0, 2]; var y = field[0, 4]; var z = field[0, 5]; Assert.IsNotNull(a.GetLinkWith(b)); Assert.IsNotNull(b.GetLinkWith(c)); Assert.IsNotNull(c.GetLinkWith(d)); Assert.IsNotNull(b.GetLinkWith(e)); Assert.IsNotNull(y.GetLinkWith(z)); Assert.AreEqual(a, new SpotRunner(z).Last()); foreach (var spot in new SpotRunner(z)) { Debug.Log(spot.GetFullName() + " c:" + spot.Links.Count); } var move = new SpotMove(cells.GetCellAt(0, 5), cells.GetCellAt(1, 5)); move.Step(); move.Step(); // //a c d //b //e // //y //z foreach (var spot in new SpotRunner(z)) { Debug.Log(spot.GetFullName() + " c:" + spot.Links.Count); } Assert.IsNotNull(a.GetLinkWith(c)); Assert.IsNotNull(d.GetLinkWith(c)); Assert.IsNotNull(b.GetLinkWith(a)); Assert.IsNotNull(b.GetLinkWith(e)); Assert.IsNotNull(y.GetLinkWith(z)); }
public void SpotMove() { var cells = new CellsField(); cells.Fill(3, 3); var field = InitByConf(new [, ] { { 1, 0, 0 }, { 1, 1, 0 }, { 0, 0, 0 } }, 3, 3, cells); var a = field[0, 0]; var b = field[0, 1]; var c = field[1, 1]; Assert.AreEqual(cells.GetCellAt(0, 0), a.GetCell()); Assert.AreEqual(cells.GetCellAt(0, 1), b.GetCell()); Assert.AreEqual(cells.GetCellAt(1, 1), c.GetCell()); var move = new SpotMove(cells.GetCellAt(1, 1), cells.GetCellAt(1, 2)); move.Step(); move.Step(); Assert.AreEqual(cells.GetCellAt(0, 1), a.GetCell()); Assert.AreEqual(cells.GetCellAt(1, 1), b.GetCell()); Assert.AreEqual(cells.GetCellAt(1, 2), c.GetCell()); move = new SpotMove(cells.GetCellAt(1, 2), cells.GetCellAt(2, 2)); move.Step(); move.Step(); Assert.AreEqual(cells.GetCellAt(1, 1), a.GetCell()); Assert.AreEqual(cells.GetCellAt(1, 2), b.GetCell()); Assert.AreEqual(cells.GetCellAt(2, 2), c.GetCell()); }