AI attack algoritm. Some bugfix and refactoring