Skip to content

Commit

Permalink
Merge pull request #309 from lucasnlm/update-14
Browse files Browse the repository at this point in the history
Update 14
  • Loading branch information
lucasnlm committed Aug 23, 2021
2 parents bb9761b + 45f851b commit 834030f
Show file tree
Hide file tree
Showing 63 changed files with 382 additions and 80 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ android {

defaultConfig {
// versionCode and versionName must be hardcoded to support F-droid
versionCode 1300001
versionName '13.0.0'
versionCode 1400001
versionName '14.0.0'
minSdkVersion 21
targetSdkVersion 31
multiDexEnabled true
Expand Down
4 changes: 2 additions & 2 deletions app/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip
distributionSha256Sum=23e7d37e9bb4f8dabb8a3ea7fdee9dd0428b9b1a71d298aefd65b11dccea220f
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip
distributionSha256Sum=3239b5ed86c3838a37d983ac100573f64c1f3fd8e1eb6c89fa5f9529b5ec091d
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import dev.lucasnlm.antimine.R
import dev.lucasnlm.antimine.common.level.database.models.Stats
import dev.lucasnlm.antimine.common.level.repository.IMinefieldRepository
import dev.lucasnlm.antimine.common.level.repository.IStatsRepository
import dev.lucasnlm.antimine.core.models.Difficulty
import dev.lucasnlm.antimine.core.repository.IDimensionRepository
import dev.lucasnlm.antimine.core.viewmodel.IntentViewModel
import dev.lucasnlm.antimine.preferences.IPreferencesRepository
Expand All @@ -22,8 +21,7 @@ class StatsViewModel(
private suspend fun loadStatsModel(): List<StatsModel> {
val minId = preferenceRepository.getStatsBase()
val stats = statsRepository.getAllStats(minId)
val standardSize = minefieldRepository.fromDifficulty(
Difficulty.Standard,
val standardSize = minefieldRepository.baseStandardSize(
dimensionRepository,
preferenceRepository,
)
Expand Down Expand Up @@ -151,7 +149,8 @@ class StatsViewModel(
}

private fun isMaster(stats: Stats): Boolean {
return (stats.mines == 200 || stats.mines == 300) && stats.width == 50 && stats.height == 50
return (stats.mines == 200 || stats.mines == 300 || stats.mines == 400) &&
stats.width == 50 && stats.height == 50
}

private fun isLegend(stats: Stats): Boolean {
Expand All @@ -167,8 +166,18 @@ class StatsViewModel(
}

private fun List<Stats>.filterStandard(standardSize: Minefield) = filter {
(it.width == standardSize.width && it.height == standardSize.height) ||
(it.width == standardSize.height && it.height == standardSize.width)
val baseWidth = (it.width - standardSize.width)
val baseHeight = (it.height - standardSize.height)
val baseWidthInv = (it.height - standardSize.width)
val baseHeightInv = (it.width - standardSize.height)

val baseCheck = (baseWidth >= 0 && baseWidth % 2 == 0 && baseHeight >= 0 && baseHeight % 2 == 0)
val baseInvCheck = (baseWidthInv >= 0 && baseWidthInv % 2 == 0 && baseHeightInv >= 0 && baseHeightInv % 2 == 0)

(baseCheck || baseInvCheck) &&
listOf(::isExpert, ::isMaster, ::isLegend, ::isIntermediate, ::isBeginner)
.any { func -> func.invoke(it) }
.not()
}

private fun List<Stats>.filterNotStandard(standardSize: Minefield) = filterNot {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ import dev.lucasnlm.antimine.preferences.IPreferencesRepository
import dev.lucasnlm.antimine.preferences.models.Minefield

class FixedMinefieldRepository : IMinefieldRepository {
override fun baseStandardSize(
dimensionRepository: IDimensionRepository,
preferencesRepository: IPreferencesRepository
): Minefield =
Minefield(9, 9, 9)

override fun fromDifficulty(
difficulty: Difficulty,
dimensionRepository: IDimensionRepository,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class StatsViewModelTest : IntentViewModelTest() {
super.setup()
every { prefsRepository.getStatsBase() } returns 0
every { prefsRepository.isPremiumEnabled() } returns false
every { minefieldRepository.baseStandardSize(any(), any()) } returns Minefield(6, 12, 9)
every { minefieldRepository.fromDifficulty(any(), any(), any()) } returns Minefield(6, 12, 9)
}

Expand Down
4 changes: 2 additions & 2 deletions common/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionSha256Sum=9d94e6e4a28ad328072ef6e56bce79a810494ae756751fdcedffdeaf27c093b1
distributionSha256Sum=3239b5ed86c3838a37d983ac100573f64c1f3fd8e1eb6c89fa5f9529b5ec091d
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ import dev.lucasnlm.antimine.preferences.models.Minefield
import kotlin.random.Random

interface IMinefieldRepository {
fun baseStandardSize(
dimensionRepository: IDimensionRepository,
preferencesRepository: IPreferencesRepository,
): Minefield

fun fromDifficulty(
difficulty: Difficulty,
dimensionRepository: IDimensionRepository,
Expand All @@ -17,6 +22,31 @@ interface IMinefieldRepository {
}

class MinefieldRepository : IMinefieldRepository {
override fun baseStandardSize(
dimensionRepository: IDimensionRepository,
preferencesRepository: IPreferencesRepository,
): Minefield {
val fieldSize = dimensionRepository.defaultAreaSize()
val verticalGap = if (dimensionRepository.navigationBarHeight() > 0)
VERTICAL_STANDARD_GAP else VERTICAL_STANDARD_GAP_WITHOUT_BOTTOM

val progressiveMines = preferencesRepository.getProgressiveValue()

val display = dimensionRepository.displaySize()
val width = display.width
val height = display.height

val calculatedWidth = ((width / fieldSize).toInt() - HORIZONTAL_STANDARD_GAP)
val calculatedHeight = ((height / fieldSize).toInt() - verticalGap)
val fitWidth = calculatedWidth.coerceAtLeast(MIN_STANDARD_WIDTH)
val fitHeight = calculatedHeight.coerceAtLeast(MIN_STANDARD_HEIGHT)
val fieldArea = fitWidth * fitHeight
val fitMines =
((fieldArea * CUSTOM_LEVEL_MINE_RATIO).toInt() + progressiveMines)
.coerceAtMost((fieldArea * MAX_LEVEL_MINE_RATIO).toInt())
return Minefield(fitWidth, fitHeight, fitMines)
}

override fun fromDifficulty(
difficulty: Difficulty,
dimensionRepository: IDimensionRepository,
Expand All @@ -39,26 +69,22 @@ class MinefieldRepository : IMinefieldRepository {
dimensionRepository: IDimensionRepository,
preferencesRepository: IPreferencesRepository,
): Minefield {
val fieldSize = dimensionRepository.defaultAreaSize()
val verticalGap = if (dimensionRepository.navigationBarHeight() > 0)
VERTICAL_STANDARD_GAP else VERTICAL_STANDARD_GAP_WITHOUT_BOTTOM

val progressiveMines = preferencesRepository.getProgressiveValue()

val display = dimensionRepository.displaySize()
val width = display.width
val height = display.height
var result: Minefield = baseStandardSize(dimensionRepository, preferencesRepository)
var resultWidth = result.width
var resultHeight = result.height

val calculatedWidth = ((width / fieldSize).toInt() - HORIZONTAL_STANDARD_GAP)
val calculatedHeight = ((height / fieldSize).toInt() - verticalGap)
val finalWidth = calculatedWidth.coerceAtLeast(MIN_STANDARD_WIDTH)
val finalHeight = calculatedHeight.coerceAtLeast(MIN_STANDARD_HEIGHT)
val fieldArea = finalWidth * finalHeight
val finalMines =
((fieldArea * CUSTOM_LEVEL_MINE_RATIO).toInt() + progressiveMines)
.coerceAtMost((fieldArea * MAX_LEVEL_MINE_RATIO).toInt())
do {
val percentage = (result.mines.toDouble() / (resultWidth * resultHeight) * 100.0).toInt()
result = Minefield(resultWidth, resultHeight, result.mines)
if (percentage <= 22) {
break
} else {
resultWidth += 2
resultHeight += 2
}
} while (percentage > 22)

return Minefield(finalWidth, finalHeight, finalMines)
return result
}

override fun randomSeed(): Long = Random.nextLong()
Expand All @@ -67,7 +93,7 @@ class MinefieldRepository : IMinefieldRepository {
private val beginnerMinefield = Minefield(9, 9, 10)
private val intermediateMinefield = Minefield(16, 16, 40)
private val expertMinefield = Minefield(24, 24, 99)
private val masterMinefield = Minefield(50, 50, 300)
private val masterMinefield = Minefield(50, 50, 400)
private val legendMinefield = Minefield(100, 100, 2000)

private const val CUSTOM_LEVEL_MINE_RATIO = 0.2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ class LimitedCheckNeighborsSolver(
}

companion object {
const val DEFAULT_BRUTE_FORCE_TIMEOUT = 500L
const val DEFAULT_BRUTE_FORCE_TIMEOUT = 1000L
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ open class GameViewModel(
totalMines = totalMines,
rightMines = totalMines,
timestamp = state.duration,
receivedTips = 2,
receivedTips = calcRewardHints(),
)
sendSideEffect(sideEffect)
}
Expand All @@ -164,7 +164,7 @@ open class GameViewModel(
totalMines = gameController.mines().count(),
rightMines = gameController.mines().count { it.mark.isNotNone() },
timestamp = state.duration,
receivedTips = 1,
receivedTips = calcRewardHints(),
turn = state.turn,
)
sendSideEffect(sideEffect)
Expand Down Expand Up @@ -386,10 +386,6 @@ open class GameViewModel(
}
}

suspend fun loadGame(): Minefield {
return loadLastGame()
}

fun pauseGame() {
if (initialized) {
if (gameController.hasMines()) {
Expand Down Expand Up @@ -649,12 +645,23 @@ open class GameViewModel(
saveGame()
saveStats()

if (clock.time() > 5L && preferencesRepository.isPremiumEnabled()) {
if (isCompletedWithMistakes()) {
addNewTip(1)
val rewardedHints = calcRewardHints()
if (rewardedHints > 0) {
addNewTip(rewardedHints)
}
}

private fun calcRewardHints(): Int {
return if (clock.time() > 5L && preferencesRepository.isPremiumEnabled()) {
val rewardedHints = if (isCompletedWithMistakes()) {
(state.minefield.mines * 0.05).toInt()
} else {
addNewTip(2)
(state.minefield.mines * 0.1).toInt()
}

rewardedHints
} else {
0
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class SoundManager(
}
}.start()
} catch (e: Exception) {
// Some Huawei phones fail to play sounds there.
// Some Huawei phones may fail to play sounds.
// Adding this try catch to at lease to make they crash.
crashReporter.sendError("Fail to play sound.\n${e.message}")
}
Expand Down
File renamed without changes.
Binary file modified common/src/main/res/mipmap-hdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified common/src/main/res/mipmap-hdpi/ic_launcher_round.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified common/src/main/res/mipmap-mdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified common/src/main/res/mipmap-mdpi/ic_launcher_round.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified common/src/main/res/mipmap-xhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified common/src/main/res/mipmap-xhdpi/ic_launcher_round.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified common/src/main/res/mipmap-xxhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified common/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified common/src/main/res/mipmap-xxxhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified common/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ import dev.lucasnlm.antimine.preferences.IPreferencesRepository
import dev.lucasnlm.antimine.preferences.models.Minefield

class FixedMinefieldRepository : IMinefieldRepository {
override fun baseStandardSize(
dimensionRepository: IDimensionRepository,
preferencesRepository: IPreferencesRepository
): Minefield =
Minefield(9, 9, 9)

override fun fromDifficulty(
difficulty: Difficulty,
dimensionRepository: IDimensionRepository,
Expand Down
68 changes: 68 additions & 0 deletions fastlane/source/icon-mine-only.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 834030f

Please sign in to comment.