This paper addresses the berthing control problem for automatic ships by using a virtual guide system based on heuristic dynamic programming (HDP) method. Firstly, by introducing an automatic virtual guide system, the berthing control problem can be transformed into a tracking control problem, and then can be further transformed into an optimal regulation problem. Secondly, the HDP method is used to solve the optimal regulation control problem of the marine surface ship with unknown ship model. Then, it is proven that the tracking error, the adaptation laws and the control inputs are uniformly bounded on the basis of the Lyapunov theory. Finally, simulations are carried out on an automatic model ship and the HDP method is compared with the backstepping control to verify the effectiveness of the developed control scheme.