public bool CheckCanPlace(IGrid grid, int x, int y, int xDir, int yDir, bool swap) { //no need to rotate symmetric pieces - consider the move impossible if (_immutable && (xDir == -1 || yDir == -1 || swap)) { return(false); } foreach (var step in _steps) { var coord = CalculateCoord(step.X, step.Y, x, y, xDir, yDir, swap); if (!grid.CheckCanPlace(coord.X, coord.Y)) { return(false); } } return(true); }
private bool IsPossibleGrid(IGrid grid) { for (int y = 0; y < grid.Height; y++) { for (int x = 0; x < grid.Width; x++) { if (grid.CheckCanPlace(x, y) && !grid.CheckCanPlace(x + 1, y) && !grid.CheckCanPlace(x - 1, y) && !grid.CheckCanPlace(x, y + 1) && !grid.CheckCanPlace(x, y - 1)) { return(false); } if (grid.CheckCanPlace(x, y) && grid.CheckCanPlace(x + 1, y) && !grid.CheckCanPlace(x - 1, y) && !grid.CheckCanPlace(x, y + 1) && !grid.CheckCanPlace(x, y - 1) && !grid.CheckCanPlace(x + 2, y) && !grid.CheckCanPlace(x + 1, y + 1) && !grid.CheckCanPlace(x + 1, y - 1)) { return(false); } if (grid.CheckCanPlace(x, y) && grid.CheckCanPlace(x, y + 1) && !grid.CheckCanPlace(x, y - 1) && !grid.CheckCanPlace(x + 1, y) && !grid.CheckCanPlace(x - 1, y) && !grid.CheckCanPlace(x, y + 2) && !grid.CheckCanPlace(x + 1, y + 1) && !grid.CheckCanPlace(x - 1, y + 1)) { return(false); } } } return(true); }