-
Notifications
You must be signed in to change notification settings - Fork 0
Strategy
There are lots of ways to win.
- Efficient bots, can look further ahead
- Smart bots, are able to make good decissions
- Random bots, will always have a change of winning
- Parsing
Once you receive the String with the board data, you need to parse it. You can use your favourite parser, but you'll want to go for the fastest parser out there.
- Finding possible moves
Finding possible moves, requires you to implement an algorithm that can do that. Again, the faster you can do this, the more time you have to look ahead.
- Caching
If you implement Minimax or something similar, you are performing a lot of calculations. Many times, these calculations can be cached locally. E.g. if you have seen a board before, you can look up the corresponding evaluation score from a DB or from a Cache
For each possible move, you need to evaluate the board. This can be as easy as counting the number of stones, but it can be very complex as well.
Samples evaluation functions:
private fun go() {
val board = arrayOf(arrayOf(0, 0, 1),arrayOf(-1, -1, 1),arrayOf(0, 0, 1))
val scoreSimple = eval1(board, 1)
val scoreAdvanced = eval2(board, 1)
}
private fun eval1(board: Array<Array<Int>>, color: Int): Int {
return color * board.sumBy { it.sumBy { it } }
}
private fun eval2(board: Array<Array<Int>>, color: Int): Int {
val stones = board.sumBy { it.sumBy { it } }
val corners = board.filter{ isCorner(it) }.sumBy { it.sumBy { it } }
val moves = board.filter{ isMyColor(color) }.sumBy { isValidMove(it, color) }
val opponentMoves = board.filter{ isMyColor(-1 * color) }.sumBy { isValidMove(it, -1 * color) }
return color * (1000 * corners) + (2 * stones) + (5 * moves) - (5 * opponentMoves)
}
eval1
is simple and fast. eval2
takes more time, but might be able to make "smarter" moves.