Python not that wierd
Alex Martelli
alex at magenta.com
Wed Aug 2 12:43:19 EDT 2000
"Steve Lamb" <grey at despair.rpglink.com> wrote in message
news:slrn8ogeha.ig9.grey at teleute.rpglink.com...
> On Wed, 2 Aug 2000 10:12:47 +0200, Alex Martelli <alex at magenta.com> wrote:
> >And one of _my_ core values is 'do things once and once only'...:-).
>
> Right, which is why I switched it to search, not match, in the code.
Sorry, I don't understand. match is optimized for the purpose of
matching the whole-line, which seems to be exactly your purpose:
> >You do want to match the RE even when not at the beginning of the
> >string? Then the ^ is wrong. It's only useful when you want to match
> >a *start-of-line* in multiline mode (but you're not running your RE in
> >multiline mode, it seems to me?).
>
> No, that is exactly how I want it. xdy+z on a line by itself, start
of
> the line, no trailing spaces, nothing.
...so why not match, without the starting-^ ...?
> >OK, but the {1,2} (or, since it can be 0, should actually be {0,2}) can
> >only limit the *number of DIGITS* in the number-of-dice-to-roll. How
> >comes all limits fall at 99 or 999? Seems a strange coincidence to
> >me. but OK, whatever.
>
> Easiest way to limit it. 99d999+/-99 seemed reasonable to exceed most
> people's expectations. I've yet, in my years of gaming, to ever see the
need
> to roll more than 12 dice, anything higher than 100 sides, or a modifier
to
> ever exceed 3 times the sides on the die. So instead of picking some
> arbitrary number like, oh, 50, I just limited the number of places to
> something reasonable.
OK. Although a long-time RPG'er myself (anybody remembers the Aleax
monster in AD&D's monster-manual? no? oh well...), I've been out of touch
with the genre for years, after all. D1000 (three 20-sided dice read each
as a digit, of course, just an extension of D100) was used in some RQ
variants discussed in Alarums & Excursions (a great APAzine, but I don't
even know if it's still around), for example (impaling chance to be 1/5th of
base hit-chance, so if you're 24% to hit why get only a 4% chance to impale
when you can have a precise 4.8% by using a "1000-sided dice"...), but I
guess those refinements didn't make it into the mainstream (although, if I
were you, I'd pose the question on some general RPG discussion group;
the 1000-sided die is such a natural that I'm surprised it's utterly
unknown).
> You're right, though, I should have tried {0,2} first. I will try that
> when I next work on it. Right now I am tackling the problem of defining
the
> valid rulesets and how to go about actually running the correct ruleset
> without requiring ifs for each set. I want to have a directory with
rulesets
> in the keys and the class name in the variable then just have dice
assigned
> to the class. However, I'm not sure if I can do something like ${$foo}()
in
> Python. Haven't research yet.
Keep a reference to the class itself, rather than to its name, and your life
is simpler:
class Foo:
pass
class Bar:
pass
themap={'fee':Foo, 'fie':Bar, 'fo':Foo, 'fum':Bar}
theobjs=[]
for tag in ('fee','fie','foo','fum'):
theobjs.append(themap[tag]())
for obj in theobjs:
print obj
and you'll get:
<__main__.Foo instance at ff7ba0>
<__main__.Bar instance at ff5470>
<__main__.Foo instance at ff5780>
<__main__.Bar instance at ff5690>
Still, if you must keep the classname rather than a more direct reference
to the class itself, it's just an issue of using it later as a key to the
appropriate
dictionary -- namely, vars():
>>> Foo
<class __main__.Foo at ff52d0>
>>> vars()['Foo']
<class __main__.Foo at ff52d0>
>>>
> I latched onto the self.foo stuff quite early. Really enjoyed it once
I
> got the concept down.
Yep, it's fun, innit? The pervasive use of dictionaries ('hashes' to
Perlists:-), so you can generally supply your own dictionary in lieu
of vars(), or use vars() as a dictionary, etc, etc, is also lots of fun.
Each class-instance has its dict, so has the class as a whole, ...
> >Agreed. And a derived class could also tweak the re if a certain game
> >should need a slightly different syntax (if you use it as self.re).
>
> Yup, though if there is such an RPG out there I am not aware of it.
;)
Well, there ARE cases where you want to roll and sum two different
kind of dice, surely. Even in bad old D&D first edition, in certain cases
you had D8+D4, for example...
Alex
More information about the Python-list
mailing list