Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!selfless.tophat.at!newsfeed.xs4all.nl!newsfeed5.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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'attributes': 0.05; 'instance': 0.05; 'instance,': 0.05; 'int': 0.05; 'character,': 0.07; 'defaults': 0.07; 'json': 0.07; 'terry': 0.07; 'attribute': 0.09; 'back-end': 0.09; 'closed,': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:80.91.229.12': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'received:lo.gmane.org': 0.09; 'subclasses': 0.09; 'pm,': 0.10; 'syntax': 0.11; '>>>': 0.12; 'am,': 0.14; 'wrote:': 0.14; '(ie,': 0.16; 'approach,': 0.16; 'benjamin': 0.16; 'file).': 0.16; 'reedy': 0.16; 'possibly': 0.16; '(i.e.': 0.17; 'classes,': 0.19; 'generic': 0.19; 'once,': 0.19; 'guess': 0.19; 'jan': 0.20; '(which': 0.20; 'header:In-Reply-To:1': 0.21; "aren't": 0.22; 'file,': 0.22; 'stuff': 0.22; 'code': 0.24; 'handles': 0.26; 'xml': 0.26; 'classes': 0.26; 'tried': 0.27; 'example': 0.27; "i'm": 0.27; '---': 0.28; 'character': 0.29; 'subject:?': 0.29; 'class.': 0.29; "python's": 0.29; 'class': 0.29; 'code,': 0.29; 'config': 0.30; 'sun,': 0.30; 'developers': 0.30; 'define': 0.31; 'player': 0.31; "skip:' 10": 0.32; 'header:X-Complaints-To:1': 0.32; 'file.': 0.32; 'to:addr:python-list': 0.33; 'list': 0.33; 'actually': 0.33; '(for': 0.33; "i've": 0.33; 'rather': 0.34; '...': 0.34; 'chris': 0.34; 'file': 0.34; 'there': 0.35; 'header :User-Agent:1': 0.35; 'driven': 0.35; 'subject:What': 0.35; 'store': 0.35; 'using': 0.35; 'determine': 0.36; 'open': 0.36; 'probably': 0.36; 'uses': 0.36; 'difference': 0.37; 'similar': 0.37; 'something': 0.37; 'change': 0.37; 'pretty': 0.37; 'received:org': 0.38; 'but': 0.38; 'data': 0.38; 'subject:: ': 0.38; 'doing': 0.39; 'should': 0.39; 'header:Mime-Version:1': 0.39; 'add': 0.39; 'to:addr:python.org': 0.39; 'basic': 0.40; 'read,': 0.40; 'really': 0.40; 'custom': 0.60; 'more': 0.60; 'your': 0.60; 'order': 0.62; 'john': 0.62; 'opened': 0.63; 'unique': 0.63; 'here': 0.66; 'making': 0.67; '100': 0.73; 'subject:this': 0.76; 'data-driven': 0.84; 'ini': 0.84; 'read/write': 0.84; 'subject:class': 0.84; 'subject:write': 0.84; 'subject:best': 0.93 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Terry Reedy Subject: Re: What's the best way to write this base class? Date: Mon, 20 Jun 2011 13:58:57 -0400 References: <142e76c3-b304-43ef-af24-919fa6146369@c9g2000yqp.googlegroups.com> <5c8be025-2d2c-42fc-a764-bd1ca03ba398@d14g2000yqb.googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: rain.gmane.org User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.17) Gecko/20110414 Lightning/1.0b2 Thunderbird/3.1.10 In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 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: 61 NNTP-Posting-Host: 82.94.164.166 X-Trace: 1308592755 news.xs4all.nl 49046 [::ffff:82.94.164.166]:38690 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:8022 On 6/20/2011 3:12 AM, Benjamin Kaplan wrote: > On Sun, Jun 19, 2011 at 9:04 PM, John Salerno wrote: >> On Jun 19, 8:52 pm, Chris Kaynor wrote: >> >>> Having a character class (along with possibly player character, non-player character, etc), make sense; however you probably want to make stuff like health, resources, damage, and any other attributes not be handles by any classes or inheritance in order to allow you to make such data-driven (ie, read from a file). Doing so makes the game much more extendable: using classes, you are likely limited to 5 or 'combinations and a few developers (plus, any designers need to know programming). >>> >>> A basic way to determine between using subclasses over a data driven approach is: is there significantly different back-end behavior or merely attribute differences. >> >> Can you give a basic example of how this data-driven approach would >> work? You don't have to provide any code, just a description would be >> helpful. Such as, do I create a data file per character, and then have >> each character instance read/write to that file? Is it good to have so >> many files open at once, or would they only need to be read, closed, >> then opened again at the end to write? >> -- > > I'm pretty sure he means that if the only difference between classes > is configuration (i.e. you aren't actually going to change code > between character classes, just base stats, growth rates, and a list > of available skills or something of that nature), then you should > store the configurations in a config file rather than making a new > class. So rather than having > class WizardCharacter(Character) : > base_health = 50 > ... > class WarriorCharacter(Character) : > base_health=70 > ... > You make a config file > > --- characterclasses.ini --- > [Wizard] > base_health=50 int = 70 > [Warrior] > base_health=70 int = 30 [Gandolf] base_health = 60 int = 100 My point here being that with a data approach, non-programmers can also define named, unique NPCs with custom stats as well as generic classes > Then, when you make a new character, rather than doing a > WizardCharacter() or a WarriorCharacter(), you do a > Character(job='Wizard') and then look up the various defaults in your > config file. Doing it this way makes it trivial to add a new class. If > you want to use an old-fashioned INI file, you can use the > ConfigParser class to read them. If you want to nest attributes (for > instance, a list of sub-items), you'll probably want to go with XML > and ElementTree. I guess you can also use JSON (which uses a syntax > similar to Python's dictionaries) but I've never really tried to make > one of those by hand before so I'm not sure how well it will work out. -- Terry Jan Reedy