def right_down(self): if self.parent.selected_units: units = [ unit for unit in self.parent.get_units() if unit.owner == self.parent.player_id ] # TODO: Filter-chaining should fix this # TODO: Implement 'unit_set' type - iterable but also features a 'filter' option? return commands.Move(ids=[ unit.id for unit in units if 'orders' in unit and 'move' in unit.orders ], to=self.parent.get_mouse_world_pos())
def parse(cmd): if cmd == '': return commands.Repeat() elif len(cmd) == 1 and cmd.isdigit(): rank = int(cmd) return commands.Frequent(rank) elif cmd == 'h': return commands.Human() elif cmd == 'r': return commands.Rated() elif cmd == '/': return commands.Root() elif cmd == '?': return commands.Help() elif cmd == '??': return commands.MoreHelp() elif cmd == 't': return commands.HelpTopic('t') elif cmd == 'd': return commands.HelpTopic('d') elif cmd == 'm': return commands.HelpTopic('m') elif _REGEX_UP.fullmatch(cmd): return commands.Up(len(cmd)) elif _REGEX_DAYS.fullmatch(cmd): # TODO is there a good way to avoid duplicating the .fullmatch() call? days_str = _REGEX_DAYS.fullmatch(cmd).group(1) days = int(days_str) return commands.Days(days) elif _REGEX_MONTHS.fullmatch(cmd): months_str = _REGEX_MONTHS.fullmatch(cmd).group(1) months = int(months_str) return commands.Months(months) elif _REGEX_TIME_CONTROL.fullmatch(cmd): minutes_str = _REGEX_TIME_CONTROL.fullmatch(cmd).group(1) minutes = int(minutes_str) return commands.TimeControl(minutes) else: # TODO maybe want a regex for moves? return commands.Move(cmd)
('--', commands.Up(2)), ('-----', commands.Up(5)), ('t', commands.HelpTopic('t')), ('2t', commands.TimeControl(2)), ('20t', commands.TimeControl(20)), ('d', commands.HelpTopic('d')), ('m', commands.HelpTopic('m')), ('3d', commands.Days(3)), ('21d', commands.Days(21)), ('7m', commands.Months(7)), ('77777m', commands.Months(77777)), # actual algebraic moves ('e4', commands.Move('e4')), ('g6', commands.Move('g6')), ('Nf3', commands.Move('Nf3')), ('O-O', commands.Move('O-O')), ('O-O-O', commands.Move('O-O-O')), ('O-O#', commands.Move('O-O#')), ('Bg8+', commands.Move('Bg8+')), # and many more... # things that aren't actually algebraic moves but aren't valid commands # (currently we just parse all of these as algebraic moves) ('13', commands.Move('13')), ('1000', commands.Move('1000')), ]) def test_parse(input, expected): assert parse(input) == expected
def test_move(self): thing = commands.Move('e4') assert thing.data.move == 'e4'
def test_different_type(self): thing = commands.Move('e4') # TODO e4 is not a number other = commands.Days('e4') assert thing != other
def test_same_type_different_contents(self): thing = commands.Move('e4') other = commands.Move('d4') assert thing != other
def test_same_type_same_contents(self): thing = commands.Move('e4') other = commands.Move('e4') assert thing == other
def test_false(self): thing = commands.Move('e4') assert not commands.Days.isinstance(thing)
def test_true(self): thing = commands.Move('e4') assert commands.Move.isinstance(thing)