public void TestCheckConnectedNotConnected( [Values(2, 4, 10)] int columns, [Values(2, 4, 10)] int rows) { var pf = new Playfield(columns, rows); for (int c = 0; c < columns - 1; c++) { for (int r = 0; r < rows; r++) { pf.GetCell(c, r).State = Cell.States.Black; } } for (int r = 0; r < rows; r++) { pf.GetCell(columns - 1, r).State = Cell.States.White; } var cs = new Playfield.CheckState(columns, rows, c => c.IsBlack); for (int c = 0; c < columns - 1; c++) { for (int r = 0; r < rows; r++) { Assert.IsFalse(pf.CheckConnected(pf.GetCell(c, r), columns - 1, cs)); } } }
public void TestCheckConnectedForceState( [Values(2, 4)] int columns, [Values(2, 4)] int rows) { var pf = new Playfield(columns, rows); for (int c = 0; c < columns; c++) { for (int r = 0; r < rows; r++) { pf.GetCell(c, r).State = Cell.States.White; } } pf.GetCell(columns - 1, rows - 1).State = Cell.States.WhiteJeweledBoth; var cs = new Playfield.CheckState(columns, rows); Assert.IsFalse(pf.CheckConnected(pf.GetCell(0, 0), 1, cs)); cs.Predicate = c => { if (c.State == Cell.States.WhiteJeweledBoth) { cs.FoundJewel = true; } return(c.IsWhite); }; Assert.IsTrue(pf.CheckConnected(pf.GetCell(0, 0), columns - 1, cs)); Assert.IsTrue(cs.FoundJewel); }
private void CellStateChanged(object sender, CellStateChangedEventArgs args) { var p = new PlayfieldPoint(args.Column, args.Row); switch (args.NewState) { case Cell.States.Empty: RemoveCell(p); break; case Cell.States.Disabled: break; case Cell.States.BlackAndWhite: break; case Cell.States.Black: case Cell.States.BlackJeweledBoth: case Cell.States.BlackJeweledHorz: case Cell.States.BlackJeweledVert: case Cell.States.White: case Cell.States.WhiteJeweledBoth: case Cell.States.WhiteJeweledHorz: case Cell.States.WhiteJeweledVert: InstantiateVisual(Playfield.GetCell(p)); break; default: break; } }
private void CellRemoveStateChanged(object sender, CellRemoveStateChangedEventArgs args) { var p = new PlayfieldPoint(args.Column, args.Row); var go = InstantiateVisual(Playfield.GetCell(p)); var delay = args.Row * removingDelayMultiplier; go?.ScaleTo(0.0f, 1.0f, removingAnim, delay); }
public void TestCheckConnectedIsConnectedUp( [Values(2, 4)] int columns, [Values(2, 4)] int rows) { var pf = new Playfield(columns, rows); for (int r = 0; r < rows; r++) { pf.GetCell(0, r).State = Cell.States.Black; } for (int c = 1; c < columns; c++) { pf.GetCell(c, rows - 1).State = Cell.States.Black; } var cs = new Playfield.CheckState(columns, rows, c => c.State == pf.GetCell(0, 0).State); Assert.IsTrue(pf.CheckConnected(pf.GetCell(0, 0), columns - 1, cs)); }
public void TestCheckConnectedIsConnected( [Values(2, 4)] int columns, [Values(2, 4)] int rows) { var pf = new Playfield(columns, rows); pf.GetCell(0, 1).State = Cell.States.White; pf.GetCell(1, 1).State = Cell.States.White; for (int i = 0; i < columns; i++) { pf.GetCell(i, 0).State = Cell.States.Black; } var cs = new Playfield.CheckState(columns, rows, c => c.IsBlack); Assert.IsTrue(pf.CheckConnected(pf.GetCell(0, 0), columns - 1, cs)); }
private void CopyGrid(Playfield playfield) { for (int row = 0; row < this.size; row++) { for (int col = 0; col < this.size; col++) { this.grid[row, col] = playfield.GetCell(row, col); } } }
public void TestCheckConnectedBackwardsConnected( [Values(4)] int columns, [Values(4)] int rows) { var pf = new Playfield(columns, rows); for (int r = 0; r < rows; r++) { pf.GetCell(0, r).State = Cell.States.Black; } for (int c = 1; c < columns; c++) { pf.GetCell(c, rows - 1).State = Cell.States.Black; } var cellToCheck = pf.GetCell(2, 1); cellToCheck.State = Cell.States.Black; var cs = new Playfield.CheckState(columns, rows, c => c.State == cellToCheck.State); Assert.IsFalse(pf.CheckConnected(cellToCheck, columns - 1, cs)); }
PathItem GetPathItemLinkedList() { var root = new PathItem { Pos = this.from }; openList.Add(root); while (openList.Count > 0) { var visiting = openList.First(); openList.Remove(visiting); var cell = visiting.Pos; if (cell == target) { return(visiting); } if (closedList.ContainsKey(cell)) { continue; } closedList[cell] = visiting; for (int i = 0; i < Vector2D.MAX_DIRS; i++) { int index = (i + dirOffset) % Vector2D.MAX_DIRS; var nextCell = playfield.GetCell(Vector2D.Add(Vector2D.Directions[index], cell.Pos)); if (playfield.IsWalkable(nextCell)) { AddToOpenList(visiting, cell, nextCell); } } openList.Sort((a, b) => a.TotalPrevisionalLength - b.TotalPrevisionalLength); } return(null); }
public void PopulateCell(PlayfieldPoint p, Cell.States state) { Playfield.GetCell(p).State = state; }
public PathFinder From(Vector2D p) { return(From(map.GetCell(p))); }