Compare commits

..

No commits in common. "dev" and "main" have entirely different histories.
dev ... main

5 changed files with 159 additions and 175 deletions

View File

@ -11,8 +11,8 @@ android {
applicationId = "com.hyperling.tictactoe" applicationId = "com.hyperling.tictactoe"
minSdk = 21 minSdk = 21
targetSdk = 34 targetSdk = 34
versionCode = 3 versionCode = 1
versionName = "1.0.2" versionName = "1.0"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables { vectorDrawables {

View File

@ -194,8 +194,8 @@ fun Game() {
Column( Column(
horizontalAlignment = Alignment.CenterHorizontally horizontalAlignment = Alignment.CenterHorizontally
, verticalArrangement = Arrangement.Center , verticalArrangement = Arrangement.Center
//, modifier = Modifier , modifier = Modifier
// .fillMaxSize() .fillMaxSize()
) { ) {
Spacer(modifier = Modifier.weight(0.1f)) Spacer(modifier = Modifier.weight(0.1f))
@ -346,15 +346,6 @@ fun Game() {
fontSize = 16.sp fontSize = 16.sp
) )
Spacer(modifier = Modifier.size(5.dp)) Spacer(modifier = Modifier.size(5.dp))
Row(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.SpaceEvenly
) {
Column (
horizontalAlignment = Alignment.Start,
verticalArrangement = Arrangement.Top
) {
Row ( Row (
verticalAlignment = Alignment.CenterVertically, verticalAlignment = Alignment.CenterVertically,
modifier = Modifier.clickable { modifier = Modifier.clickable {
@ -370,6 +361,21 @@ fun Game() {
fontSize = 16.sp fontSize = 16.sp
) )
} }
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 ( Row (
verticalAlignment = Alignment.CenterVertically, verticalAlignment = Alignment.CenterVertically,
modifier = Modifier.clickable { modifier = Modifier.clickable {
@ -385,42 +391,6 @@ fun Game() {
fontSize = 16.sp 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
)
}
}
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 ( Row (
verticalAlignment = Alignment.CenterVertically, verticalAlignment = Alignment.CenterVertically,
modifier = Modifier.clickable { modifier = Modifier.clickable {
@ -436,6 +406,21 @@ fun Game() {
fontSize = 16.sp 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 ( Row (
verticalAlignment = Alignment.CenterVertically, verticalAlignment = Alignment.CenterVertically,
modifier = Modifier.clickable { modifier = Modifier.clickable {
@ -452,8 +437,6 @@ fun Game() {
) )
} }
} }
}
}
Spacer(modifier = Modifier.weight(.05f)) Spacer(modifier = Modifier.weight(.05f))
// */ // */
@ -649,10 +632,10 @@ fun playWeightedMove(grid: MutableList<String>, behavior: Int, piece: String) :
// Easy, does not prevent human from winning and may try to win. // Easy, does not prevent human from winning and may try to win.
0 -> { 0 -> {
causeWin = 100 causeWin = 100
preventLoss = -25 preventLoss = -1
middle = 0 middle = 1
corner = 0 corner = 1
side = 0 side = 1
} }
// Hard, will try to win for itself and prevent the human from winning. // Hard, will try to win for itself and prevent the human from winning.
1 -> { 1 -> {
@ -664,7 +647,7 @@ fun playWeightedMove(grid: MutableList<String>, behavior: Int, piece: String) :
} }
// Annoying / stubborn, will not let you win but also will not try to win. // Annoying / stubborn, will not let you win but also will not try to win.
2 -> { 2 -> {
causeWin = -25 causeWin = 99
preventLoss = 100 preventLoss = 100
middle = 4 middle = 4
corner = 3 corner = 3
@ -672,11 +655,11 @@ fun playWeightedMove(grid: MutableList<String>, behavior: Int, piece: String) :
} }
// Shy, refuses to complete the game unless it's the only move left. // Shy, refuses to complete the game unless it's the only move left.
3 -> { 3 -> {
causeWin = -25 causeWin = -1
preventLoss = -25 preventLoss = -1
middle = 4 middle = 1
corner = 3 corner = 1
side = 2 side = 1
} }
// Random! No need for the other function anymore. ;) // Random! No need for the other function anymore. ;)
else -> { else -> {
@ -697,131 +680,132 @@ fun playWeightedMove(grid: MutableList<String>, behavior: Int, piece: String) :
// Top Row, Win Conditions // Top Row, Win Conditions
if (grid[0] == piece && grid[1] == piece && grid[2].isBlank()) 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) 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) if (grid[0].isBlank() && grid[1] == piece && grid[2] == piece)
weights[0] += causeWin weights[0] = causeWin
// Top Row, Lose Conditions // Top Row, Lose Conditions
if (grid[0] == human && grid[1] == human && grid[2].isBlank()) 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) 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) if (grid[0].isBlank() && grid[1] == human && grid[2] == human)
weights[0] += preventLoss weights[0] = preventLoss
// Middle Row, Win Conditions // Middle Row, Win Conditions
if (grid[3] == piece && grid[4] == piece && grid[5].isBlank()) 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) 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) if (grid[3].isBlank() && grid[4] == piece && grid[5] == piece)
weights[3] += causeWin weights[3] = causeWin
// Middle Row, Lose Conditions // Middle Row, Lose Conditions
if (grid[3] == human && grid[4] == human && grid[5].isBlank()) 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) 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) if (grid[3].isBlank() && grid[4] == human && grid[5] == human)
weights[3] += preventLoss weights[3] = preventLoss
// Bottom Row, Win Conditions // Bottom Row, Win Conditions
if (grid[6] == piece && grid[7] == piece && grid[8].isBlank()) 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) 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) if (grid[6].isBlank() && grid[7] == piece && grid[8] == piece)
weights[6] += causeWin weights[6] = causeWin
// Bottom Row, Lose Conditions // Bottom Row, Lose Conditions
if (grid[6] == human && grid[7] == human && grid[8].isBlank()) 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) 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) if (grid[6].isBlank() && grid[7] == human && grid[8] == human)
weights[6] += preventLoss weights[6] = preventLoss
// Left Column, Win Conditions // Left Column, Win Conditions
if (grid[0] == piece && grid[3] == piece && grid[6].isBlank()) 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) 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) if (grid[0].isBlank() && grid[3] == piece && grid[6] == piece)
weights[0] += causeWin weights[0] = causeWin
// Left Column, Lose Conditions // Left Column, Lose Conditions
if (grid[0] == human && grid[3] == human && grid[6].isBlank()) 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) 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) if (grid[0].isBlank() && grid[3] == human && grid[6] == human)
weights[0] += preventLoss weights[0] = preventLoss
// Middle Column, Win Conditions // Middle Column, Win Conditions
if (grid[1] == piece && grid[4] == piece && grid[7].isBlank()) 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) 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) if (grid[1].isBlank() && grid[4] == piece && grid[7] == piece)
weights[1] += causeWin weights[1] = causeWin
// Middle Column, Lose Conditions // Middle Column, Lose Conditions
if (grid[1] == human && grid[4] == human && grid[7].isBlank()) 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) 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) if (grid[1].isBlank() && grid[4] == human && grid[7] == human)
weights[1] += preventLoss weights[1] = preventLoss
// Right Column, Win Conditions // Right Column, Win Conditions
if (grid[2] == piece && grid[5] == piece && grid[8].isBlank()) 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) 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) if (grid[2].isBlank() && grid[5] == piece && grid[8] == piece)
weights[2] += causeWin weights[2] = causeWin
// Right Column, Lose Conditions // Right Column, Lose Conditions
if (grid[2] == human && grid[5] == human && grid[8].isBlank()) 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) 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) if (grid[2].isBlank() && grid[5] == human && grid[8] == human)
weights[2] += preventLoss weights[2] = preventLoss
// Top Left Diagonal, Win Conditions // Top Left Diagonal, Win Conditions
if (grid[0] == piece && grid[4] == piece && grid[8].isBlank()) 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) 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) if (grid[0].isBlank() && grid[4] == piece && grid[8] == piece)
weights[0] += causeWin weights[0] = causeWin
// Top Left Diagonal, Lose Conditions // Top Left Diagonal, Lose Conditions
if (grid[0] == human && grid[4] == human && grid[8].isBlank()) 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) 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) if (grid[0].isBlank() && grid[4] == human && grid[8] == human)
weights[0] += preventLoss weights[0] = preventLoss
// Top Right Diagonal, Win Conditions // Top Right Diagonal, Win Conditions
if (grid[2] == piece && grid[4] == piece && grid[6].isBlank()) 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) 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) if (grid[2].isBlank() && grid[4] == piece && grid[6] == piece)
weights[2] += causeWin weights[2] = causeWin
// Top Right Diagonal, Lose Conditions // Top Right Diagonal, Lose Conditions
if (grid[2] == human && grid[4] == human && grid[6].isBlank()) 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) 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) 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. // Set all the played pieces to a very low number.

View File

@ -2,15 +2,15 @@
<string name="app_name">Tic-Tac-Toe</string> <string name="app_name">Tic-Tac-Toe</string>
<string name="opponent_header">Choose your opponent:</string> <string name="opponent_header">Choose your opponent:</string>
<string name="opponent_human">Human</string> <string name="opponent_human">Human - Someone next to you.</string>
<string name="opponent_random">AI : Random</string> <string name="opponent_random">AI : Random - Fills any open spot.</string>
<string name="opponent_hard">AI : Hard</string> <string name="opponent_hard">AI : Hard - Your typical try-hard.</string>
<string name="opponent_easy">AI : Easy</string> <string name="opponent_easy">AI : Easy - Opportunist, may try to win.</string>
<string name="opponent_annoying">AI : Stubborn</string> <string name="opponent_annoying">AI : Stubborn - Won\'t let you win.</string>
<string name="opponent_shy">AI : Shy</string> <string name="opponent_shy">AI : Shy - Too scared to win.</string>
<string name="link1_text">Website</string> <string name="link1_text">Website</string>
<string name="link1_uri">https://hyperling.com</string> <string name="link1_uri">https://hyperling.com</string>
<string name="link2_text">Source Code</string> <string name="link2_text">GitHub</string>
<string name="link2_uri">https://git.hyperling.com/me/android-tictactoe</string> <string name="link2_uri">https://github.com/Hyperling/TicTacToeAndroid</string>
</resources> </resources>

View File

@ -1,5 +1,5 @@
[versions] [versions]
agp = "8.7.3" agp = "8.3.1"
kotlin = "1.9.0" kotlin = "1.9.0"
coreKtx = "1.10.1" coreKtx = "1.10.1"
junit = "4.13.2" junit = "4.13.2"

View File

@ -1,6 +1,6 @@
#Sat Mar 30 12:28:25 MST 2024 #Sat Mar 30 12:28:25 MST 2024
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists