% in Barto et. al. work, the state space was divided into 162 boxes.
% 
% get_box.m
function box=get_box(x,x_dot,theta,theta_dot);
one=pi/180; six=6*pi/180; twelve=12*pi/180; fifty=50*pi/180;

if abs(x)>2.4 | abs(theta)>twelve
   % return -1 to signal a failure
   box=-1;
else
   
  if x<-0.8, 					box=1;		% MATLAB can only start with 1, not 0
  elseif x<0.8,				box=2;
  else,							box=3;
  end

  if x_dot<-0.5,				box=box+0;
  elseif x_dot<0.5,			box=box+3;
  else, 							box=box+6;
  end
         
  if theta<-six, 				box=box+0;
  elseif theta<-one,			box=box+9;
  elseif theta<0,				box=box+18;
  elseif theta<one,			box=box+27;
  elseif theta<six,			box=box+36;
  else,							box=box+45;
  end

  if theta_dot<-fifty,		box=box+0;
  elseif theta_dot<fifty,	box=box+54;
  else,							box=box+108;
  end

end

% uncomment the next line, you will see the box the state is in.
% box=box	