private static bool CanPlaceTile(Tile t, Grid <BorderKind> terrainId, int tileX, int tileY, out int matches) { matches = 0; for (int x = 0; x <= t.Width; x++) { for (int y = 0; y <= t.Height; y++) { if (tileX + x >= terrainId.Width || tileY + y >= terrainId.Height) { return(false); } BorderKind terrain1 = t.TerrainId[x, y]; BorderKind terrain2 = terrainId[tileX + x, tileY + y]; if (!terrain1.IsCompatible(terrain2)) { return(false); } if (terrain1 == terrain2) { matches++; } else if (t.IsLarge) { return(false); } } } return(true); }