Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder4.news.weretis.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.011 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'subject:Python': 0.06; 'lookup': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'python': 0.11; 'random': 0.14; '70,': 0.16; 'blocks': 0.16; 'kern': 0.16; 'normally,': 0.16; 'reasonably': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject:user': 0.16; 'tuple': 0.16; 'underlying': 0.16; 'url:title': 0.16; 'weapon': 0.16; 'write,': 0.16; 'wrote:': 0.18; 'bit': 0.19; 'starts': 0.20; 'creating': 0.23; 'header:User-Agent:1': 0.23; 'certainly': 0.24; 'entries': 0.24; 'interpret': 0.24; 'replace': 0.24; 'string,': 0.24; "i've": 0.25; 'nearly': 0.26; 'tables': 0.26; 'header:X -Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'chris': 0.29; '[1]': 0.29; 'array': 0.29; '[2]': 0.30; 'robert': 0.30; '(which': 0.31; 'code': 0.31; 'second,': 0.31; 'table': 0.34; 'maybe': 0.34; 'could': 0.34; 'beyond': 0.35; 'but': 0.35; 'there': 0.35; 'data,': 0.36; 'done': 0.36; 'subject:New': 0.37; 'so,': 0.37; 'easily': 0.37; 'implement': 0.38; 'generic': 0.38; 'handle': 0.38; 'to:addr:python-list': 0.38; 'list,': 0.38; 'ability': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'subject: / ': 0.60; 'first': 0.61; "you'll": 0.62; 'url:index': 0.63; 'such': 0.63; 'our': 0.64; 'world': 0.66; 'believe': 0.68; 'special': 0.74; 'million': 0.74; 'eco': 0.84; 'heh.': 0.84; "it'd": 0.84; 'terrible': 0.84; 'url:php': 0.85; 'received:86': 0.91; 'technique': 0.93 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Robert Kern Subject: Re: New user's initial thoughts / criticisms of Python Date: Mon, 11 Nov 2013 11:53:40 +0000 References: <-JadnUirYuhUruPPnZ2dnUVZ8rSdnZ2d@bt.com> <1c4c0901-f80a-42f3-9df5-7e7431353079@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: cpc2-cmbg17-2-0-cust347.5-4.cable.virginm.net User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:24.0) Gecko/20100101 Thunderbird/24.1.0 In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 45 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1384170873 news.xs4all.nl 15936 [2001:888:2000:d::a6]:60703 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:59068 On 2013-11-11 10:39, Chris Angelico wrote: > A 'minor weapon' is based on a roll of a 100-sided dice. If it's 01 to > 70, "+1 weapon: 2,000gp [weapon]"; if it's 71 to 85, "+2 weapon: > 8,000gp [weapon]"; if 86 to 90, "Specific weapon [minor specific > weapon]"; and if 91 to 100, "Special ability [minor special weapon] > and roll again". > > My code to handle that starts out with this array: > > "minor weapon":({ > 70,"+1 weapon: 2,000gp [weapon]", > 85,"+2 weapon: 8,000gp [weapon]", > 90,"Specific weapon [minor specific weapon]", > 100,"Special ability [minor special weapon] and roll again", > }), > > (that's Pike; in Python it'd be a list, or maybe a tuple of tuples), > and denormalizes it into a lookup table by creating 70 entries quoting > the first string, 15 quoting the second, 5, and 10, respectively. So, > with a bit of preprocessing, a lookup table (which in this case is an > array (list), but could just as easily be a dict) can be used to > handle inequalities. But this is because lookup tables can be treated > as data, where if/elif/else blocks have to be code; there are roughly > 42 million such lookup tables in the code I snagged that from, and > having code for each one would work out far less manageable. Normally, > you'll want to render inequalities with code as if/elif. Heh. I've done pretty much exactly the same thing to implement an engine[1] to draw from the random tables on Abulafia[2] which have nearly the same structure. It scales up reasonably well beyond d100s. It's certainly not a technique I would pull out to replace one-off if-elif chains that you literally write, but it works well when you write the generic code once to apply to many tables. [1] http://rollmeup.mechanicalkern.com/ [2] http://www.random-generator.com/index.php?title=Main_Page -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco