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

Dev-Picayune

Dev-Picayune | dev-picayune | Scoop.it

Via Lisset Parting
Suzi Claxton'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.

Roxane Luepkeev's curator insight, August 27, 2013 3:19 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 Suzi Claxton
Scoop.it!

Dev-Picayune

Dev-Picayune | dev-picayune | Scoop.it
Suzi Claxton's insight:

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.

more...
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.

Roxane Luepkeev's curator insight, August 27, 2013 3:19 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.