First attempt at a Python prog (Chess)
Chris Hinsley
chris.hinsley at gmail.com
Thu Feb 14 12:48:10 EST 2013
On 2013-02-14 06:05:13 +0000, Tim Roberts said:
> Chris Hinsley <chris.hinsley at gmail.com> 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 line-by-line to Python. For
> example, in Python, there's no reason not to keep the board as an 8x8 array
> instead of a 64-element list. That by itself would make the code easier to
> read. It would also let you replace this:
> for row in range(8):
> for col in range(8):
>
> with the more Pythonic:
> for row in board:
> for cell in row:
>
> I would probably replace the piece_type function with a map that maps the
> piece number directly to the piece
Is a Python list as fast as a bytearray ? I didn't copy a C prog BTW !
Yep, after I posted the code I started thinking about how to do that
sort of thing :) Thanks, for the advice.
Chris
More information about the Python-list
mailing list