working implementation of minimax