AutoPvP - automatically process your PvP fights

Donavin69

Member
AutoPvP 0.3.4
This script requires ZLib

This will automatically PvP for you, using all of your PvPs for the day.
It picks flowers and fights a random opponent, version 0.1 currently only supports Moxie (Backstab)...

Sets 2 ZLib vars for the Win message and Lose message, (AutoPvP_WinMsg and AutoPvP_LoseMsg)
Sets Zlib var for configurable Fight 'method', defaults to your PrimeStat
1 = Muscle
2 = Mysticality
3 = Moxie
4 = Ballyhoo

Version history:
0.1 initial release, limited to flower picking with Moxie
0.2 add ZLib configurable variable for fighting method
0.2.5 fix a typo that made the method fail
0.3 Add parsing for who you fight, and win/lose
0.3.1 Add a swagger result at the end of the fighting
0.3.2 Add a counter for totals for the day
0.3.3 Add mood processing between fights (mood execute)
0.3.4 Add 'AutoPvP_Ranked' zlib var, set to 1 by default, change to 2 for 'tougher'
 

Attachments

  • AutoPvP.ash
    3.1 KB · Views: 671
Last edited:

Bale

Minion
I use a modified version of RoyalTonberry's PvP script. It uses this bit of code to parse the fight results. You might want to adopt it. Or not. Your call.

PHP:
string fight_string = visit_url("peevpee.php?action=fight&place=fight&pwd&ranked=1&who=&stance="+FightStat+"&attacktype=flowers&winmessage="+WinMsg+"&losemessage="+LoseMsg);

matcher names = create_matcher("<a href=\"showplayer\\.php\\?who=\\d+\"><b>([^<]+)</b></a> calls out <a href=\"showplayer\\.php\\?who=\\d+\"><b>([^<]+)</b></a> for battle!", fight_string);
string names_string = "";
if(names.find()) {
	names_string = names.group(1) + " calls out " + names.group(2) + " for battle!";
} else {
	print("no call-out found");
}

matcher m = create_matcher("<b>([^<]+)</b> won the fight, <b>(\\d+)</b> to <b>(\\d+)</b>!", fight_string);
if(m.find()) {
	string victoryString = m.group(1) + " won the fight, " + m.group(2) + " to " + m.group(3);
	print(names_string + " ... " + victoryString);
} else {
	print("No result could be found");
}

Of course it would be nicer if those two regexps were combined into a single regexp, but I didn't feel like putting in the trouble since regexp don't like me as much as I like them.
 

Catch-22

Active member
Of course it would be nicer if those two regexps were combined into a single regexp, but I didn't feel like putting in the trouble since regexp don't like me as much as I like them.

Jeff Atwood said:
Do not try to do everything in one uber-regex. I know you can do it that way, but you're not going to. It's not worth it. Break the operation down into several smaller, more understandable regular expressions, and apply each in turn. Nobody will be able to understand or debug that monster 20-line regex, but they might just have a fighting chance at understanding and debugging five mini regexes.

The rest of the article can be found here, I recommend anyone who uses regular expressions to have a read :)
 
When I was teaching myself python, I would sit in #python on irc. Programmers get a kick out of one-liners. And it's amazing what can be accomplished in one line of code. I don't personally think it's good practice because my brain always asplodes when I see them. But, again, I admit to not being a programmer. ;)
 

Winterbay

Active member
If you want to look at complicated ash-lines open up basically any of zarqon's scripts. For a while I went through batbrain and demystified it so that I would understand what it did, but I gave up because it takes so darn long...
 

Bale

Minion
zarqon is a student of the school of coding that says it is pointless for a statement to do only one thing if you can make it do ten. It's hard to read, but it finds elegance in complexity.



Well, for what it is worth, I'm posting my PvP script here now. Note that it color codes fight results based on victory or defeat. That makes it easier to follow. Unlike Donavin69's script it can only be customized by editing the script, but I made it very easy to do. I also made it easy to modify it so that it can be customized with zlib variables, if that's your thing. I just don't find it necessary to customize since there is a basic simple configurations that I won't want to change.


Code:
int MUSCLE_STANCE = 1;
int MYST_STANCE = 2;
int MOXIE_STANCE = 3;
int BALLYHOO_STANCE = 4;

int RANDOM_PERSON = 1;
int HARDER_PERSON = 2;

string HIT_FOR_FLOWERS = "flowers";
string HIT_FOR_FAME = "fame";
string HIT_FOR_LOOT = "lootwhatever";

void autoPvP(int fights) {
	int stance = BALLYHOO_STANCE;
	int ranked = RANDOM_PERSON;
	string attacktype = HIT_FOR_FLOWERS;
	
	string winMessage = "Have a Cheerio";
	string loseMessage = "OUch! I suck.";

	if(fights < 1) fights = 1;
	string color = "red";
	for f from 1 to fights {
		print("Fight #"+f+ "......");
		string fight_res = visit_url("peevpee.php?action=fight&place=fight"
				  + "&attacktype=" + attacktype 
				  + "&ranked=" + ranked 
				  + "&stance=" + stance 
				  + "&who="
				  + "&losemessage=" + loseMessage
				  + "&winmessage=" + winMessage);
				  
		matcher names = create_matcher("<a href=\"showplayer\\.php\\?who=\\d+\"><b>([^<]+)</b></a> calls out <a href=\"showplayer\\.php\\?who=\\d+\"><b>([^<]+)</b></a> for battle!", fight_res);
		string result = "";
		if(names.find())
			result = names.group(1) + " calls out " + names.group(2) + " for battle!";
		else print("no call-out found");
	
		matcher m = create_matcher("<b>([^<]+)</b> won the fight, <b>(\\d+)</b> to <b>(\\d+)</b>!", fight_res);
		if(m.find()) {
			result = result + " ... " + m.group(1) + " won the fight, " + m.group(2) + " to " + m.group(3);
			if(m.group(1) == my_name())
				color = "green";
			else color = "red";
		} else print("No result could be found");
		
		print(result, color);
	}
}

int count_fights() {
	string PeeVPee=visit_url("peevpee.php?place=fight");
	if(PeeVPee.contains_text("You must break your")) {
		print("You haven't chosen to PvP, I can't help you!", "blue");
	} else if(PeeVPee.contains_text("You're out of fights")) {
		print("You are out of fights, wait for rollover!", "red");
	} else {
		matcher PvPs = create_matcher("You have ([0-9,]+) fights remaining today", PeeVPee);
		if(find(PvPs)) {
			print("You have "+ PvPs.group(1) +" fights remaining today", "blue");
			return PvPs.group(1).to_int();
		}
	}
	return 0;
}

void autoPvP() {
	int fights = count_fights();
	if(fights > 0)
		autoPvP(fights);
}

void main(){
	autoPvP();
}
 

Catch-22

Active member
zarqon is a student of the school of coding that says it is pointless for a statement to do only one thing if you can make it do ten. It's hard to read, but it finds elegance in complexity.
Some excerpts from The Art of Unix Programming:
Eric S. Raymond said:
Rule of Clarity: Clarity is better than cleverness.
Rule of Simplicity: Design for simplicity; add complexity only where you must.
Rule of Transparency: Design for visibility to make inspection and debugging easier.

Of course, we can't all be Eric S. Raymond.

There's also an interesting article here written about PHP code, which I think can equally apply to ASH scripts.

Anyway, I'm nitpicking really, but if you ever work in an environment where you have to look at code written by somebody else, you're going to love the programmer who is clear, concise and well-documented.

TBH, I've seen some well documented work from Zarqon (zLib) and some poorly commented work (SmartStasis), and I think it just comes down to laziness really, but that's also a compliment :)
 

Bale

Minion
I was aware of that actually. Whereas you have iron in your blood, I have irony. I don't like to let a sentence mean only one thing when I can mean ten.
 

shabob

New member
Of course, we can't all be Eric S. Raymond.

For which state of affairs I am entirely grateful. One ignorant, sexist, arrogant prig is enough for this world.

That's not to detract from the skill displayed in some of his earlier coding, and his insights in Cathedral and the Bazaar were revolutionary. These days, however, if one can quote from RationalWiki:

His work and expertise in computer technology has been all but overshadowed by his batshit insane wingnut tendencies in the wake of 9/11, as well as his increasingly wanky ego-gazing as he acknowledges that people aren't so crazy about him anymore.
 

fronobulax

Developer
Staff member
For which state of affairs I am entirely grateful. One ignorant, sexist, arrogant prig is enough for this world.

That's not to detract from the skill displayed in some of his earlier coding, and his insights in Cathedral and the Bazaar were revolutionary. These days, however, if one can quote from RationalWiki:

Since sometimes the message gets lost when the messenger is shot, similar points are made by many people. In searching for a citation I got distracted by Knuth's comments on art and elegance. One quote does seem to explain some of the scripting philosophies.

One rather curious thing I've noticed about aesthetic satisfaction is that our pleasure is significantly enhanced when we accomplish something with limited tools.
 

Donavin69

Member
Using Bales suggestion, I finally got interested in who I fought and won/lost against...

I still receive a message saying 'You lost the PvP fight!' after EVERY fight, even when I obviously win the fight, a bit of an error in the message, and I can't determine where it comes from (running a debug log doesn't show the message at all)

I have updated the code to Version 0.3 and uploaded the new version...Enjoy!
 

lostcalpolydude

Developer
Staff member
That message is from mafia. The only guess I have is that your name capitalization has changed since the first time you logged in with mafia (just see if the capitalization at the top of any mafia window matches your current capitalization). It also isn't reporting stat losses when you lose a fight, correct?
 

Theraze

Active member
Just use to_lower_case() to make sure that capitalization doesn't matter on the name, since KoL itself doesn't allow for alternate names with (only) differing capitalizations...
 

Donavin69

Member
I was getting this message before I parsed anything for the name.

What should I convert case on?
 
Last edited:

Theraze

Active member
Easiest thing to convert would probably be fight_string, before you create the matchers. Doesn't look like you're actually having any of the matches go against proper case, but... might take a bit of testing. Believe that should work though. :)
 

Donavin69

Member
I tried converting the fight_string to_lower_case, but have the same 'annoying' message, again, I do actually win the fight, and it parses out that I win the fight...so it is just a message...

I did confirm that my name WAS different than what my mafia window shows....I change my capitalization to match the top of Mafia, and it now tells me I lost stats when I do, and it tells me I won when I do...
 

Veracity

Developer
Staff member
Revision 11011 changes KoLmafia's parsing of the results to extract the name of the winner and compare it to your own name, ignoring case. It also extracts the number of contests won vs. lost and includes that info in the logged message.

Untested, since I am out of fites for today.
 
Top