コード例 #1
0
 def highlight(self, view, errors, replace=False):
     bookmarked_line = self._bookmark_error(view)
     grouped = group_by(errors, lambda e: e.error_type)
     for error_type in type(self).error_types:
         lines = [e.line for e in grouped.get(error_type, list())]
         lines = [l for l in lines if l != bookmarked_line]
         self._highlight_lines(view, lines, error_type, replace)
コード例 #2
0
def resolve_retreat_orders():
    retreats = filter(lambda x: x['action'] == 'retreat',
                      gamestate['retreat_orders'].values())
    groups = group_by(retreats, 'to')
    for group in filter(lambda x: len(x) == 1, groups):
        [valid_retreat] = group
        territory = valid_retreat['territory']
        to = valid_retreat['to']
        piece = gamestate['dislodged_units'][territory][0]
        add_piece(piece, to)
コード例 #3
0
def status(args):
    # Transform selection criteria into test functions.
    if args.time:
        filter_time = lambda slot: \
            all(map(lambda invl: slot.intersects(invl), args.time))
    else:
        filter_time = lambda _: True
    if not args.all:
        filter_open = lambda slot: slot.iscurrent()
    else:
        filter_open = lambda _: True
    # Select work slots matching the selection criteria..
    slots = [slot for slot in session.wslots \
             if filter_time(slot) and filter_open(slot)]

    if not slots:
        # FIXME Update the message.
        print("You don't seem to be working now.")
    else:
        # FIXME Update the message, especially in case when called with --all.
        print("You have been working on the following tasks:")
        now = datetime.now(session.config['TIMEZONE'])
        task2slot = group_by(slots, "task", single_attr=True)
        for task in task2slot:
            task_slots = task2slot[task]
            # Expected case: only working once on the task in parallel:
            if len(task_slots) == 1:
                end = task_slots[0].end or now
                time_spent = format_timedelta(end - task_slots[0].start)
                try:
                    print("\t{time: >18}: {task}".format(task=task.name,
                                                         time=time_spent))
                except:
                    continue
            else:
                for slot in task_slots:
                    end = slot.end or now
                    time_spent = format_timedelta(end - slot.start)
                    print("M\t{time: >18}: {task}".format(task=task.name,
                                                          time=time_spent))
    return 0
コード例 #4
0
ファイル: highlighter.py プロジェクト: coltfred/SublimeSBT
 def highlight(self, view, errors, replace=False):
     grouped = group_by(errors, lambda e: e.error_type)
     for error_type in ['warning', 'failure', 'error']:
         lines = [e.line for e in grouped.get(error_type, list())]
         self._highlight_lines(view, lines, error_type, replace)
コード例 #5
0
def resolve_orders():
    board = gamestate['gameboard']
    orders = gamestate['orders']

    ## Break all support and convoy orders
    for territory in orders:
        order = orders[territory]
        if order['action'] == 'move/attack' and order['to'] in orders:
            if orders[order['to']]['action'] == 'support' and (
                    'to' not in orders[order['to']]
                    or orders[order['to']]['to'] != territory):
                add_order({'territory': order['to'], 'action': 'hold'})
            if orders[order['to']]['action'] == 'convoy':
                add_order({'territory': order['to'], 'action': 'hold'})

    ## Determine which units are successfully moved, and which are convoyed
    for territory in orders:
        order = orders[territory]
        if order['action'] == 'move/attack':
            if is_illegal_move(order):
                add_order({
                    'territory': territory,
                    'action': 'hold',
                    'is_convoyed': False
                })
            else:
                order['is_convoyed'] = is_convoyed(order)

    ## Calculate support for each attacking and holding piece
    for territory in orders:
        order = get_order(territory)
        if order['action'] in frozenset(['move/attack', 'hold']):
            increase_support(territory)
        elif order['action'] == 'support':
            increase_support(order['supporting'])

    ## Find and resolve swap standoffs
    for territory in orders.copy():
        order = get_order(territory)
        if order['action'] == 'move/attack':
            attacked_territory = order['to']
            attacked_territory_order = get_order(attacked_territory)
            if attacked_territory_order and \
            attacked_territory < territory and \
            attacked_territory_order['action'] == 'move/attack' and \
            attacked_territory_order['to'] == territory and \
            not order['is_convoyed'] and \
            not attacked_territory_order['is_convoyed']:
                ## Swap standoff
                if order['support'] > attacked_territory_order['support']:
                    add_order({
                        'territory': attacked_territory,
                        'action': 'hold',
                        'support': 0
                    })
                elif order['support'] < attacked_territory_order['support']:
                    add_order({
                        'territory': territory,
                        'action': 'hold',
                        'support': 0
                    })
                else:
                    add_order({
                        'territory': territory,
                        'action': 'hold',
                        'support': 1
                    })
                    add_order({
                        'territory': attacked_territory,
                        'action': 'hold',
                        'support': 1
                    })
    ## Find and resolve move/move standoffs
    attacking_orders = filter(lambda x: x['action'] == 'move/attack',
                              orders.values())
    for group in filter(lambda x: len(x) > 1, group_by(attacking_orders,
                                                       'to')):
        losers = determine_losers(group)
        for order in losers:
            add_order({
                'territory': order['territory'],
                'action': 'hold',
                'support': 1
            })
        if len(losers) == len(group):
            gamestate['invalid_retreats'].add(group[0]['to'])
    ## Loop and resolve move/hold standoffs
    standoff_found = True
    while standoff_found:
        standoff_found = False
        for territory in orders.copy():
            order = get_order(territory)
            if order['action'] == 'move/attack':
                attacked_territory = order['to']
                attacked_territory_order = get_order(attacked_territory)
                if attacked_territory_order and attacked_territory_order[
                        'action'] == 'hold':
                    standoff_found = True
                    if order['support'] > attacked_territory_order[
                            'support'] and get_piece(attacked_territory).split(
                            )[0] != get_piece(territory).split()[0]:
                        dislodge_territory(attacked_territory, territory)
                        break  ## Can't keep iterating over orders because it has been modified TODO find a better way to do this
                    else:
                        add_order({
                            'territory': territory,
                            'action': 'hold',
                            'support': 1
                        })