dev-picayune
0 view | +0 today
Follow
Your new post is loading...
Your new post is loading...
Rescooped by Roxane Luepkeev from dev-picayune
Scoop.it!

Dev-Picayune

Dev-Picayune | dev-picayune | Scoop.it

Via Suzi Claxton, Lisset Parting
Roxane Luepkeev's insight:

The behavior above mirrors the standard Checkers rule that if you have a capture, you must take it - otherwise, you can make a regular move. In my code, both state.captures and state.moves are properties that return Python lists. Since an empty list evaluates to False in an or statement, if state.captures is empty, then the return statement automatically uses state.moves list instead.

more...
Suzi Claxton's curator insight, August 27, 2013 3:12 AM

It took some thought to come up with an equivalent behavior for generator objects. In the new version, legal_moves becomes a wrapper method that returns one generator object or the other based on whether the first generator object yields at least one item.

Lisset Parting's curator insight, August 27, 2013 3:17 AM

It took some thought to come up with an equivalent behavior for generator objects. In the new version, legal_moves becomes a wrapper method that returns one generator object or the other based on whether the first generator object yields at least one item.

Suzi Claxton's curator insight, August 27, 2013 3:18 AM

The behavior above mirrors the standard Checkers rule that if you have a capture, you must take it - otherwise, you can make a regular move. In my code, both state.captures and state.moves are properties that return Python lists. Since an empty list evaluates to False in an or statement, if state.captures is empty, then the return statement automatically uses state.moves list instead.

Scooped by Roxane Luepkeev
Scoop.it!

Dev-Picayune

Dev-Picayune | dev-picayune | Scoop.it
Roxane Luepkeev's insight:

The behavior above mirrors the standard Checkers rule that if you have a capture, you must take it - otherwise, you can make a regular move. In my code, both state.captures and state.moves are properties that return Python lists. Since an empty list evaluates to False in an or statement, if state.captures is empty, then the return statement automatically uses state.moves list instead.

more...
No comment yet.