PDA

View Full Version : Python script for tracking Crusader maneuvers



kjones
2009-05-09, 01:57 PM
To expedite an upcoming encounter with a Crusader NPC, I hacked together a little Python script. I've uploaded it here:

Crusader script (http://www.contrib.andrew.cmu.edu/~jkeller/maneuvers.py)

Basically, it keeps track of three lists - withheld maneuvers, expended maneuvers, and active maneuvers, and juggles your readied maneuvers among them as specified in p. 9-10 of the ToB. (If I'm reading the rules correctly, that is.) If you use a maneuver, you enter the number of the maneuver, and you tell it when you've ended your turn, and get new maneuvers appropriately.

Known issues:

It's just a script, so you can only use it if you have Python installed. I'm not sure how to release it as an applet or something on a website - though I'm sure that's not hard.
Right now, the readied maneuvers are hard-coded in, since I'm only using it for this one encounter. It would be pretty easy to make it so that you input your readied maneuvers at the beginning of the encounter, though - or even read them out of a file somewhere.
I don't do any clever parsing of the input, so if you enter anything other than an integer, it will crash. If you're running this on a UNIX-like system, I suggest running it with rlwrap. I'm sure there's ways to do this correctly, but I don't have much experience with Python.


Other than that, it works just fine. If you play a crusader, or run a lot of crusaders as NPCs, you might find this helpful - I think it's easier than shuffling cards around. And it was a fun excuse for me to play with Python as well! So enjoy.

Arbitrarity
2009-05-09, 03:39 PM
For the "s = int(raw_input(""))", you should use a try loop to catch errors. That is:
while 1:

try:


s=int(raw_input("-->")

except:


pass
Bleah, this formatting saddens me :/ Lousy indent tags.

Readied manuevers can easily be read by using file-reading, like so:
f = file.open("maneuvers.txt", "r")
withheld = f.readlines()
f.close()

Finally, compiling to work as an .exe can be explained here. (http://www.ehow.com/how_2091641_compile-python-code.html)

Bryn
2009-05-09, 06:02 PM
For posting code, try
tags, to get something like this:

while 1:

try:

s=int(raw_input("-->")

except:

pass
(spoilered for fixed-width size)
:smallwink:

Arbitrarity
2009-05-09, 09:22 PM
Doesn't really help, Z. It seperates them, but it doesn't indent, and python NEEDS indentation.

subject42
2009-05-09, 09:34 PM
If you don't mind my asking, why do you wrap all of your collections in the enumerate function when you loop over them? You don't seem to be using the iterator variable anywhere.

Except for that little bit, it looks like you could easily compile it in Jython (http://www.jython.org/Project/) if you wanted t put it up on the web.

kjones
2009-05-09, 11:16 PM
Arbitrary: Yeah, crashing on invalid input is kind of silly. My professors would kill me if they knew (I'm a CS minor)... :smalltongue:

But that's an easy fix - I'll update it RSN.

Regarding file-reading - that part is easy enough, but that would mean you'd need to keep a text file with your readied maneuvers. Would it be better to have you enter them at the beginning of the combat? They make about an equal amount of sense...

subject42: If I understand your question correctly, I'm only using enumerate(list) to number the output when it's printed. It's not particularly necessary.

Thanks for the suggestion w.r.t. Jython - I know nothing whatsoever about developing for web applications, but making a Java applet is brain-dead simple. (Assuming my host lets me run them...)

Chronos
2009-05-09, 11:39 PM
If you want to be really thorough about it, you'd also include a list of maneuvers known to select the readied maneuvers from, and provide provision for Adaptive Style. And if you really want to be thorough, a list of all Crusader maneuvers, to make it easier to level-up or transfer to a different character, and a few editable blank maneuvers to allow for Martial Study or prestige classes.