implemented minmax algorithm