Now AIs are simulating human players but I wonder how I should possibly implement the ai into the code?
- Should I make the AI use the player UI to simulate player behaviour or should the AI use direct commands but simulate as if it would be limited to the same UI restrictions as the player?
The unit (regardless of PC or NPC) should be controlled by an API on top of the unit's state. The interface allows for triggering actions and influencing variables like desired movement speed. This is in total what defines what the unit is able to do and how it is controlled. The player gets a player controller that translates (G)UI input into invocations of the unit control. The AI (how ever it is implemented) also invokes the unit control interface in the end. This way both the player as well as an AI is able to request for actions to be performed by the respective unit.
One advantage of the above approach is the clear distinction between layers of functionality. Regardless of the unit, if you have a controller that is able to support all actions provides by the unit, then it can be used to control it. Further, the underlying system like locomotion, animation, and physics are independent on how exactly the unit is controlled. Benefitting side effects: Want to take over control of another character, e.g. to check for its animation clips correctness during development? No problem (if you have a suitable controller, of course). Want to make the UI for the PC configurable? The unit's API tells you what is possible. Want to try out another AI method? You just need to go down to the level of actions (which belongs to AI anyway) but no further.
Notice that with the above the AI does not suffer from "the same UI restrictions as the player". Otherwise it would make no sense, IMHO. The (G)UI is what is named the interface for the human to control the machine. It is one of your tasks to implement a (G)UI and controller in the best foreseeable way to feed the unit's API. On the other hand, the unit's abilities are provided in a defined and consistent way and are the same for the player as well as for the AI (in the margins of a given game mechanics). The restrictions being inherent there are the same for players as well as for AI.