Skip to content

Commit b05de2f

Browse files
author
magicgoose
committed
wrong comparison removed
1 parent b4b7c42 commit b05de2f

File tree

2 files changed

+19
-23
lines changed

2 files changed

+19
-23
lines changed

src/magicgoose/gomoku/ai/Brain.scala

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class MoveSearcher(val board: GomokuBoard) {
3131
board.total_size / 2
3232
}
3333
}
34-
34+
3535
def findPossibleMoves(): GrowableArray[Int] = {
3636
import LineInfo._
3737

@@ -67,7 +67,7 @@ class MoveSearcher(val board: GomokuBoard) {
6767
cell += 1
6868
}
6969
}
70-
// if (li(player, 3, ))
70+
// if (li(player, 3, ))
7171
val th3 = li(-player, 3, OPEN) + li(-player, 3, BROKEN)
7272
if (li(player, 3) == 0 && th3 > 0) {
7373
board.withMove(_)(() => {
@@ -96,7 +96,7 @@ class MoveSearcher(val board: GomokuBoard) {
9696
* simple score, with hash lookup
9797
*/
9898
def getSimpleScore() = {
99-
board.heur_score()
99+
board.heur_score()
100100
}
101101

102102
/**
@@ -119,24 +119,21 @@ class MoveSearcher(val board: GomokuBoard) {
119119
if (moves.length == 0) throw new Error("This should not happen! No available moves.")
120120
moves.sortByInplace(test_move_heur)
121121
if (board.pieces == 1) moves.trim(2)
122-
if (moves.head <= -LineInfo.WIN) moves.head
123-
else {
124-
var bestmove = 0
125-
var bestscore = alpha
126-
@inline def loop(i: Int): Int = {
127-
if (i < moves.length) {
128-
val recursedscore: Int = -search_score(moves(i), depth, -b, -bestscore)
129-
if (recursedscore > bestscore) {
130-
bestscore = recursedscore
131-
bestmove = moves(i)
132-
}
133-
if (bestscore >= LineInfo.WIN1) {
134-
bestmove
135-
} else loop(i + 1)
136-
} else bestmove
137-
}
138-
loop(0)
122+
var bestmove = 0
123+
var bestscore = alpha
124+
@inline def loop(i: Int): Int = {
125+
if (i < moves.length) {
126+
val recursedscore: Int = -search_score(moves(i), depth, -b, -bestscore)
127+
if (recursedscore > bestscore) {
128+
bestscore = recursedscore
129+
bestmove = moves(i)
130+
}
131+
if (bestscore >= LineInfo.WIN1) {
132+
bestmove
133+
} else loop(i + 1)
134+
} else bestmove
139135
}
136+
loop(0)
140137
}
141138

142139
/**
@@ -161,8 +158,7 @@ class MoveSearcher(val board: GomokuBoard) {
161158
val result =
162159
if (he.hash == board.getHash && he.depth == depth) {
163160
he.score
164-
} else
165-
{
161+
} else {
166162
val heur = board.heur_score()
167163
if (math.abs(heur) >= LineInfo.WIN1 || depth <= 0)
168164
heur

src/magicgoose/gomoku/gui/GomokuMainWindow.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ class GomokuMainWindow {
234234

235235
content.add(board_container, BorderLayout.CENTER)
236236
content.add(panel_box(
237-
intSlider(name = "AI strength", value = 4, min = 1, max = 6, handler = change_strength),
237+
intSlider(name = "AI strength", value = searcher.max_depth, min = 1, max = 6, handler = change_strength),
238238
button("Undo move", undo_move),
239239
button("Force computer move & Switch side", switch_side),
240240
button("Load position", load_position),

0 commit comments

Comments
 (0)