Instead of trying to use/make a crappy auto duel AI for PvP, you should reconsider and run the casual duels/ranked duels farming bot with either "Duel Skipper" (currently recommended since it causes quick losses) or the "Disconnect PvP Duels" option enabled (currently not recommended since it's much slower but it's also safer in regards to bans).
Losing (casual) PvP duels is totally fine since you still get rewards. You do not have to win. Using the bot as explained above is perfectly fine for farming. This may sound unreasonable to some people but after following my advice and seeing the results of it, you will start to understand also.