connect four (game)

namenobodywants at gmail.com namenobodywants at gmail.com
Sat Nov 25 14:58:59 EST 2017


On Saturday, November 25, 2017 at 5:00:12 AM UTC-8, bartc wrote:

> Actually I've no idea what these tests are supposed to prove. 

me neither; i think you guys may be getting me out of my depth now


> They are to do with one class called 'infinity', which is never used in the rest 
> of the program apart from one line.
> 
> I established that within a few seconds, and I would concentrate on what 
> 'infinity' is actually for, rather than go to considerable lengths to 
> test a class that may not actually be needed.

my current version of "infinity" looks like this

class Infinity:
    def __init__(self,signum): self.signum = (+1) if signum > 0 else (-1)
    def __repr__(self): return '+oo' if self.signum == (+1) else '-oo'
    def __lt__(self,other): return self.signum == (-1)
    def __le__(self,other): return self.signum == (-1)
    def __gt__(self,other): return self.signum == (+1)
    def __ge__(self,other): return self.signum == (+1)
    def __eq__(self,other): return isinstance(other,Infinity) and self.signum == other.signum

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

peace
stm










More information about the Python-list mailing list