diff --git a/README.md b/README.md index 01fd259..41aec63 100644 --- a/README.md +++ b/README.md @@ -8,9 +8,9 @@ and maybe even make the game mad. 🐇🥚 ## Download -App is hosted at [Hyperling.com](https://hyperling.com/home/#tictactoe) where +App is hosted at [git.hyperling.com](https://git.hyperling.com/me/android-tictactoe) where it is also available for -[Direct Download](https://hyperling.com/files/apks/TicTacToe.apk). +[Direct Download](https://git.hyperling.com/me/android-tictactoe/releases). ## TODO diff --git a/app/build.gradle.kts b/app/build.gradle.kts index a281a7c..2a2f3e4 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -5,14 +5,14 @@ plugins { android { namespace = "com.hyperling.tictactoe" - compileSdk = 34 + compileSdk = 36 defaultConfig { applicationId = "com.hyperling.tictactoe" minSdk = 21 - targetSdk = 34 - versionCode = 1 - versionName = "1.0" + targetSdk = 36 + versionCode = 4 + versionName = "1.1.0" testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" vectorDrawables { @@ -22,7 +22,7 @@ android { buildTypes { release { - isMinifyEnabled = false + isMinifyEnabled = true proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro") } } @@ -47,7 +47,6 @@ android { } dependencies { - implementation(libs.androidx.core.ktx) implementation(libs.androidx.lifecycle.runtime.ktx) implementation(libs.androidx.activity.compose) diff --git a/app/src/main/java/com/hyperling/tictactoe/MainActivity.kt b/app/src/main/java/com/hyperling/tictactoe/MainActivity.kt index 16f30ad..e17010f 100644 --- a/app/src/main/java/com/hyperling/tictactoe/MainActivity.kt +++ b/app/src/main/java/com/hyperling/tictactoe/MainActivity.kt @@ -194,8 +194,8 @@ fun Game() { Column( horizontalAlignment = Alignment.CenterHorizontally , verticalArrangement = Arrangement.Center - , modifier = Modifier - .fillMaxSize() + //, modifier = Modifier + // .fillMaxSize() ) { Spacer(modifier = Modifier.weight(0.1f)) @@ -346,95 +346,112 @@ fun Game() { fontSize = 16.sp ) Spacer(modifier = Modifier.size(5.dp)) - Row ( + + Row( verticalAlignment = Alignment.CenterVertically, - modifier = Modifier.clickable { - opponentHuman = setRadiosFalse() + horizontalArrangement = Arrangement.SpaceEvenly + ) { + Column ( + horizontalAlignment = Alignment.Start, + verticalArrangement = Arrangement.Top + ) { + Row ( + verticalAlignment = Alignment.CenterVertically, + modifier = Modifier.clickable { + opponentHuman = setRadiosFalse() + } + ){ + RadioButton( + selected = opponentHuman, + onClick = { opponentHuman = setRadiosFalse() }, + ) + Text( + text = stringResource(id = R.string.opponent_human), + fontSize = 16.sp + ) + } + Row ( + verticalAlignment = Alignment.CenterVertically, + modifier = Modifier.clickable { + opponentHard = setRadiosFalse() + } + ){ + RadioButton( + selected = opponentHard, + onClick = { opponentHard = setRadiosFalse() }, + ) + Text( + text = stringResource(id = R.string.opponent_hard), + fontSize = 16.sp + ) + } + Row ( + verticalAlignment = Alignment.CenterVertically, + modifier = Modifier.clickable { + opponentAnnoying = setRadiosFalse() + } + ){ + RadioButton( + selected = opponentAnnoying, + onClick = { opponentAnnoying = setRadiosFalse() }, + ) + Text( + text = stringResource(id = R.string.opponent_annoying), + fontSize = 16.sp + ) + } } - ){ - RadioButton( - selected = opponentHuman, - onClick = { opponentHuman = setRadiosFalse() }, - ) - Text( - text = stringResource(id = R.string.opponent_human), - fontSize = 16.sp - ) - } - Row ( - verticalAlignment = Alignment.CenterVertically, - modifier = Modifier.clickable { - opponentRandom = setRadiosFalse() + + Column ( + horizontalAlignment = Alignment.Start, + verticalArrangement = Arrangement.Bottom + ) { + Row ( + verticalAlignment = Alignment.CenterVertically, + modifier = Modifier.clickable { + opponentRandom = setRadiosFalse() + } + ){ + RadioButton( + selected = opponentRandom, + onClick = { opponentRandom = setRadiosFalse() }, + ) + Text( + text = stringResource(id = R.string.opponent_random), + fontSize = 16.sp + ) + } + Row ( + verticalAlignment = Alignment.CenterVertically, + modifier = Modifier.clickable { + opponentEasy = setRadiosFalse() + } + ){ + RadioButton( + selected = opponentEasy, + onClick = { opponentEasy = setRadiosFalse() }, + ) + Text( + text = stringResource(id = R.string.opponent_easy), + fontSize = 16.sp + ) + } + Row ( + verticalAlignment = Alignment.CenterVertically, + modifier = Modifier.clickable { + opponentShy = setRadiosFalse() + } + ){ + RadioButton( + selected = opponentShy, + onClick = { opponentShy = setRadiosFalse() }, + ) + Text( + text = stringResource(id = R.string.opponent_shy), + fontSize = 16.sp + ) + } } - ){ - RadioButton( - selected = opponentRandom, - onClick = { opponentRandom = setRadiosFalse() }, - ) - Text( - text = stringResource(id = R.string.opponent_random), - fontSize = 16.sp - ) - } - Row ( - verticalAlignment = Alignment.CenterVertically, - modifier = Modifier.clickable { - opponentHard = setRadiosFalse() - } - ){ - RadioButton( - selected = opponentHard, - onClick = { opponentHard = setRadiosFalse() }, - ) - Text( - text = stringResource(id = R.string.opponent_hard), - fontSize = 16.sp - ) - } - Row ( - verticalAlignment = Alignment.CenterVertically, - modifier = Modifier.clickable { - opponentEasy = setRadiosFalse() - } - ){ - RadioButton( - selected = opponentEasy, - onClick = { opponentEasy = setRadiosFalse() }, - ) - Text( - text = stringResource(id = R.string.opponent_easy), - fontSize = 16.sp - ) - } - Row ( - verticalAlignment = Alignment.CenterVertically, - modifier = Modifier.clickable { - opponentAnnoying = setRadiosFalse() - } - ){ - RadioButton( - selected = opponentAnnoying, - onClick = { opponentAnnoying = setRadiosFalse() }, - ) - Text( - text = stringResource(id = R.string.opponent_annoying), - fontSize = 16.sp - ) - } - Row ( - verticalAlignment = Alignment.CenterVertically, - modifier = Modifier.clickable { - opponentShy = setRadiosFalse() - } - ){ - RadioButton( - selected = opponentShy, - onClick = { opponentShy = setRadiosFalse() }, - ) - Text( - text = stringResource(id = R.string.opponent_shy), - fontSize = 16.sp - ) } } Spacer(modifier = Modifier.weight(.05f)) @@ -632,10 +649,10 @@ fun playWeightedMove(grid: MutableList, behavior: Int, piece: String) : // Easy, does not prevent human from winning and may try to win. 0 -> { causeWin = 100 - preventLoss = -1 - middle = 1 - corner = 1 - side = 1 + preventLoss = -25 + middle = 0 + corner = 0 + side = 0 } // Hard, will try to win for itself and prevent the human from winning. 1 -> { @@ -647,7 +664,7 @@ fun playWeightedMove(grid: MutableList, behavior: Int, piece: String) : } // Annoying / stubborn, will not let you win but also will not try to win. 2 -> { - causeWin = 99 + causeWin = -25 preventLoss = 100 middle = 4 corner = 3 @@ -655,11 +672,11 @@ fun playWeightedMove(grid: MutableList, behavior: Int, piece: String) : } // Shy, refuses to complete the game unless it's the only move left. 3 -> { - causeWin = -1 - preventLoss = -1 - middle = 1 - corner = 1 - side = 1 + causeWin = -25 + preventLoss = -25 + middle = 4 + corner = 3 + side = 2 } // Random! No need for the other function anymore. ;) else -> { @@ -680,132 +697,131 @@ fun playWeightedMove(grid: MutableList, behavior: Int, piece: String) : // Top Row, Win Conditions if (grid[0] == piece && grid[1] == piece && grid[2].isBlank()) - weights[2] = causeWin + weights[2] += causeWin if (grid[0] == piece && grid[1].isBlank() && grid[2] == piece) - weights[1] = causeWin + weights[1] += causeWin if (grid[0].isBlank() && grid[1] == piece && grid[2] == piece) - weights[0] = causeWin + weights[0] += causeWin // Top Row, Lose Conditions if (grid[0] == human && grid[1] == human && grid[2].isBlank()) - weights[2] = preventLoss + weights[2] += preventLoss if (grid[0] == human && grid[1].isBlank() && grid[2] == human) - weights[1] = preventLoss + weights[1] += preventLoss if (grid[0].isBlank() && grid[1] == human && grid[2] == human) - weights[0] = preventLoss + weights[0] += preventLoss // Middle Row, Win Conditions if (grid[3] == piece && grid[4] == piece && grid[5].isBlank()) - weights[5] = causeWin + weights[5] += causeWin if (grid[3] == piece && grid[4].isBlank() && grid[5] == piece) - weights[4] = causeWin + weights[4] += causeWin if (grid[3].isBlank() && grid[4] == piece && grid[5] == piece) - weights[3] = causeWin + weights[3] += causeWin // Middle Row, Lose Conditions if (grid[3] == human && grid[4] == human && grid[5].isBlank()) - weights[5] = preventLoss + weights[5] += preventLoss if (grid[3] == human && grid[4].isBlank() && grid[5] == human) - weights[4] = preventLoss + weights[4] += preventLoss if (grid[3].isBlank() && grid[4] == human && grid[5] == human) - weights[3] = preventLoss + weights[3] += preventLoss // Bottom Row, Win Conditions if (grid[6] == piece && grid[7] == piece && grid[8].isBlank()) - weights[8] = causeWin + weights[8] += causeWin if (grid[6] == piece && grid[7].isBlank() && grid[8] == piece) - weights[7] = causeWin + weights[7] += causeWin if (grid[6].isBlank() && grid[7] == piece && grid[8] == piece) - weights[6] = causeWin + weights[6] += causeWin // Bottom Row, Lose Conditions if (grid[6] == human && grid[7] == human && grid[8].isBlank()) - weights[8] = preventLoss + weights[8] += preventLoss if (grid[6] == human && grid[7].isBlank() && grid[8] == human) - weights[7] = preventLoss + weights[7] += preventLoss if (grid[6].isBlank() && grid[7] == human && grid[8] == human) - weights[6] = preventLoss + weights[6] += preventLoss // Left Column, Win Conditions if (grid[0] == piece && grid[3] == piece && grid[6].isBlank()) - weights[6] = causeWin + weights[6] += causeWin if (grid[0] == piece && grid[3].isBlank() && grid[6] == piece) - weights[3] = causeWin + weights[3] += causeWin if (grid[0].isBlank() && grid[3] == piece && grid[6] == piece) - weights[0] = causeWin + weights[0] += causeWin // Left Column, Lose Conditions if (grid[0] == human && grid[3] == human && grid[6].isBlank()) - weights[6] = preventLoss + weights[6] += preventLoss if (grid[0] == human && grid[3].isBlank() && grid[6] == human) - weights[3] = preventLoss + weights[3] += preventLoss if (grid[0].isBlank() && grid[3] == human && grid[6] == human) - weights[0] = preventLoss + weights[0] += preventLoss // Middle Column, Win Conditions if (grid[1] == piece && grid[4] == piece && grid[7].isBlank()) - weights[7] = causeWin + weights[7] += causeWin if (grid[1] == piece && grid[4].isBlank() && grid[7] == piece) - weights[4] = causeWin + weights[4] += causeWin if (grid[1].isBlank() && grid[4] == piece && grid[7] == piece) - weights[1] = causeWin + weights[1] += causeWin // Middle Column, Lose Conditions if (grid[1] == human && grid[4] == human && grid[7].isBlank()) - weights[7] = preventLoss + weights[7] += preventLoss if (grid[1] == human && grid[4].isBlank() && grid[7] == human) - weights[4] = preventLoss + weights[4] += preventLoss if (grid[1].isBlank() && grid[4] == human && grid[7] == human) - weights[1] = preventLoss + weights[1] += preventLoss // Right Column, Win Conditions if (grid[2] == piece && grid[5] == piece && grid[8].isBlank()) - weights[8] = causeWin + weights[8] += causeWin if (grid[2] == piece && grid[5].isBlank() && grid[8] == piece) - weights[5] = causeWin + weights[5] += causeWin if (grid[2].isBlank() && grid[5] == piece && grid[8] == piece) - weights[2] = causeWin + weights[2] += causeWin // Right Column, Lose Conditions if (grid[2] == human && grid[5] == human && grid[8].isBlank()) - weights[8] = preventLoss + weights[8] += preventLoss if (grid[2] == human && grid[5].isBlank() && grid[8] == human) - weights[5] = preventLoss + weights[5] += preventLoss if (grid[2].isBlank() && grid[5] == human && grid[8] == human) - weights[2] = preventLoss + weights[2] += preventLoss // Top Left Diagonal, Win Conditions if (grid[0] == piece && grid[4] == piece && grid[8].isBlank()) - weights[8] = causeWin + weights[8] += causeWin if (grid[0] == piece && grid[4].isBlank() && grid[8] == piece) - weights[4] = causeWin + weights[4] += causeWin if (grid[0].isBlank() && grid[4] == piece && grid[8] == piece) - weights[0] = causeWin + weights[0] += causeWin // Top Left Diagonal, Lose Conditions if (grid[0] == human && grid[4] == human && grid[8].isBlank()) - weights[8] = preventLoss + weights[8] += preventLoss if (grid[0] == human && grid[4].isBlank() && grid[8] == human) - weights[4] = preventLoss + weights[4] += preventLoss if (grid[0].isBlank() && grid[4] == human && grid[8] == human) - weights[0] = preventLoss + weights[0] += preventLoss // Top Right Diagonal, Win Conditions if (grid[2] == piece && grid[4] == piece && grid[6].isBlank()) - weights[6] = causeWin + weights[6] += causeWin if (grid[2] == piece && grid[4].isBlank() && grid[6] == piece) - weights[4] = causeWin + weights[4] += causeWin if (grid[2].isBlank() && grid[4] == piece && grid[6] == piece) - weights[2] = causeWin + weights[2] += causeWin // Top Right Diagonal, Lose Conditions if (grid[2] == human && grid[4] == human && grid[6].isBlank()) - weights[6] = preventLoss + weights[6] += preventLoss if (grid[2] == human && grid[4].isBlank() && grid[6] == human) - weights[4] = preventLoss + weights[4] += preventLoss if (grid[2].isBlank() && grid[4] == human && grid[6] == human) - weights[2] = preventLoss - + weights[2] += preventLoss // */ // Set all the played pieces to a very low number. diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 64640c2..f29f16d 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -2,15 +2,15 @@ Tic-Tac-Toe Choose your opponent: - Human - Someone next to you. - AI : Random - Fills any open spot. - AI : Hard - Your typical try-hard. - AI : Easy - Opportunist, may try to win. - AI : Stubborn - Won\'t let you win. - AI : Shy - Too scared to win. + Human + AI : Random + AI : Hard + AI : Easy + AI : Stubborn + AI : Shy Website https://hyperling.com - GitHub - https://github.com/Hyperling/TicTacToeAndroid + Source Code + https://git.hyperling.com/me/android-tictactoe \ No newline at end of file diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 32534eb..0ca22d3 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,5 +1,5 @@ [versions] -agp = "8.3.1" +agp = "8.11.1" kotlin = "1.9.0" coreKtx = "1.10.1" junit = "4.13.2" diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index bf913c1..f803c2e 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ #Sat Mar 30 12:28:25 MST 2024 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.3-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists