Compare commits
No commits in common. "dev" and "main" have entirely different histories.
@ -11,8 +11,8 @@ android {
|
||||
applicationId = "com.hyperling.tictactoe"
|
||||
minSdk = 21
|
||||
targetSdk = 34
|
||||
versionCode = 3
|
||||
versionName = "1.0.2"
|
||||
versionCode = 1
|
||||
versionName = "1.0"
|
||||
|
||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||
vectorDrawables {
|
||||
|
@ -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,112 +346,95 @@ fun Game() {
|
||||
fontSize = 16.sp
|
||||
)
|
||||
Spacer(modifier = Modifier.size(5.dp))
|
||||
|
||||
Row(
|
||||
Row (
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
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
|
||||
)
|
||||
}
|
||||
modifier = Modifier.clickable {
|
||||
opponentHuman = 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 = opponentHuman,
|
||||
onClick = { opponentHuman = setRadiosFalse() },
|
||||
)
|
||||
Text(
|
||||
text = stringResource(id = R.string.opponent_human),
|
||||
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 (
|
||||
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))
|
||||
@ -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.
|
||||
0 -> {
|
||||
causeWin = 100
|
||||
preventLoss = -25
|
||||
middle = 0
|
||||
corner = 0
|
||||
side = 0
|
||||
preventLoss = -1
|
||||
middle = 1
|
||||
corner = 1
|
||||
side = 1
|
||||
}
|
||||
// Hard, will try to win for itself and prevent the human from winning.
|
||||
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.
|
||||
2 -> {
|
||||
causeWin = -25
|
||||
causeWin = 99
|
||||
preventLoss = 100
|
||||
middle = 4
|
||||
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.
|
||||
3 -> {
|
||||
causeWin = -25
|
||||
preventLoss = -25
|
||||
middle = 4
|
||||
corner = 3
|
||||
side = 2
|
||||
causeWin = -1
|
||||
preventLoss = -1
|
||||
middle = 1
|
||||
corner = 1
|
||||
side = 1
|
||||
}
|
||||
// Random! No need for the other function anymore. ;)
|
||||
else -> {
|
||||
@ -697,131 +680,132 @@ fun playWeightedMove(grid: MutableList<String>, 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.
|
||||
|
@ -2,15 +2,15 @@
|
||||
<string name="app_name">Tic-Tac-Toe</string>
|
||||
|
||||
<string name="opponent_header">Choose your opponent:</string>
|
||||
<string name="opponent_human">Human</string>
|
||||
<string name="opponent_random">AI : Random</string>
|
||||
<string name="opponent_hard">AI : Hard</string>
|
||||
<string name="opponent_easy">AI : Easy</string>
|
||||
<string name="opponent_annoying">AI : Stubborn</string>
|
||||
<string name="opponent_shy">AI : Shy</string>
|
||||
<string name="opponent_human">Human - Someone next to you.</string>
|
||||
<string name="opponent_random">AI : Random - Fills any open spot.</string>
|
||||
<string name="opponent_hard">AI : Hard - Your typical try-hard.</string>
|
||||
<string name="opponent_easy">AI : Easy - Opportunist, may try to win.</string>
|
||||
<string name="opponent_annoying">AI : Stubborn - Won\'t let you win.</string>
|
||||
<string name="opponent_shy">AI : Shy - Too scared to win.</string>
|
||||
|
||||
<string name="link1_text">Website</string>
|
||||
<string name="link1_uri">https://hyperling.com</string>
|
||||
<string name="link2_text">Source Code</string>
|
||||
<string name="link2_uri">https://git.hyperling.com/me/android-tictactoe</string>
|
||||
<string name="link2_text">GitHub</string>
|
||||
<string name="link2_uri">https://github.com/Hyperling/TicTacToeAndroid</string>
|
||||
</resources>
|
@ -1,5 +1,5 @@
|
||||
[versions]
|
||||
agp = "8.7.3"
|
||||
agp = "8.3.1"
|
||||
kotlin = "1.9.0"
|
||||
coreKtx = "1.10.1"
|
||||
junit = "4.13.2"
|
||||
|
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@ -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.9-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
|
Loading…
x
Reference in New Issue
Block a user