-
Notifications
You must be signed in to change notification settings - Fork 50
/
Omok.kt
30 lines (25 loc) · 962 Bytes
/
Omok.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package game
import Board
import Stone
import StoneColor
import listener.OmokEventListener
import player.BlackPlayer
import player.WhitePlayer
class Omok(private val eventListener: OmokEventListener) {
private val board = Board(BlackPlayer(), WhitePlayer())
fun run() {
eventListener.onStartGame()
var currentStoneColor: StoneColor = StoneColor.BLACK
var currentBoard: Board = board
do {
currentBoard = takeTurn(currentBoard, currentStoneColor)
eventListener.onEndTurn(currentBoard.getPlayers())
currentStoneColor = currentStoneColor.next()
} while (currentBoard.isRunning())
eventListener.onEndGame(board.getWinner())
}
private fun takeTurn(board: Board, stoneColor: StoneColor): Board {
val newStone = Stone.of(eventListener.onTakeTurn(stoneColor))
return board.putStone(stoneColor, newStone) ?: return takeTurn(board, stoneColor)
}
}