Added comments to make sure I understand it. Attempted to make it so the best unit attacks first.