About the environments
For the controller part of your question, I would advice looking at openAI gym.
https://www.gymlibrary.ml/content/environment_creation/ #how to make your own gym enviroment
Those gym enviroments work kinda like this
env = gym.make("ALE/SpaceInvaders-v5")
observation = env.reset()
observation, reward, done =env.step(action)
Where your observation can be pixels,ram dumps, etc. The actions can be internally mapped to key presses. (but the internals don't really matter that much) Gym environments are just an easy way to then have your agent take in the observations and map them to actions. So your game can be stepped through so you don't have to worry about a complicated way to integrate the AI and keeping it synced.
There are already a bunch of artari games included (also ms pacman) https://www.gymlibrary.ml/environments/atari/
About the AI
Since you want to learn directly from the pixels or other more complex data types I advice you to read this:
Deep Reinforcement Learning, a textbook (arXiv:2201.02135)
https://arxiv.org/abs/2201.02135
If you just want some simple tutorial just read "Hands-On Reinforcement Learning with Python", then you can try to implement something like DQN , with some cnn architecture. (similar to how they did in arXiv:1312.5602 "Playing Atari with Deep Reinforcement Learning").
Since DQN is model free, off policy and relatively easy to implement.
(cool thing about off policy is that your agent doesnt have to interact with the environment as it doesnt need to sample "experience" using only it's current policy (way of choosing actions given a state) so you can even play the game itself and collect information (a,s,s',r) while playing and train your agent on that (to nudge it in the right direction if it gets stuck))
if you're not a fan of gradient descent based methods, you can also use methods like ES (evolutionary strategies). As that way you can directly optimize for a reward. (it's a genetic algorithm that scales well in both compute and dimensionality) (arXiv:1703.03864 Evolution Strategies as a
Scalable Alternative to Reinforcement Learning)