Trying to implement valueIteration