Create best.R

Starting. What is missing is the addition of the state variable in the  if conditions.