Skip to content

Commit 7c9134a

Browse files
committed
Reverted max difficulty to the old maximum
1 parent 93cb883 commit 7c9134a

File tree

5 files changed

+19
-24
lines changed

5 files changed

+19
-24
lines changed

app/src/main/java/com/flaghacker/sttt/bots/MMBot.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import java.lang.Math.max
1010

1111
class MMBot(private val depth: Int) : Bot {
1212
override fun move(board: Board, timer: Timer): Byte? {
13-
return negaMax(board, value(board), depth + 1,
14-
NEGATIVE_INFINITY, POSITIVE_INFINITY, playerSign(board.nextPlayer())).move
13+
return negaMax(board, value(board), depth,
14+
NEGATIVE_INFINITY, POSITIVE_INFINITY, playerSign(board.nextPlayer())).move
1515
}
1616

1717
private class ValuedMove(val move: Byte, val value: Double)

app/src/main/java/com/flaghacker/sttt/common/Board.kt

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@ package com.flaghacker.sttt.common
33
import java.io.Serializable
44
import java.util.*
55

6-
typealias Coord = Byte
7-
86
fun toCoord(x: Int, y: Int) = (((x / 3) + (y / 3) * 3) * 9 + ((x % 3) + (y % 3) * 3)).toByte()
97
fun Int.toPair() = toByte().toPair()
10-
fun Coord.toPair(): Pair<Int, Int> {
8+
fun Byte.toPair(): Pair<Int, Int> {
119
val om = this / 9
1210
val os = this % 9
1311
return Pair((om % 3) * 3 + (os % 3), (om / 3) * 3 + (os / 3))
@@ -27,7 +25,7 @@ class Board : Serializable {
2725
private var rows: Array<Int> = Array(6) { 0 }
2826
private var macroMask = 0b111111111
2927
private var nextPlayer: Player = Player.PLAYER
30-
private var lastMove: Coord? = null
28+
private var lastMove: Byte? = null
3129
private var wonBy = Player.NEUTRAL
3230

3331
constructor()
@@ -42,7 +40,7 @@ class Board : Serializable {
4240
lastMove = board.lastMove
4341
}
4442

45-
constructor(board: Array<Array<Player>>, macroMask: Int, lastMove: Coord?) {
43+
constructor(board: Array<Array<Player>>, macroMask: Int, lastMove: Byte?) {
4644
if (board.size != 9 && board.all { it.size != 9 })
4745
throw IllegalArgumentException("Input board is the wrong size (input: $board)")
4846
else if (macroMask < 0 || macroMask > 0b111111111)
@@ -96,8 +94,8 @@ class Board : Serializable {
9694
return board
9795
}
9896

99-
fun availableMoves(): List<Coord> {
100-
val output = ArrayList<Coord>()
97+
fun availableMoves(): List<Byte> {
98+
val output = ArrayList<Byte>()
10199

102100
for (macro in 0 until 9) {
103101
if (macroMask.getBit(macro)) {
@@ -115,13 +113,13 @@ class Board : Serializable {
115113
else -> Player.NEUTRAL
116114
}
117115

118-
fun tile(index: Coord): Player = when {
116+
fun tile(index: Byte): Player = when {
119117
rows[index / 27].getBit(index % 27) -> Player.PLAYER
120118
rows[3 + index / 27].getBit(index % 27) -> Player.ENEMY
121119
else -> Player.NEUTRAL
122120
}
123121

124-
fun play(index: Coord): Boolean {
122+
fun play(index: Byte): Boolean {
125123
val row = index / 27 //Row (0,1,2)
126124
val macroShift = (index / 9) % 3 * 9 //Shift to go to the right micro (9om)
127125
val moveShift = index % 9 //Shift required for index within matrix (os)

app/src/main/java/com/henrykvdb/sttt/BoardView.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import android.view.MotionEvent
99
import android.view.View
1010
import android.widget.TextView
1111
import com.flaghacker.sttt.common.Board
12-
import com.flaghacker.sttt.common.Coord
1312
import com.flaghacker.sttt.common.Player
1413
import com.flaghacker.sttt.common.toCoord
1514

@@ -19,7 +18,7 @@ class BoardView(context: Context?, attrs: AttributeSet?) : View(context, attrs)
1918
private val path: Path = Path()
2019
private val paint: Paint = Paint()
2120

22-
private lateinit var moveCallback: Callback<Coord>
21+
private lateinit var moveCallback: Callback<Byte>
2322
private var gameState: GameState = GameState.Builder().build()
2423
private var nextPlayerView: TextView? = null
2524

@@ -46,7 +45,7 @@ class BoardView(context: Context?, attrs: AttributeSet?) : View(context, attrs)
4645
postInvalidate()
4746
}
4847

49-
fun setup(moveCallback: Callback<Coord>, nextPlayerView: TextView) {
48+
fun setup(moveCallback: Callback<Byte>, nextPlayerView: TextView) {
5049
this.moveCallback = moveCallback
5150
this.nextPlayerView = nextPlayerView
5251
}

app/src/main/java/com/henrykvdb/sttt/MainActivity.kt

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import android.widget.RadioButton
2929
import android.widget.RadioGroup
3030
import android.widget.TextView
3131
import android.widget.Toast
32-
import com.flaghacker.sttt.common.Coord
3332
import com.flaghacker.sttt.common.Player
3433
import com.flaghacker.sttt.common.Timer
3534
import com.google.android.gms.ads.AdRequest
@@ -116,8 +115,8 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
116115
//Prepare fields
117116
btAdapter = BluetoothAdapter.getDefaultAdapter()
118117
boardView = findViewById(R.id.boardView)
119-
boardView?.setup(object : Callback<Coord> {
120-
override fun invoke(coord: Coord) {
118+
boardView?.setup(object : Callback<Byte> {
119+
override fun invoke(coord: Byte) {
121120
gameThread.play(Source.Local, coord)
122121
}
123122
}, findViewById(R.id.next_move_view))
@@ -252,7 +251,7 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
252251
when (action) {
253252
INTENT_MOVE -> {
254253
val src = intent.getSerializableExtra(INTENT_DATA_FIRST) as Source
255-
val move = intent.getSerializableExtra(INTENT_DATA_SECOND) as Coord
254+
val move = intent.getSerializableExtra(INTENT_DATA_SECOND) as Byte
256255
gameThread.play(src, move)
257256
}
258257
INTENT_NEWGAME -> newGame(intent.getSerializableExtra(INTENT_DATA_FIRST) as GameState)
@@ -349,7 +348,7 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
349348

350349
private inner class GameThread : Thread(), Closeable {
351350
private val playerLock = java.lang.Object()
352-
private val playerMove = AtomicReference<Pair<Coord, Source>>()
351+
private val playerMove = AtomicReference<Pair<Byte, Source>>()
353352

354353
@Volatile
355354
private var running: Boolean = false
@@ -378,8 +377,8 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
378377
}
379378
}
380379

381-
private fun waitForMove(player: Source): Coord? {
382-
playerMove.set(Pair<Coord, Source>(null, null))
380+
private fun waitForMove(player: Source): Byte? {
381+
playerMove.set(Pair<Byte, Source>(null, null))
383382
while ((!gs!!.board().availableMoves().contains(playerMove.get().first) //Impossible move
384383
|| player != playerMove.get().second //Wrong player
385384
|| playerMove.get() == null //No Pair
@@ -398,7 +397,7 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
398397
return playerMove.getAndSet(null).first
399398
}
400399

401-
fun play(source: Source, move: Coord) {
400+
fun play(source: Source, move: Byte) {
402401
synchronized(playerLock) {
403402
playerMove.set(Pair(move, source))
404403
playerLock.notify() //TODO fix #1

app/src/main/java/com/henrykvdb/sttt/util/IntentUtil.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@ package com.henrykvdb.sttt.util
22

33
import android.content.Context
44
import android.content.Intent
5-
import com.flaghacker.sttt.common.Coord
65
import com.henrykvdb.sttt.*
76

8-
fun sendMove(context: Context, src: MainActivity.Source, move: Coord) {
7+
fun sendMove(context: Context, src: MainActivity.Source, move: Byte) {
98
val i = Intent(INTENT_MOVE)
109
i.putExtra(INTENT_DATA_FIRST, src)
1110
i.putExtra(INTENT_DATA_SECOND, move)

0 commit comments

Comments
 (0)