first version of minmax algorithm