added minimax
refactor minimax