Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'subject:Python': 0.05; 'extent': 0.07; 'nested': 0.07; 'python': 0.09; '(actually': 0.09; '(instead': 0.09; 'dict': 0.09; 'dojo': 0.09; 'iterate': 0.09; 'keyed': 0.09; 'list).': 0.09; 'occasionally': 0.09; 'cc:addr :python-list': 0.10; 'slightly': 0.15; '(also': 0.16; '2):': 0.16; 'benjamin': 0.16; 'cc:name:python list': 0.16; 'computes': 0.16; 'coordinates': 0.16; 'dojo,': 0.16; 'innermost': 0.16; 'move).': 0.16; 'multiplied': 0.16; 'row': 0.16; 'wrote:': 0.17; 'board.': 0.17; 'implementing': 0.17; 'pieces': 0.17; 'string,': 0.17; 'tim': 0.18; 'ideal': 0.20; 'sort': 0.21; 'earlier': 0.21; 'tuples': 0.22; 'cc:2**0': 0.23; 'ourselves': 0.23; 'allows': 0.25; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; '(which': 0.26; 'question': 0.27; 'replace': 0.27; 'message- id:@mail.gmail.com': 0.27; 'went': 0.28; 'represent': 0.28; 'asks': 0.29; 'block,': 0.29; 'piece': 0.29; "i'm": 0.29; 'function': 0.30; 'lists': 0.31; 'structure': 0.32; 'suggestion': 0.32; 'could': 0.32; 'received:google.com': 0.34; 'list': 0.35; 'lists.': 0.35; 'doing': 0.35; 'board': 0.35; 'received:209.85.220': 0.35; 'received:209.85': 0.35; 'something': 0.35; 'but': 0.36; '(i.e.': 0.36; 'others.': 0.36; "didn't": 0.36; 'subject: (': 0.36; 'why': 0.37; 'rather': 0.37; 'received:209': 0.37; 'data': 0.37; 'subject:: ': 0.38; 'things': 0.38; 'list,': 0.39; 'first': 0.61; 'back': 0.62; 'more': 0.63; 'here': 0.65; 'subject:First': 0.65; 'monthly': 0.66; 'life': 0.66; 'score': 0.75; '2013': 0.84; 'abandon': 0.84; 'board:': 0.84; 'conclusions': 0.84; 'mechanics': 0.84; 'oscar': 0.84; '"how': 0.91; 'do:': 0.91; 'to:addr:mail': 0.91; 'favour': 0.93 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:mime-version:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; bh=UgHD1g89pI5sda/S+nuP9cuqZbCzBcRomv3cAHNR/NY=; b=p9xJVXcdRpJqVp/0eFTsIWULgg9m/tHbn84cq3AFReS0OXu44oof3nu3nmG63BrkEU fWiZqlKq1KpcfxO+QMHPx89u3ti3p+Dm8WOS2R+JIW+AyZZ1D3TaycmyoLPolW1HjswQ qN3RafKWv1Ej8WkIFQ9MKnrEtJFU1ZljuJf2xIalOXKSLu+nrIxGp4cMFfcirz4lgJwB K1qWwTIIW2Wqd2MHIqAHix/w3WLVVpceJ4BVvCF9YgHPBcuhOqbJeDxO8FqXoQon3d2v vLUNHb7b4dPgk1DA7JJuO0EjUstLVWj1mlfXpmy7V2ZU4qvU5261IRq+x2vQU3nrS5MN o+qw== X-Received: by 10.52.89.83 with SMTP id bm19mr2526455vdb.123.1360933930785; Fri, 15 Feb 2013 05:12:10 -0800 (PST) MIME-Version: 1.0 In-Reply-To: <511E1DCB.40406@timgolden.me.uk> References: <2013021323250974803-chrishinsley@gmailcom> <511E1DCB.40406@timgolden.me.uk> From: Oscar Benjamin Date: Fri, 15 Feb 2013 13:11:50 +0000 Subject: Re: First attempt at a Python prog (Chess) To: Tim Golden Content-Type: text/plain; charset=ISO-8859-1 Cc: Python List 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: 51 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1360933939 news.xs4all.nl 6887 [2001:888:2000:d::a6]:50527 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:38918 On 15 February 2013 11:36, Tim Golden wrote: > On 15/02/2013 11:22, Oscar Benjamin wrote: >> Why not make board a list of lists. Then you can do: >> >> for row in board: >> for piece in row: >> >> rather than using range(). >> >> Or perhaps you could have a dict that maps position tuples to pieces, >> e.g.: {(1, 2): 'k', ...} > > I'm laughing slightly here because, at the monthly London Python > Dojo, we often find ourselves implementing board-game mechanics > of one sort or another: Boggle, Battleships, Sliding block, > Connect 4, Noughts-and-Crosses, even things like Game of Life > (which has a board of sorts). > > And the "how shall we represent the board?" question is pretty > much the first thing any team asks themselves. And you always > get someone in favour of lists of lists, someone for one long > list, I always get confused when doing this about which of my coordinates needs to be multiplied (i.e. whether I am in Fortran or C order). > someone who likes a string, someone (me) who likes a sparse > dict keyed on coords, Clearly better than the others. > someone else likes nested defaultdicts, > and occasionally more outlandish schemes. > > We even went to the extent of having a Dojo a few months back > which was solely about implementing the ideal board for varying > characteristics, but we didn't come to any conclusions :) In this case the innermost loop of the program is over the pieces on the board. Clearly you want a data structure that allows you to iterate directly over them. (Actually since that loop is to calculate the score I would replace it with a function that computes the change in score as a result of each move). > (Also I seem to remember that the OP was advised earlier precisely > to abandon lists of lists in favour of something else). Actually the suggestion was for the list of lists (instead of a flat list). Oscar