fun decideMove(state: IGameState): IGameMove? { if (state.isDraw()) return null if (state.isWin()) return null val moves: Collection<IGameMove> = logic.validMoves(this, state) return if (moves.size == 0) { null } else { val mvs: Array<IGameMove> = moves.toArray(arrayOf<IGameMove>()) val idx = (Math.random() * moves.size).toInt() mvs[idx] } }
Randomly make a move based upon the available logic of the game . Make sure you check that the game is not already won , lost or drawn before calling this method , because you