public static double[][] costMap(double[][] energyMap){
    double[][] costMap=new double[energyMap.length][energyMap[0].length];
    //Compute the costs of the top (i.e. the values)
    for(int j=0;j<costMap[0].length;j++){
      costMap[0][j]=energyMap[0][j];
    }
    //Compute the rest of the minimum costs
    for(int i=1;i<costMap.length;i++){
      for(int j=0;j<costMap[i].length;j++){
        double min=Double.MAX_VALUE;
        if(isValidPoint(costMap,i-1,j-1) && costMap[i-1][j-1]<min) min=costMap[i-1][j-1];
        if(isValidPoint(costMap,i-1,j) && costMap[i-1][j]<min) min=costMap[i-1][j];
        if(isValidPoint(costMap,i-1,j+1) && costMap[i-1][j+1]<min) min=costMap[i-1][j+1];
        costMap[i][j]=min+energyMap[i][j];
      }
    }
    return costMap;
  }