Can someone give me a hand with this? I am trying to make a pretty simple game, it takes place on a grid like a checker board. The object of the game is to get to the enemy side of the board before they get to yours. To do this you can place down up to 5 blocks to trap the enemy and destroy 1 block in case your trapped yourself. I have the player movement and block placement already done, but my problem is that i cant figure out how to make my enemy not, well, stupid. Currently i had it trying to move up towards my side and if it couldnt then it would move another way. The problem is though that it will move into a blocked in position and then move itself out, only to move itself back into that position immeadiately after.

Can someone give me an idea of how i would make the enemy move so it wont get itself stuck in an endless loop of getting blocked in, moving back, getting blocked in, moving back.