Use brute force by default
This commit is contained in:
parent
42ed255f3c
commit
22aabea90a
39 changed files with 10 additions and 69 deletions
|
@ -4,7 +4,6 @@ import dev.lucasnlm.antimine.common.level.database.models.FirstOpen
|
|||
import dev.lucasnlm.antimine.common.level.database.models.Save
|
||||
import dev.lucasnlm.antimine.common.level.database.models.SaveStatus
|
||||
import dev.lucasnlm.antimine.common.level.database.models.Stats
|
||||
import dev.lucasnlm.antimine.common.level.solver.BruteForceSolver
|
||||
import dev.lucasnlm.antimine.common.level.logic.FlagAssistant
|
||||
import dev.lucasnlm.antimine.common.level.logic.MinefieldCreator
|
||||
import dev.lucasnlm.antimine.common.level.logic.MinefieldHandler
|
||||
|
@ -23,9 +22,6 @@ import kotlinx.coroutines.flow.Flow
|
|||
import kotlinx.coroutines.flow.flow
|
||||
import kotlin.random.Random
|
||||
|
||||
/**
|
||||
* Controls a minesweeper logic.
|
||||
*/
|
||||
class GameController {
|
||||
private val minefield: Minefield
|
||||
private val startTime = System.currentTimeMillis()
|
||||
|
@ -34,7 +30,6 @@ class GameController {
|
|||
private var gameControl: GameControl = GameControl.Standard
|
||||
private var mines: Sequence<Area> = emptySequence()
|
||||
private var useQuestionMark = true
|
||||
private var useSolverAlgorithms = false
|
||||
|
||||
var hasMines = false
|
||||
private set
|
||||
|
@ -69,18 +64,14 @@ class GameController {
|
|||
private fun getArea(id: Int) = field.first { it.id == id }
|
||||
|
||||
private fun plantMinesExcept(safeId: Int) {
|
||||
if (useSolverAlgorithms) {
|
||||
val solver = LimitedBruteForceSolver()
|
||||
do {
|
||||
val useSafeZone = minefield.width > 9 && minefield.height > 9
|
||||
field = minefieldCreator.create(safeId, useSafeZone)
|
||||
val fieldCopy = field.map { it.copy() }.toMutableList()
|
||||
val minefieldHandler = MinefieldHandler(fieldCopy, false)
|
||||
minefieldHandler.openAt(safeId)
|
||||
} while (solver.keepTrying() && !solver.trySolve(minefieldHandler.result().toMutableList()))
|
||||
} else {
|
||||
field = minefieldCreator.create(safeId, true)
|
||||
}
|
||||
val solver = LimitedBruteForceSolver()
|
||||
do {
|
||||
val useSafeZone = minefield.width > 9 && minefield.height > 9
|
||||
field = minefieldCreator.create(safeId, useSafeZone)
|
||||
val fieldCopy = field.map { it.copy() }.toMutableList()
|
||||
val minefieldHandler = MinefieldHandler(fieldCopy, false)
|
||||
minefieldHandler.openAt(safeId)
|
||||
} while (solver.keepTrying() && !solver.trySolve(minefieldHandler.result().toMutableList()))
|
||||
|
||||
mines = field.filter { it.hasMine }.asSequence()
|
||||
firstOpen = FirstOpen.Position(safeId)
|
||||
|
@ -272,8 +263,4 @@ class GameController {
|
|||
fun useQuestionMark(useQuestionMark: Boolean) {
|
||||
this.useQuestionMark = useQuestionMark
|
||||
}
|
||||
|
||||
fun useSolverAlgorithms(useSolverAlgorithms: Boolean) {
|
||||
this.useSolverAlgorithms = useSolverAlgorithms
|
||||
}
|
||||
}
|
||||
|
|
|
@ -346,7 +346,6 @@ class GameViewModel @ViewModelInject constructor(
|
|||
|
||||
updateGameControl(gameControl)
|
||||
useQuestionMark(preferencesRepository.useQuestionMark())
|
||||
useSolverAlgorithms(preferencesRepository.useSolverAlgorithms())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,7 +24,6 @@ interface IPreferencesRepository {
|
|||
fun useAnimations(): Boolean
|
||||
fun useQuestionMark(): Boolean
|
||||
fun isSoundEffectsEnabled(): Boolean
|
||||
fun useSolverAlgorithms(): Boolean
|
||||
}
|
||||
|
||||
class PreferencesRepository(
|
||||
|
@ -78,9 +77,6 @@ class PreferencesRepository(
|
|||
override fun isSoundEffectsEnabled(): Boolean =
|
||||
getBoolean(PREFERENCE_SOUND_EFFECTS, false)
|
||||
|
||||
override fun useSolverAlgorithms(): Boolean =
|
||||
getBoolean(PREFERENCE_USE_SOLVER_ALGORITHMS, false)
|
||||
|
||||
override fun controlStyle(): ControlStyle {
|
||||
val index = getInt(PREFERENCE_CONTROL_STYLE, -1)
|
||||
return ControlStyle.values().getOrNull(index) ?: ControlStyle.Standard
|
||||
|
@ -120,6 +116,5 @@ class PreferencesRepository(
|
|||
private const val PREFERENCE_CUSTOM_GAME_MINES = "preference_custom_game_mines"
|
||||
private const val PREFERENCE_SOUND_EFFECTS = "preference_sound"
|
||||
private const val PREFERENCE_STATS_BASE = "preference_stats_base"
|
||||
private const val PREFERENCE_USE_SOLVER_ALGORITHMS = "preference_use_solver_algorithms"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,7 +48,6 @@
|
|||
<string name="quit">Verlaat</string>
|
||||
<string name="are_you_sure">Is jy seker?</string>
|
||||
<string name="enable_automatic_flags">Aktiveer outomatiese plasing van vlaggies</string>
|
||||
<string name="enable_no_guessing_maps">Find solvable maps</string>
|
||||
<string name="open_areas">Open Areas</string>
|
||||
<string name="total_time">Total Time</string>
|
||||
<string name="average_time">Average Time</string>
|
||||
|
|
|
@ -48,7 +48,6 @@
|
|||
<string name="quit">خروج</string>
|
||||
<string name="are_you_sure">هل أنت متأكد؟</string>
|
||||
<string name="enable_automatic_flags">Enable automatic placing of flags</string>
|
||||
<string name="enable_no_guessing_maps">Find solvable maps</string>
|
||||
<string name="open_areas">فتح المناطق</string>
|
||||
<string name="total_time">مجموع الوقت</string>
|
||||
<string name="average_time">متوسط الوقت</string>
|
||||
|
|
|
@ -48,7 +48,6 @@
|
|||
<string name="quit">Изход</string>
|
||||
<string name="are_you_sure">Сигурни ли сте?</string>
|
||||
<string name="enable_automatic_flags">Позволява автоматично слагане на флагове</string>
|
||||
<string name="enable_no_guessing_maps">Намери решими карти</string>
|
||||
<string name="open_areas">Отворени площи</string>
|
||||
<string name="total_time">Общо време</string>
|
||||
<string name="average_time">Средно време</string>
|
||||
|
|
|
@ -48,7 +48,6 @@
|
|||
<string name="quit">Surt</string>
|
||||
<string name="are_you_sure">Esteu segurs?</string>
|
||||
<string name="enable_automatic_flags">Activa la col·locació automàtica de banderes</string>
|
||||
<string name="enable_no_guessing_maps">Find solvable maps</string>
|
||||
<string name="open_areas">Zones obertes</string>
|
||||
<string name="total_time">Temps total</string>
|
||||
<string name="average_time">Durada mitjana</string>
|
||||
|
|
|
@ -48,7 +48,6 @@
|
|||
<string name="quit">Ukončit</string>
|
||||
<string name="are_you_sure">Jste si jisti?</string>
|
||||
<string name="enable_automatic_flags">Povolit automatické umísťování vlajek</string>
|
||||
<string name="enable_no_guessing_maps">Najít řešitelná minová pole</string>
|
||||
<string name="open_areas">Otevřené oblasti</string>
|
||||
<string name="total_time">Celkový čas</string>
|
||||
<string name="average_time">Průměrný čas</string>
|
||||
|
|
|
@ -48,7 +48,6 @@
|
|||
<string name="quit">Quit</string>
|
||||
<string name="are_you_sure">Are you sure?</string>
|
||||
<string name="enable_automatic_flags">Enable automatic placing of flags</string>
|
||||
<string name="enable_no_guessing_maps">Find solvable maps</string>
|
||||
<string name="open_areas">Open Areas</string>
|
||||
<string name="total_time">Total Time</string>
|
||||
<string name="average_time">Average Time</string>
|
||||
|
|
|
@ -48,7 +48,6 @@
|
|||
<string name="quit">Beenden</string>
|
||||
<string name="are_you_sure">Bist du sicher?</string>
|
||||
<string name="enable_automatic_flags">Automatische Markierungen aktivieren</string>
|
||||
<string name="enable_no_guessing_maps">Lösbare Karten finden</string>
|
||||
<string name="open_areas">Offene Flächen</string>
|
||||
<string name="total_time">Gesamtzeit</string>
|
||||
<string name="average_time">Durchschnittliche Zeit</string>
|
||||
|
|
|
@ -48,7 +48,6 @@
|
|||
<string name="quit">Έξοδος</string>
|
||||
<string name="are_you_sure">Είσαι σίγουρος;</string>
|
||||
<string name="enable_automatic_flags">Ενεργοποίηση αυτόματης τοποθέτησης σημαιών</string>
|
||||
<string name="enable_no_guessing_maps">Find solvable maps</string>
|
||||
<string name="open_areas">Ανοιχτές περιοχές</string>
|
||||
<string name="total_time">Συνολικός Χρόνος</string>
|
||||
<string name="average_time">Μέσος χρόνος</string>
|
||||
|
|
|
@ -48,7 +48,6 @@
|
|||
<string name="quit">Quit</string>
|
||||
<string name="are_you_sure">Are you sure?</string>
|
||||
<string name="enable_automatic_flags">Enable automatic placing of flags</string>
|
||||
<string name="enable_no_guessing_maps">Find solvable maps</string>
|
||||
<string name="open_areas">Open Areas</string>
|
||||
<string name="total_time">Total Time</string>
|
||||
<string name="average_time">Average Time</string>
|
||||
|
|
|
@ -48,7 +48,6 @@
|
|||
<string name="quit">Salir</string>
|
||||
<string name="are_you_sure">¿Estás seguro?</string>
|
||||
<string name="enable_automatic_flags">Activar situación automática de banderas</string>
|
||||
<string name="enable_no_guessing_maps">Encontrar mapas solubles</string>
|
||||
<string name="open_areas">Abrir Áreas</string>
|
||||
<string name="total_time">Tiempo total</string>
|
||||
<string name="average_time">Tiempo promedio</string>
|
||||
|
|
|
@ -48,7 +48,6 @@
|
|||
<string name="quit">Lopeta</string>
|
||||
<string name="are_you_sure">Oletko varma?</string>
|
||||
<string name="enable_automatic_flags">Kytke lippujen automaattinen asettaminen päälle</string>
|
||||
<string name="enable_no_guessing_maps">Etsi ratkaistavia karttoja</string>
|
||||
<string name="open_areas">Avaa alueita</string>
|
||||
<string name="total_time">Aika yhteensä</string>
|
||||
<string name="average_time">Keskimääräinen aika</string>
|
||||
|
|
|
@ -48,7 +48,6 @@
|
|||
<string name="quit">Quitter</string>
|
||||
<string name="are_you_sure">Vraiment ?</string>
|
||||
<string name="enable_automatic_flags">Activer le placement automatique de drapeaux</string>
|
||||
<string name="enable_no_guessing_maps">Find solvable maps</string>
|
||||
<string name="open_areas">Zones ouvertes</string>
|
||||
<string name="total_time">Temps de jeu total</string>
|
||||
<string name="average_time">Temps de jeu moyen</string>
|
||||
|
|
|
@ -48,7 +48,6 @@
|
|||
<string name="quit">समाप्त करें</string>
|
||||
<string name="are_you_sure">क्या आपको यकीन है?</string>
|
||||
<string name="enable_automatic_flags">फ्लैग के स्वचालित रखे जाने को सक्रिय क</string>
|
||||
<string name="enable_no_guessing_maps">Find solvable maps</string>
|
||||
<string name="open_areas">Open Areas</string>
|
||||
<string name="total_time">कुल समय</string>
|
||||
<string name="average_time">औसत समय</string>
|
||||
|
|
|
@ -48,7 +48,6 @@
|
|||
<string name="quit">Kilépés</string>
|
||||
<string name="are_you_sure">Biztos vagy benne?</string>
|
||||
<string name="enable_automatic_flags">A zászlók automatikus elhelyezésének engedélyezése</string>
|
||||
<string name="enable_no_guessing_maps">Megoldható térképek keresése</string>
|
||||
<string name="open_areas">Nyílt területek</string>
|
||||
<string name="total_time">Teljes játékidő</string>
|
||||
<string name="average_time">Átlagos játékidő</string>
|
||||
|
|
|
@ -48,7 +48,6 @@
|
|||
<string name="quit">Keluar</string>
|
||||
<string name="are_you_sure">Anda yakin?</string>
|
||||
<string name="enable_automatic_flags">Aktifkan penempatan bendera otomatis</string>
|
||||
<string name="enable_no_guessing_maps">Cari bidang ranjau yang dapat dipecahkan</string>
|
||||
<string name="open_areas">Buka</string>
|
||||
<string name="total_time">Total waktu</string>
|
||||
<string name="average_time">Waktu rata-rata</string>
|
||||
|
|
|
@ -48,7 +48,6 @@
|
|||
<string name="quit">Esci</string>
|
||||
<string name="are_you_sure">Sei sicuro?</string>
|
||||
<string name="enable_automatic_flags">Abilita il posizionamento automatico delle bandiere</string>
|
||||
<string name="enable_no_guessing_maps">Trova le mappe risolvibili</string>
|
||||
<string name="open_areas">Aree Aperte</string>
|
||||
<string name="total_time">Tempo Totale</string>
|
||||
<string name="average_time">Durata Media</string>
|
||||
|
|
|
@ -48,7 +48,6 @@
|
|||
<string name="quit">Quit</string>
|
||||
<string name="are_you_sure">Are you sure?</string>
|
||||
<string name="enable_automatic_flags">Enable automatic placing of flags</string>
|
||||
<string name="enable_no_guessing_maps">Find solvable maps</string>
|
||||
<string name="open_areas">Open Areas</string>
|
||||
<string name="total_time">Total Time</string>
|
||||
<string name="average_time">Average Time</string>
|
||||
|
|
|
@ -48,7 +48,6 @@
|
|||
<string name="quit">終了</string>
|
||||
<string name="are_you_sure">本当によろしいですか?</string>
|
||||
<string name="enable_automatic_flags">旗を自動で立てる</string>
|
||||
<string name="enable_no_guessing_maps">解決可能なマップを検索</string>
|
||||
<string name="open_areas">開いたエリアの数</string>
|
||||
<string name="total_time">合計時間</string>
|
||||
<string name="average_time">平均時間</string>
|
||||
|
|
|
@ -48,7 +48,6 @@
|
|||
<string name="quit">Quit</string>
|
||||
<string name="are_you_sure">Are you sure?</string>
|
||||
<string name="enable_automatic_flags">Enable automatic placing of flags</string>
|
||||
<string name="enable_no_guessing_maps">Find solvable maps</string>
|
||||
<string name="open_areas">Open Areas</string>
|
||||
<string name="total_time">Total Time</string>
|
||||
<string name="average_time">Average Time</string>
|
||||
|
|
|
@ -48,7 +48,6 @@
|
|||
<string name="quit">Stoppen</string>
|
||||
<string name="are_you_sure">Weet je het zeker?</string>
|
||||
<string name="enable_automatic_flags">Schakel automatisch plaatsen van vlaggen in</string>
|
||||
<string name="enable_no_guessing_maps">Find solvable maps</string>
|
||||
<string name="open_areas">Open gebieden</string>
|
||||
<string name="total_time">Totale Tijd</string>
|
||||
<string name="average_time">Gemiddelde Tijd</string>
|
||||
|
|
|
@ -48,7 +48,6 @@
|
|||
<string name="quit">Avslutt</string>
|
||||
<string name="are_you_sure">Er du sikker?</string>
|
||||
<string name="enable_automatic_flags">Aktiver automatisk plassering av flagg</string>
|
||||
<string name="enable_no_guessing_maps">Finn løsbare kart</string>
|
||||
<string name="open_areas">Åpne områder</string>
|
||||
<string name="total_time">Total Tid</string>
|
||||
<string name="average_time">Gjennomsnittlig Tid</string>
|
||||
|
|
|
@ -48,7 +48,6 @@
|
|||
<string name="quit">Wyjdź</string>
|
||||
<string name="are_you_sure">Na pewno?</string>
|
||||
<string name="enable_automatic_flags">Włącz automatyczne umieszczanie flag</string>
|
||||
<string name="enable_no_guessing_maps">Find solvable maps</string>
|
||||
<string name="open_areas">Odkryte pola</string>
|
||||
<string name="total_time">Całkowity czas gry</string>
|
||||
<string name="average_time">Średni czas gry</string>
|
||||
|
|
|
@ -48,7 +48,6 @@
|
|||
<string name="quit">Sair</string>
|
||||
<string name="are_you_sure">Tem certeza?</string>
|
||||
<string name="enable_automatic_flags">Ativar colocação automática de bandeiras</string>
|
||||
<string name="enable_no_guessing_maps">Calcular mapas solucionáveis</string>
|
||||
<string name="open_areas">Áreas abertas</string>
|
||||
<string name="total_time">Tempo total</string>
|
||||
<string name="average_time">Tempo médio</string>
|
||||
|
|
|
@ -48,7 +48,6 @@
|
|||
<string name="quit">Quit</string>
|
||||
<string name="are_you_sure">Are you sure?</string>
|
||||
<string name="enable_automatic_flags">Activar colocação automática de bandeiras</string>
|
||||
<string name="enable_no_guessing_maps">Find solvable maps</string>
|
||||
<string name="open_areas">Open Areas</string>
|
||||
<string name="total_time">Total Time</string>
|
||||
<string name="average_time">Average Time</string>
|
||||
|
|
|
@ -48,7 +48,6 @@
|
|||
<string name="quit">Quit</string>
|
||||
<string name="are_you_sure">Are you sure?</string>
|
||||
<string name="enable_automatic_flags">Enable automatic placing of flags</string>
|
||||
<string name="enable_no_guessing_maps">Find solvable maps</string>
|
||||
<string name="open_areas">Open Areas</string>
|
||||
<string name="total_time">Total Time</string>
|
||||
<string name="average_time">Average Time</string>
|
||||
|
|
|
@ -48,7 +48,6 @@
|
|||
<string name="quit">Выход</string>
|
||||
<string name="are_you_sure">Вы уверены?</string>
|
||||
<string name="enable_automatic_flags">Включить авторазмещение флагов</string>
|
||||
<string name="enable_no_guessing_maps">Найти беспроигрышные поля</string>
|
||||
<string name="open_areas">Открытые зоны</string>
|
||||
<string name="total_time">Общее время</string>
|
||||
<string name="average_time">Среднее время</string>
|
||||
|
|
|
@ -48,7 +48,6 @@
|
|||
<string name="quit">Quit</string>
|
||||
<string name="are_you_sure">Are you sure?</string>
|
||||
<string name="enable_automatic_flags">Enable automatic placing of flags</string>
|
||||
<string name="enable_no_guessing_maps">Find solvable maps</string>
|
||||
<string name="open_areas">Open Areas</string>
|
||||
<string name="total_time">Total Time</string>
|
||||
<string name="average_time">Average Time</string>
|
||||
|
|
|
@ -48,7 +48,6 @@
|
|||
<string name="quit">Quit</string>
|
||||
<string name="are_you_sure">Are you sure?</string>
|
||||
<string name="enable_automatic_flags">Enable automatic placing of flags</string>
|
||||
<string name="enable_no_guessing_maps">Find solvable maps</string>
|
||||
<string name="open_areas">Open Areas</string>
|
||||
<string name="total_time">Total Time</string>
|
||||
<string name="average_time">Average Time</string>
|
||||
|
|
|
@ -48,7 +48,6 @@
|
|||
<string name="quit">Çık</string>
|
||||
<string name="are_you_sure">Emin misiniz?</string>
|
||||
<string name="enable_automatic_flags">Bayrakları Otomatik Yerleştir</string>
|
||||
<string name="enable_no_guessing_maps">Find solvable maps</string>
|
||||
<string name="open_areas">Açık Alanlar</string>
|
||||
<string name="total_time">Toplam Süre</string>
|
||||
<string name="average_time">Ortalama Süre</string>
|
||||
|
|
|
@ -48,7 +48,6 @@
|
|||
<string name="quit">Вийти</string>
|
||||
<string name="are_you_sure">Ви впевнені?</string>
|
||||
<string name="enable_automatic_flags">Увімкнути автоматичне розміщення прапорців</string>
|
||||
<string name="enable_no_guessing_maps">Find solvable maps</string>
|
||||
<string name="open_areas">Відкриті області</string>
|
||||
<string name="total_time">Час перегляду</string>
|
||||
<string name="average_time">Середній час</string>
|
||||
|
|
|
@ -48,7 +48,6 @@
|
|||
<string name="quit">Thoát</string>
|
||||
<string name="are_you_sure">Bạn chắc chứ?</string>
|
||||
<string name="enable_automatic_flags">Bật tự động để cờ</string>
|
||||
<string name="enable_no_guessing_maps">Find solvable maps</string>
|
||||
<string name="open_areas">Khu vực mở</string>
|
||||
<string name="total_time">Tổng thời gian</string>
|
||||
<string name="average_time">Thời gian bình quân</string>
|
||||
|
|
|
@ -48,7 +48,6 @@
|
|||
<string name="quit">退出</string>
|
||||
<string name="are_you_sure">你确定吗?</string>
|
||||
<string name="enable_automatic_flags">启用旗标自动放置</string>
|
||||
<string name="enable_no_guessing_maps">查找可解决的地图</string>
|
||||
<string name="open_areas">开放区域</string>
|
||||
<string name="total_time">总用时</string>
|
||||
<string name="average_time">平均用时</string>
|
||||
|
|
|
@ -48,7 +48,6 @@
|
|||
<string name="quit">Quit</string>
|
||||
<string name="are_you_sure">Are you sure?</string>
|
||||
<string name="enable_automatic_flags">Enable automatic placing of flags</string>
|
||||
<string name="enable_no_guessing_maps">Find solvable maps</string>
|
||||
<string name="open_areas">Open Areas</string>
|
||||
<string name="total_time">Total Time</string>
|
||||
<string name="average_time">Average Time</string>
|
||||
|
|
|
@ -21,13 +21,6 @@
|
|||
android:title="@string/enable_automatic_flags"
|
||||
app:iconSpaceReserved="false" />
|
||||
|
||||
<SwitchPreferenceCompat
|
||||
android:checked="false"
|
||||
android:defaultValue="false"
|
||||
android:key="preference_use_solver_algorithms"
|
||||
android:title="@string/enable_no_guessing_maps"
|
||||
app:iconSpaceReserved="false" />
|
||||
|
||||
</PreferenceCategory>
|
||||
|
||||
<PreferenceCategory
|
||||
|
|
|
@ -89,7 +89,7 @@ class GameControllerTest {
|
|||
withGameController { controller ->
|
||||
val lastMine = controller.field.last { it.hasMine }
|
||||
assertEquals(
|
||||
listOf(92, 91, 81, 70, 86, 41, 87, 67, 33, 36, 13, 59, 38, 27, 49, 4, 39, 5, 29, 19),
|
||||
listOf(95, 85, 74, 73, 65, 88, 55, 91, 45, 52, 90, 47, 59, 42, 36, 32, 39, 28, 4, 3),
|
||||
controller.takeExplosionRadius(lastMine).map { it.id }.toList()
|
||||
)
|
||||
|
||||
|
|
|
@ -83,7 +83,7 @@ class MinefieldFactoryTest {
|
|||
preferencesRepository
|
||||
).run {
|
||||
assertEquals(49, width)
|
||||
assertEquals(97, height)
|
||||
assertEquals(96, height)
|
||||
assertEquals(950, mines)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue