Example #1
0
    def isolated_scores(self):
        """
        The input format of the score sheet contains information about
        which team has how many tokens in a zone. We don't really care
        about this level, and really want to know _who owns_ each zone.
        Similarly, it's more useful have a list of which slots a team
        owns, rather than a map of slot to whether or not they own it.

        This method performs these tidyups and returns a new dictionary.
        In the process, we also ensure that there are no clashes.
        """

        zone_tokens = {}
        slot_bottoms = {}
        for tla, team_data in self._scoresheet.items():
            validate_team(tla, team_data)
            zone_tokens[tla] = team_data['zone_tokens']
            slot_bottoms[tla] = team_data['slot_bottoms']

        zones_owned = tidy_zones(zone_tokens)
        slots_owned = tidy_slots(slot_bottoms)

        isolated = {}
        for tla, team_data in self._scoresheet.items():
            isolated[tla] = {
                'robot_moved': team_data['robot_moved'],
                'slots_owned': slots_owned[tla],
                'upright_tokens': team_data['upright_tokens'],
                'zones_owned': zones_owned[tla],
            }

        return isolated
Example #2
0
    def isolated_scores(self):
        """
        The input format of the score sheet contains information about
        which team has how many tokens in a zone. We don't really care
        about this level, and really want to know _who owns_ each zone.
        Similarly, it's more useful have a list of which slots a team
        owns, rather than a map of slot to whether or not they own it.

        This method performs these tidyups and returns a new dictionary.
        In the process, we also ensure that there are no clashes.
        """

        zone_tokens = {}
        slot_bottoms = {}
        for tla, team_data in self._scoresheet.items():
            validate_team(tla, team_data)
            zone_tokens[tla] = team_data['zone_tokens']
            slot_bottoms[tla] = team_data['slot_bottoms']

        zones_owned = tidy_zones(zone_tokens)
        slots_owned = tidy_slots(slot_bottoms)

        isolated = {}
        for tla, team_data in self._scoresheet.items():
            isolated[tla] = {
                'robot_moved': team_data['robot_moved'],
                'slots_owned': slots_owned[tla],
                'upright_tokens': team_data['upright_tokens'],
                'zones_owned': zones_owned[tla],
            }

        return isolated
def test_tidy_zones_mixed():
    input_ = {
        'TLA1' : { 0: 1, 1: 4, 2: 0, 3: 0 },
        'TLA2' : { 0: 1, 1: 1, 2: 2, 3: 0 },
    }

    expected = {
        'TLA1' : set([1]),
        'TLA2' : set([2]),
    }

    actual = tidy_zones(input_)
    assert actual == expected
def test_tidy_zones_tie():
    input_ = {
        'TLA1' : { 0: 1, 1: 0, 2: 0, 3: 0 },
        'TLA2' : { 0: 1, 1: 0, 2: 0, 3: 0 },
    }

    expected = {
        'TLA1' : set(),
        'TLA2' : set(),
    }

    actual = tidy_zones(input_)
    assert actual == expected
def test_tidy_zones_simple():
    input_ = {
        'TLA1' : { 0: 1, 1: 1, 2: 0, 3: 0 },
        'TLA2' : { 0: 0, 1: 0, 2: 1, 3: 1 },
    }

    expected = {
        'TLA1' : set([0, 1]),
        'TLA2' : set([2, 3]),
    }

    actual = tidy_zones(input_)
    assert actual == expected
def test_tidy_zones_mixed():
    input_ = {
        'TLA1': {
            0: 1,
            1: 4,
            2: 0,
            3: 0
        },
        'TLA2': {
            0: 1,
            1: 1,
            2: 2,
            3: 0
        },
    }

    expected = {
        'TLA1': set([1]),
        'TLA2': set([2]),
    }

    actual = tidy_zones(input_)
    assert actual == expected
def test_tidy_zones_tie():
    input_ = {
        'TLA1': {
            0: 1,
            1: 0,
            2: 0,
            3: 0
        },
        'TLA2': {
            0: 1,
            1: 0,
            2: 0,
            3: 0
        },
    }

    expected = {
        'TLA1': set(),
        'TLA2': set(),
    }

    actual = tidy_zones(input_)
    assert actual == expected
def test_tidy_zones_simple():
    input_ = {
        'TLA1': {
            0: 1,
            1: 1,
            2: 0,
            3: 0
        },
        'TLA2': {
            0: 0,
            1: 0,
            2: 1,
            3: 1
        },
    }

    expected = {
        'TLA1': set([0, 1]),
        'TLA2': set([2, 3]),
    }

    actual = tidy_zones(input_)
    assert actual == expected