Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: First attempt at a Python prog (Chess)

Reply
Thread Tools

Re: First attempt at a Python prog (Chess)

 
 
Tim Golden
Guest
Posts: n/a
 
      02-15-2013
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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: First attempt at a Python prog (Chess) Oscar Benjamin Python 4 02-19-2013 09:10 PM
Re: First attempt at a Python prog (Chess) Rick Johnson Python 0 02-15-2013 05:05 AM
Re: First attempt at a Python prog (Chess) jkn Python 1 02-15-2013 03:09 AM
Re: First attempt at a Python prog (Chess) Ian Kelly Python 0 02-14-2013 06:30 PM
Re: First attempt at a Python prog (Chess) Oscar Benjamin Python 0 02-13-2013 11:55 PM



Advertisments