Refactor of Minimax algorithm