from Predicate import * from zerolife.enum import Direction class DirectionalTestPredicate(TestPredicate): '''compares the state of each direction to the direction of the desired state''' def holds(self, board, coordinates): for k, v in self.desiredState.items(): print("Direction " + str(k)) print("value " + str(v)) print(board[coordinates[0]+k.x][coordinates[1]+k.y]) if board[coordinates[0]+k.x][coordinates[1]+k.y].state != v: return False return True def __str__(self): '''This function looks like one line of unreadable nonsense. This is what happens: 1. join the pairs of directions to states with a colon, making: direction:state 2. join that list using spaces 3. join DIRECTION, the result from 2, and some parenthesis ''' return ''.join(["(DIRECTION ",\ ' '.join((''.join([k.__str__(), ':', \ v.__str__()]) for (k, v) in self.desiredState.items())), ")"])