Battle algorithm and script