Re: First attempt at a Python prog (Chess)

2014-04-30 Thread Robert Kern
On 2014-04-30 16:15, Mark H Harris wrote: On 4/30/14 8:28 AM, Chris Hinsley wrote: On 2013-02-15 05:05:27 +, Rick Johnson said: First of all your naming conventions suck. You've used the "interface" style for every function in this game so i can't /easily/ eyeball parse the /real/ interfac

Re: First attempt at a Python prog (Chess)

2014-04-30 Thread Mark H Harris
On 4/30/14 8:28 AM, Chris Hinsley wrote: On 2013-02-15 05:05:27 +, Rick Johnson said: First of all your naming conventions suck. You've used the "interface" style for every function in this game so i can't /easily/ eyeball parse the /real/ interface functions from the helper functions -- an

Re: First attempt at a Python prog (Chess)

2014-04-30 Thread Chris Hinsley
perplexed me: "First attempt at a Python prog (Chess)"Okay, but how does that translate to: "The fastest, most efficient, most brain fricked python code ever released in the form of a game, that just happens to look an awful lot like C source"? http://en.wikipedia.or

Re: First attempt at a Python prog (Chess)

2013-07-04 Thread Joshua Landau
Just a minor suggestion: def display_board(board): print ' a b c d e f g h' print '+---+---+---+---+---+---+---+---+' for row in range(8): for col in range(8): piece = board[row * 8 + col] if piece_type[piece] == WHITE: print '| \x1b[31;0

Re: First attempt at a Python prog (Chess)

2013-07-04 Thread Chris Hinsley
On 2013-02-13 23:25:09 +, Chris Hinsley said: New to Python, which I really like BTW. First serious prog. Hope you like it. I know it needs a 'can't move if your King would be put into check' test. But the weighted value of the King piece does a surprising emergent job. New version with

Re: First attempt at a Python prog (Chess)

2013-02-19 Thread Neil Cerutti
On 2013-02-15, MRAB wrote: > On 2013-02-15 16:17, Neil Cerutti wrote: >> On 2013-02-15, Oscar Benjamin wrote: >>> if score > best_score or best_score is None: >> >> You need the None check first to avoid an exception from the >> comparison. > > Only in Python 3. It is a more difficult to find bu

Re: First attempt at a Python prog (Chess)

2013-02-19 Thread Ian Kelly
On Mon, Feb 18, 2013 at 9:15 PM, Tim Roberts wrote: > Chris Hinsley wrote: >> >>Is a Python list as fast as a bytearray ? > > Python does not actually have a native array type. Everything in your > program that looked like an array was actually a list. How do you mean? >>> isinstance(bytearray

Re: First attempt at a Python prog (Chess)

2013-02-18 Thread Steven D'Aprano
On Mon, 18 Feb 2013 20:15:28 -0800, Tim Roberts wrote: > Chris Hinsley wrote: >> >>Is a Python list as fast as a bytearray ? > > Python does not actually have a native array type. Everything in your > program that looked like an array was actually a list. Actually it does, but you have to impo

Re: First attempt at a Python prog (Chess)

2013-02-18 Thread Tim Roberts
Chris Hinsley wrote: > >Is a Python list as fast as a bytearray ? Python does not actually have a native array type. Everything in your program that looked like an array was actually a list. -- Tim Roberts, t...@probo.com Providenza & Boekelheide, Inc. -- http://mail.python.org/mailman/listinf

Re: First attempt at a Python prog (Chess)

2013-02-16 Thread Oscar Benjamin
On 15 February 2013 15:49, Chris Angelico wrote: > On Sat, Feb 16, 2013 at 2:36 AM, Tim Golden wrote: >> How true. This last time, my team split into two: one half >> to handle the display, the other working on the algorithm. We >> ended up having to draw a really simple diagram on the back of >>

Re: First attempt at a Python prog (Chess)

2013-02-15 Thread Matt Jones
"Only in Python 3." Use best practices always, not just when you have to. *Matt Jones* On Fri, Feb 15, 2013 at 11:52 AM, MRAB wrote: > On 2013-02-15 16:17, Neil Cerutti wrote: > >> On 2013-02-15, Oscar Benjamin wrote: >> >>> if score > best_score or best_score is None: >>> >> >> You need the

Re: First attempt at a Python prog (Chess)

2013-02-15 Thread MRAB
On 2013-02-15 16:17, Neil Cerutti wrote: On 2013-02-15, Oscar Benjamin wrote: if score > best_score or best_score is None: You need the None check first to avoid an exception from the comparison. Only in Python 3. if best_score is None or score > best_score: -- http://mail.python.org/m

Re: First attempt at a Python prog (Chess)

2013-02-15 Thread Tim Golden
On Sat, Feb 16, 2013 at 2:36 AM, Tim Golden wrote: How true. This last time, my team split into two: one half to handle the display, the other working on the algorithm. We ended up having to draw a really simple diagram on the back of an envelope with the x,y pairs written out and pass it back a

Re: First attempt at a Python prog (Chess)

2013-02-15 Thread Jussi Piitulainen
Tim Golden writes: > On 15/02/2013 13:11, Oscar Benjamin wrote: > > On 15 February 2013 11:36, Tim Golden wrote: > >> 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, someo

Re: First attempt at a Python prog (Chess)

2013-02-15 Thread Neil Cerutti
On 2013-02-15, Oscar Benjamin wrote: > if score > best_score or best_score is None: You need the None check first to avoid an exception from the comparison. if best_score is None or score > best_score: -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list

Re: First attempt at a Python prog (Chess)

2013-02-15 Thread Chris Angelico
On Sat, Feb 16, 2013 at 2:36 AM, Tim Golden wrote: > How true. This last time, my team split into two: one half > to handle the display, the other working on the algorithm. We > ended up having to draw a really simple diagram on the back of > an envelope with the x,y pairs written out and pass it

Re: First attempt at a Python prog (Chess)

2013-02-15 Thread Tim Golden
On 15/02/2013 13:11, Oscar Benjamin wrote: > On 15 February 2013 11:36, Tim Golden wrote: >> 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, >

Re: First attempt at a Python prog (Chess)

2013-02-15 Thread Oscar Benjamin
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 pi

Re: First attempt at a Python prog (Chess)

2013-02-15 Thread Tim Golden
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 sligh

Re: First attempt at a Python prog (Chess)

2013-02-15 Thread Oscar Benjamin
On 13 February 2013 23:25, Chris Hinsley wrote: > New to Python, which I really like BTW. > > First serious prog. Hope you like it. I know it needs a 'can't move if your > King would be put into check' test. But the weighted value of the King piece > does a surprising emergent job. > > #!/usr/bin/

Re: First attempt at a Python prog (Chess)

2013-02-14 Thread Rick Johnson
On Thursday, February 14, 2013 11:48:10 AM UTC-6, Chris Hinsley wrote: > Is a Python list as fast as a bytearray? Why would you care about that now? Are you running this code on the Xerox Alto? Excuse me for the sarcasm but your post title has perplexed me: "First attempt at a Pyt

Re: First attempt at a Python prog (Chess)

2013-02-14 Thread Chris Hinsley
On 2013-02-14 21:14:03 +, jkn said: Hi Chris On Wednesday, 13 February 2013 23:25:09 UTC, Chris Hinsley wrote: New to Python, which I really like BTW. Welcome aboard! But aren't you supposed to be writing Forth? ;-) Cheers Jon N Well, I'm experimenting with other things too

Re: First attempt at a Python prog (Chess)

2013-02-14 Thread jkn
Hi Chris On Wednesday, 13 February 2013 23:25:09 UTC, Chris Hinsley wrote: > New to Python, which I really like BTW. Welcome aboard! But aren't you supposed to be writing Forth? ;-) Cheers Jon N -- http://mail.python.org/mailman/listinfo/python-list

Re: First attempt at a Python prog (Chess)

2013-02-14 Thread Ian Kelly
On Thu, Feb 14, 2013 at 10:48 AM, Chris Hinsley wrote: > Is a Python list as fast as a bytearray ? I didn't copy a C prog BTW ! >>> from timeit import Timer >>> t1 = Timer("board[36] = board[20]; board[20] = ' '", "board = >>> bytearray('RNBQKBNR >>> p

Re: First attempt at a Python prog (Chess)

2013-02-14 Thread Chris Hinsley
On 2013-02-14 06:05:13 +, Tim Roberts said: Chris Hinsley wrote: New to Python, which I really like BTW. First serious prog. Hope you like it. I know it needs a 'can't move if your King would be put into check' test. But the weighted value of the King piece does a surprising emergent job

Re: First attempt at a Python prog (Chess)

2013-02-13 Thread Tim Roberts
Chris Hinsley wrote: >New to Python, which I really like BTW. > >First serious prog. Hope you like it. I know it needs a 'can't move if >your King would be put into check' test. But the weighted value of the >King piece does a surprising emergent job. It looks a little like a C program ported

Re: First attempt at a Python prog (Chess)

2013-02-13 Thread Chris Hinsley
On 2013-02-13 23:55:20 +, Oscar Benjamin said: On 13 February 2013 23:25, Chris Hinsley wrote: New to Python, which I really like BTW. Glad to hear it. First serious prog. Hope you like it. I know it needs a 'can't move if your King would be put into check' test. But the weighted value

Re: First attempt at a Python prog (Chess)

2013-02-13 Thread Oscar Benjamin
On 13 February 2013 23:25, Chris Hinsley wrote: > New to Python, which I really like BTW. Glad to hear it. > First serious prog. Hope you like it. I know it needs a 'can't move if your > King would be put into check' test. But the weighted value of the King piece > does a surprising emergent job

First attempt at a Python prog (Chess)

2013-02-13 Thread Chris Hinsley
New to Python, which I really like BTW. First serious prog. Hope you like it. I know it needs a 'can't move if your King would be put into check' test. But the weighted value of the King piece does a surprising emergent job. #!/usr/bin/python -tt # -*- coding: utf-8 -*- # Copyright (C) 2013 C