How do I make enemies fight

I'm planning on making a game that involves sone sort of fighting.
I want the enemy character to fight the player but not just repeatedly attack like crazy, just throw a few hits, maybe defend or retreat.
How would I make an enemy intelligent enough to do this ?
I want the enemy character to fight the player but not just repeatedly attack like crazy, just throw a few hits, maybe defend or retreat.
How would I make an enemy intelligent enough to do this ?