fix several bugs and implement a basic IA for player.