Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #38915

Re: First attempt at a Python prog (Chess)

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <mail@timgolden.me.uk>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.005
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'subject:Python': 0.05; 'extent': 0.07; 'nested': 0.07; 'python': 0.09; 'dict': 0.09; 'dojo': 0.09; 'keyed': 0.09; 'occasionally': 0.09; 'slightly': 0.15; '(also': 0.16; '2):': 0.16; 'benjamin': 0.16; 'dojo,': 0.16; 'from:addr:timgolden.me.uk': 0.16; 'from:name:tim golden': 0.16; 'message-id:@timgolden.me.uk': 0.16; 'received:74.55.86': 0.16; 'received:74.55.86.74': 0.16; 'received:smtp.webfaction.com': 0.16; 'received:webfaction.com': 0.16; 'row': 0.16; 'tjg': 0.16; 'wrote:': 0.17; 'implementing': 0.17; 'string,': 0.17; 'ideal': 0.20; 'sort': 0.21; 'earlier': 0.21; 'tuples': 0.22; 'ourselves': 0.23; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; '(which': 0.26; 'question': 0.27; 'went': 0.28; 'represent': 0.28; 'asks': 0.29; 'block,': 0.29; 'piece': 0.29; "i'm": 0.29; 'lists': 0.31; 'could': 0.32; 'received:192.168.100': 0.33; 'to:addr :python-list': 0.33; 'list': 0.35; 'lists.': 0.35; 'board': 0.35; 'something': 0.35; 'but': 0.36; "didn't": 0.36; 'subject: (': 0.36; 'why': 0.37; 'rather': 0.37; 'subject:: ': 0.38; 'things': 0.38; 'to:addr:python.org': 0.39; 'received:192': 0.39; 'list,': 0.39; 'received:192.168': 0.40; 'first': 0.61; 'back': 0.62; 'more': 0.63; 'here': 0.65; 'subject:First': 0.65; 'monthly': 0.66; 'life': 0.66; 'from:addr:mail': 0.71; 'abandon': 0.84; 'board:': 0.84; 'conclusions': 0.84; 'mechanics': 0.84; 'oscar': 0.84; '"how': 0.91; 'do:': 0.91; 'favour': 0.93
Date Fri, 15 Feb 2013 11:36:43 +0000
From Tim Golden <mail@timgolden.me.uk>
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20130107 Thunderbird/17.0.2
MIME-Version 1.0
To python-list@python.org
Subject Re: First attempt at a Python prog (Chess)
References <2013021323250974803-chrishinsley@gmailcom> <CAHVvXxQT8_VxK2D_z+L8pdaxzvmX_WS=5wvfwkRKtczESvZ9uQ@mail.gmail.com>
In-Reply-To <CAHVvXxQT8_VxK2D_z+L8pdaxzvmX_WS=5wvfwkRKtczESvZ9uQ@mail.gmail.com>
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding 7bit
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.1803.1360928209.2939.python-list@python.org> (permalink)
Lines 34
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1360928209 news.xs4all.nl 6850 [2001:888:2000:d::a6]:36042
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:38915

Show key headers only | View raw


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, someone who likes a string, someone (me) who likes a sparse
dict keyed on coords, 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 :)

(Also I seem to remember that the OP was advised earlier precisely
to abandon lists of lists in favour of something else).

TJG

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

First attempt at a Python prog (Chess) Chris Hinsley <chris.hinsley@gmail.com> - 2013-02-13 23:25 +0000
  Re: First attempt at a Python prog (Chess) Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2013-02-13 23:55 +0000
    Re: First attempt at a Python prog (Chess) Chris Hinsley <chris.hinsley@gmail.com> - 2013-02-14 01:31 +0000
  Re: First attempt at a Python prog (Chess) Tim Roberts <timr@probo.com> - 2013-02-13 22:05 -0800
    Re: First attempt at a Python prog (Chess) Chris Hinsley <chris.hinsley@gmail.com> - 2013-02-14 17:48 +0000
      Re: First attempt at a Python prog (Chess) Ian Kelly <ian.g.kelly@gmail.com> - 2013-02-14 11:30 -0700
      Re: First attempt at a Python prog (Chess) Tim Roberts <timr@probo.com> - 2013-02-18 20:15 -0800
        Re: First attempt at a Python prog (Chess) Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-02-19 06:24 +0000
        Re: First attempt at a Python prog (Chess) Ian Kelly <ian.g.kelly@gmail.com> - 2013-02-19 12:41 -0700
  Re: First attempt at a Python prog (Chess) jkn <jkn_gg@nicorp.f9.co.uk> - 2013-02-14 13:14 -0800
    Re: First attempt at a Python prog (Chess) Chris Hinsley <chris.hinsley@gmail.com> - 2013-02-14 22:13 +0000
      Re: First attempt at a Python prog (Chess) Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-02-14 22:09 -0500
  Re: First attempt at a Python prog (Chess) Rick Johnson <rantingrickjohnson@gmail.com> - 2013-02-14 21:05 -0800
  Re: First attempt at a Python prog (Chess) Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2013-02-15 11:22 +0000
    Re: First attempt at a Python prog (Chess) Neil Cerutti <neilc@norwich.edu> - 2013-02-15 16:17 +0000
      Re: First attempt at a Python prog (Chess) MRAB <python@mrabarnett.plus.com> - 2013-02-15 17:52 +0000
        Re: First attempt at a Python prog (Chess) Neil Cerutti <neilc@norwich.edu> - 2013-02-19 21:10 +0000
      Re: First attempt at a Python prog (Chess) Matt Jones <matt.walker.jones@gmail.com> - 2013-02-15 12:03 -0600
  Re: First attempt at a Python prog (Chess) Tim Golden <mail@timgolden.me.uk> - 2013-02-15 11:36 +0000
  Re: First attempt at a Python prog (Chess) Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2013-02-15 13:11 +0000
  Re: First attempt at a Python prog (Chess) Tim Golden <mail@timgolden.me.uk> - 2013-02-15 15:36 +0000
    Re: First attempt at a Python prog (Chess) Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2013-02-15 18:48 +0200
  Re: First attempt at a Python prog (Chess) Chris Angelico <rosuav@gmail.com> - 2013-02-16 02:49 +1100
  Re: First attempt at a Python prog (Chess) Tim Golden <mail@timgolden.me.uk> - 2013-02-15 17:37 +0000
  Re: First attempt at a Python prog (Chess) Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-02-15 13:41 -0500
  Re: First attempt at a Python prog (Chess) Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2013-02-16 14:39 +0000

csiph-web