Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,18 @@ dependencies {

implementation 'com.github.PhilJay:MPAndroidChart:v3.1.0'

implementation 'com.github.sephiroth74:NumberSlidingPicker:v1.0.3'

implementation 'com.github.tony19:logback-android:2.0.0'
implementation('com.github.toomasr:sgf4j:sgf4j-parser-0.0.6') {
// Force to use android logging
exclude group: 'org.apache.logging.log4j', module: 'log4j-slf4j-impl'
exclude group: 'org.apache.logging.log4j', module: 'log4j-api'
exclude group: 'org.apache.logging.log4j', module: 'log4j-core'
}

implementation 'com.vmadalin:easypermissions-ktx:1.0.0'

testImplementation 'com.nhaarman:mockito-kotlin-kt1.1:1.6.0'
testImplementation 'junit:junit:4.13.2'
testImplementation "io.insert-koin:koin-test-junit4:$koin_version"
Expand Down
20 changes: 20 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="com.google.android.gms.permission.AD_ID" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<application
android:allowBackup="true"
Expand Down Expand Up @@ -37,6 +39,24 @@

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />

<data android:scheme="file" android:mimeType="application/x-go-sgf" android:pathPattern=".*\\.sgf" />
<data android:scheme="content" android:pathPattern=".*\\.sgf" android:mimeType="application/x-go-sgf" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />

<data android:scheme="http" android:host="*" android:mimeType="application/x-go-sgf" />
<data android:scheme="https" android:host="*" android:mimeType="application/x-go-sgf" />
</intent-filter>
</activity>
<activity
android:name=".ui.screens.login.FacebookLoginCallbackActivity"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ import io.zenandroid.onlinego.data.model.StoneType
import io.zenandroid.onlinego.data.model.katago.KataGoResponse
import io.zenandroid.onlinego.data.model.katago.KataGoResponse.*
import io.zenandroid.onlinego.data.model.katago.Query
import io.zenandroid.onlinego.data.repositories.SettingsRepository
import io.zenandroid.onlinego.gamelogic.Util
import io.zenandroid.onlinego.utils.recordException
import org.koin.core.context.GlobalContext
import java.io.*
import java.util.*
import java.util.concurrent.atomic.AtomicLong
Expand All @@ -38,6 +40,8 @@ object KataGoAnalysisEngine {
private val netFile = File(filesDir, "katagonet.gz")
private val cfgFile = File(filesDir, "katago.cfg")

private val settingsRepository: SettingsRepository by GlobalContext.get().inject()

@Throws(IOException::class)
@Synchronized
fun startEngine() {
Expand Down Expand Up @@ -134,7 +138,7 @@ object KataGoAnalysisEngine {
fun analyzeMoveSequence(
sequence: List<Position>,
komi: Float? = null,
maxVisits: Int? = null,
maxVisits: Int? = settingsRepository.maxVisits,
includeOwnership: Boolean? = null,
includeMovesOwnership: Boolean? = null,
includePolicy: Boolean? = null
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package io.zenandroid.onlinego.data.model.local

import android.util.Log
import io.zenandroid.onlinego.data.model.Position
import io.zenandroid.onlinego.data.model.ogs.GameData
import io.zenandroid.onlinego.data.model.ogs.OGSGame
import io.zenandroid.onlinego.data.model.ogs.Phase
import io.zenandroid.onlinego.data.ogs.TimeControl
import io.zenandroid.onlinego.utils.toEpochMicros

data class SgfData(
val name: String?,
var position: Position?,
var handicap: Int?,
val rules: String?
) {
companion object {
fun fromString(game: String): SgfData {
return SgfData(
name = null,
handicap = null,
rules = null,
position = null
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ private const val BOARD_THEME = "board_theme"
private const val SHOW_RANKS = "show_ranks"
private const val SHOW_COORDINATES = "show_coordinates"
private const val SOUND = "sound"
private const val MAX_VISITS = "max_ai_visits"
private const val DETAILED_ANALYSIS = "detailed_analysis"

class SettingsRepository {
private val prefs = PreferenceManager.getDefaultSharedPreferences(OnlineGoApplication.instance.baseContext)
Expand Down Expand Up @@ -44,4 +46,12 @@ class SettingsRepository {
var sound: Boolean
get() = prefs.getBoolean(SOUND, true)
set(value) = prefs.edit().putBoolean(SOUND, value).apply()
}

var maxVisits: Int
get() = prefs.getInt(MAX_VISITS, 30)
set(value) = prefs.edit().putInt(MAX_VISITS, value).apply()

var detailedAnalysis: Boolean
get() = prefs.getBoolean(DETAILED_ANALYSIS, false)
set(value) = prefs.edit().putBoolean(DETAILED_ANALYSIS, value).apply()
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ import androidx.compose.ui.res.imageResource
import androidx.compose.ui.res.vectorResource
import androidx.compose.ui.unit.IntSize
import androidx.compose.ui.unit.dp
import io.zenandroid.onlinego.OnlineGoApplication
import io.zenandroid.onlinego.data.model.BoardTheme
import io.zenandroid.onlinego.data.model.Cell
import io.zenandroid.onlinego.data.model.Position
import io.zenandroid.onlinego.data.model.StoneType
import io.zenandroid.onlinego.data.model.ogs.PlayCategory
import io.zenandroid.onlinego.data.repositories.SettingsRepository
import io.zenandroid.onlinego.gamelogic.RulesManager.isPass
import io.zenandroid.onlinego.utils.recordException
import org.koin.core.context.GlobalContext
import kotlin.math.ceil
import kotlin.math.roundToInt
Expand Down Expand Up @@ -68,6 +70,12 @@ fun Board(

// Board background image, it is either a jpg or a svg
val backgroundImage: ImageBitmap? = boardTheme.backgroundImage?.let {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
boardTheme.backgroundImage.run {
Exception("blep: $this, ${OnlineGoApplication.instance.getDrawable(this)}")
.let(::recordException)
}
}
ImageBitmap.imageResource(id = boardTheme.backgroundImage)
}
val backgroundColor: Color? = boardTheme.backgroundColor?.let {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import io.zenandroid.onlinego.data.model.Cell
import io.zenandroid.onlinego.data.model.Position
import io.zenandroid.onlinego.data.model.katago.KataGoResponse.Response
import io.zenandroid.onlinego.data.model.katago.MoveInfo
import io.zenandroid.onlinego.data.model.local.SgfData

sealed class AiGameAction {
object ViewReady: AiGameAction()
class ViewReady(val loadData: SgfData?, val savedData: String?): AiGameAction()
object ViewPaused: AiGameAction()
class RestoredState(val state: AiGameState): AiGameAction()
object CantRestoreState: AiGameAction()
Expand All @@ -16,6 +17,7 @@ sealed class AiGameAction {
class NewGame(
val size: Int,
val youPlayBlack: Boolean,
val youPlayWhite: Boolean,
val handicap: Int
): AiGameAction()

Expand All @@ -28,11 +30,12 @@ sealed class AiGameAction {

class NewPosition(val newPos: Position): AiGameAction()
class AIMove(val newPos: Position, val aiAnalisis: Response, val selectedMove: MoveInfo): AiGameAction()
object NextPlayerChanged: AiGameAction()
object AIError: AiGameAction()
class AIHint(val aiAnalisis: Response): AiGameAction()
class AIOwnershipResponse(val aiAnalisis: Response): AiGameAction()
object HideOwnership: AiGameAction()
class ScoreComputed(val newPos: Position, val whiteScore: Float, val blackScore: Int, val aiWon: Boolean, val aiAnalisis: Response): AiGameAction()
class ScoreComputed(val newPos: Position, val whiteScore: Float, val blackScore: Int, val whiteWon: Boolean, val aiAnalisis: Response): AiGameAction()


// User actions
Expand All @@ -46,6 +49,7 @@ sealed class AiGameAction {
object UserAskedForOwnership: AiGameAction()
class UserTriedSuicidalMove(val coordinate: Cell): AiGameAction()
class UserTriedKoMove(val coordinate: Cell): AiGameAction()
object ToggleAIBlack: AiGameAction()
object ToggleAIWhite: AiGameAction()


}
}
Loading