Re: Sort with extra variables

2007-03-03 Thread Thomas Dybdahl Ahle
Den Sat, 03 Mar 2007 11:26:08 +0100 skrev Diez B. Roggisch: >> Well, you'd have to define the function inside the sortMoves function, >> as it is where the variables exists. >> >> def sortMoves(board, table, ply, moves): >> def sortKey(move): >> return getMoveValue(board, table, ply,

Re: Sort with extra variables

2007-03-03 Thread Diez B. Roggisch
> Well, you'd have to define the function inside the sortMoves function, as > it is where the variables exists. > > def sortMoves(board, table, ply, moves): > def sortKey(move): > return getMoveValue(board, table, ply, move) > moves.sort(key=sortKey, reverse=True) return moves >

Re: Sort with extra variables

2007-03-03 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, Thomas Dybdahl Ahle wrote: > Den Fri, 02 Mar 2007 21:13:02 +0100 skrev Bjoern Schliessmann: > >> Thomas Dybdahl Ahle wrote: >> >>> However I'd really like not to use the lambda, as it slows down the >>> code. >> >> Did you check how much the slowdown is? > > Yes, the la

Re: Sort with extra variables

2007-03-02 Thread Alex Martelli
Thomas Dybdahl Ahle <[EMAIL PROTECTED]> wrote: > I have a sort function in a python chess program. > Currently it looks like this: > > def sortMoves (board, table, ply, moves): > f = lambda move: getMoveValue (board, table, ply, move) > moves.sort(key=f, reverse=True) > return moves >

Re: Sort with extra variables

2007-03-02 Thread MonkeeSage
On Mar 2, 7:34 pm, Thomas Dybdahl Ahle <[EMAIL PROTECTED]> wrote: > Well, you'd have to define the function inside the sortMoves function, as > it is where the variables exists. Oh, sorry, I wasn't thinking there! Regards, Jordan -- http://mail.python.org/mailman/listinfo/python-list

Re: Sort with extra variables

2007-03-02 Thread Thomas Dybdahl Ahle
Den Fri, 02 Mar 2007 16:46:05 -0800 skrev Paul Rubin: > Thomas Dybdahl Ahle <[EMAIL PROTECTED]> writes: >> Do you mean that I add my moves something like this? >> >> from heapq import heappush, heappop >> heap = [] >> for move in genAll(): >> heappush(heap, (-getMoveValue (board, table, ply,

Re: Sort with extra variables

2007-03-02 Thread Thomas Dybdahl Ahle
Den Fri, 02 Mar 2007 16:27:47 -0800 skrev MonkeeSage: > On Mar 2, 5:51 pm, Thomas Dybdahl Ahle <[EMAIL PROTECTED]> wrote: >> I guess the thing is that I'd have to create a new callable no matter >> how, as it is the only way to bring the extra variables into the >> getValue function when called by

Re: Sort with extra variables

2007-03-02 Thread Paul Rubin
Thomas Dybdahl Ahle <[EMAIL PROTECTED]> writes: > Do you mean that I add my moves something like this? > > from heapq import heappush, heappop > heap = [] > for move in genAll(): > heappush(heap, (-getMoveValue (board, table, ply, move), move)) > > And then use heappop(heap) in the alphabeta

Re: Sort with extra variables

2007-03-02 Thread MonkeeSage
On Mar 2, 5:51 pm, Thomas Dybdahl Ahle <[EMAIL PROTECTED]> wrote: > I guess the thing is that I'd have to create a new callable no matter > how, as it is the only way to bring the extra variables into the getValue > function when called by sort. Yes, but you don't have to create it every time you

Re: Sort with extra variables

2007-03-02 Thread Thomas Dybdahl Ahle
Den Fri, 02 Mar 2007 15:20:33 -0800 skrev MonkeeSage: > On Mar 2, 5:11 pm, Thomas Dybdahl Ahle <[EMAIL PROTECTED]> wrote: >> Wouldn't that be just as slow? > > Well, I'm not sure about speed, but with the lambda you're creating a > new callable for f every time you call sortMoves. Intuitively, th

Re: Sort with extra variables

2007-03-02 Thread MonkeeSage
On Mar 2, 5:11 pm, Thomas Dybdahl Ahle <[EMAIL PROTECTED]> wrote: > Wouldn't that be just as slow? Well, I'm not sure about speed, but with the lambda you're creating a new callable for f every time you call sortMoves. Intuitively, that seems like it would be more of a hit than just doing a lookup

Re: Sort with extra variables

2007-03-02 Thread Thomas Dybdahl Ahle
Den Fri, 02 Mar 2007 20:33:45 +0100 skrev Diez B. Roggisch: > Thomas Dybdahl Ahle schrieb: >> I have a sort function in a python chess program. Currently it looks >> like this: >> >> def sortMoves (board, table, ply, moves): >> f = lambda move: getMoveValue (board, table, ply, move) >> mo

Re: Sort with extra variables

2007-03-02 Thread Thomas Dybdahl Ahle
Den Fri, 02 Mar 2007 11:44:27 -0800 skrev Paul Rubin: > Thomas Dybdahl Ahle <[EMAIL PROTECTED]> writes: >> Do you have any ideas how I can sort these moves the fastest? > > One idea: if you're using alpha-beta pruning, maybe you can use > something like heapq instead of sorting, since a lot of th

Re: Sort with extra variables

2007-03-02 Thread Thomas Dybdahl Ahle
Den Fri, 02 Mar 2007 21:13:02 +0100 skrev Bjoern Schliessmann: > Thomas Dybdahl Ahle wrote: > >> However I'd really like not to use the lambda, as it slows down the >> code. > > Did you check how much the slowdown is? Yes, the lambda adds 50% -- http://mail.python.org/mailman/listinfo/python-l

Re: Sort with extra variables

2007-03-02 Thread Bjoern Schliessmann
Thomas Dybdahl Ahle wrote: > However I'd really like not to use the lambda, as it slows down > the code. Did you check how much the slowdown is? Regards, Björn -- BOFH excuse #65: system needs to be rebooted -- http://mail.python.org/mailman/listinfo/python-list

Re: Sort with extra variables

2007-03-02 Thread Paul Rubin
Thomas Dybdahl Ahle <[EMAIL PROTECTED]> writes: > Do you have any ideas how I can sort these moves the fastest? One idea: if you're using alpha-beta pruning, maybe you can use something like heapq instead of sorting, since a lot of the time you only have to look at the first few moves (ordered bes

Re: Sort with extra variables

2007-03-02 Thread Diez B. Roggisch
Thomas Dybdahl Ahle schrieb: > I have a sort function in a python chess program. > Currently it looks like this: > > def sortMoves (board, table, ply, moves): > f = lambda move: getMoveValue (board, table, ply, move) > moves.sort(key=f, reverse=True) > return moves > > However I'd rea

Sort with extra variables

2007-03-02 Thread Thomas Dybdahl Ahle
I have a sort function in a python chess program. Currently it looks like this: def sortMoves (board, table, ply, moves): f = lambda move: getMoveValue (board, table, ply, move) moves.sort(key=f, reverse=True) return moves However I'd really like not to use the lambda, as it slows dow