Your question is very broad and very vague. Actually, you ask two questions.
1) Is there a way to make an AI system that learns from your actions?
To the first one, the answer is obviously "yes". Let's figure out a hangman game: the AI could figure out what letters you tend to pick frequently and choose words that have few of these letters, just to annoy you. In other words, it learns from you.
This is of course a pretty simple example but still a very valid one. It is actually the simplest model, making counts/statistics about the player's behavior and then applying a counter-action accordingly.
Then, there are all kind of more advanced models, machine learning techniques, neural networks, etc.
2) Is there a way to make a program that writes it own code according to your actions as a player?
Actually, there is no need to write code to adapt to a player's actions. Most of the time, everything in the game boils down to a set of choices and numbers. You can represent the player's location, it's direction, speed, playing cards, whatever, using numbers. So basically, it's just some data crunching which will throw out a number to tell what the AI opponent should do.
Rewriting code at runtime is rarely used, and surely unnecessary for most AI tasks. However, there are some programming languages which can rewrite their own code at run-time, most notably Scheme/Lisp. Others too, even javascript could do it to some extend with "eval", however, it is considered "very" bad practice to do that. Scheme/Lisp on the other hand have very powerful mechanisms to manipulate their own code. I believe in the seventies or eighties there was also research about AI manipulating their own code, but as far as I know, nothing very fancy came out of it.