connect four (game)

nospam.Michael Torrie torriem at gmail.com
Sun Nov 26 03:09:00 EST 2017


On 11/25/2017 12:58 PM, namenobodywants at gmail.com wrote:
> the idea is that there should be exactly one object posinf (positive
infinity) that compares as strictly greater than any number ever considered,
and exactly one object neginf that compares as strictly less; as the code
stands now there is no reason not to use +/-70 in that capacity; the "infinity"
 class is there so that the game-playing parts of the code (which at present
are intentionally as primitive as possible) can be modified more smoothly
later; the single place where "infinity" is instantiated is in the function
"getvalue", which returns the value of a finished game:
>
> def getvalue(winner,accessibles):
>     return Infinity(+1) if winner == ex else Infinity(-1) if winner == oh
else 0 if not accessibles else None
>
> if ex has won then the value of the game is posinf; if oh has won then it's
neginf; if the game is tied (no winner but no accessible columns remaining)
then the value of the game is zero; otherwise the game is not finished and its
finished value is None

So you are using this Infinity class as a sentinel value of some kind?
Representing game state?  There may be an easier way than a full on custom
type.  Sometimes just a sentinel object is sufficient.  Or an enumeration.




More information about the Python-list mailing list