Monte Carlo Tree Search in connect 5 tree design
In you implementation you need to separate the game rules from the mcts search algorithm. Mcts does not need an evaluation like minimax. When calling random playouts all you need to do is keep making legal moves till the game ends and mark the playout with an outcome of win/loss.

your game rules need functions like
legal_moves, make_move, undo_move, is_game_over, winnerIs and maintain a states that represent the position

your mcts needs
mcts, ucb_sample, expand, random_playout, backpropogation

for states you need
position {visits, value or total/count}