コード例 #1
0
    def test_color_state(self):
        generator = PuzzleGenerator(5)
        generator.generate_filled_field()
        generator.field_state.color_state()

        for cell in generator.field_state.field.get_all_cells():
            self.assertTrue(generator.field_state._colored_cells[cell] in
                            generator.field_state.COLORS)
コード例 #2
0
    def test_field_to_string(self):
        generator = PuzzleGenerator(4)
        generator.generate_filled_field()
        state = generator.field_state
        state_to_string = str(state)
        state_from_string = FieldState.from_string_to_state(state_to_string)

        self.assertDictEqual(state_from_string.get_full_state(),
                             state.get_full_state())
コード例 #3
0
    def test_generate_field_for_game_with_unities(self):
        generator = PuzzleGenerator(4)
        generator.generate_filled_field()
        generator.generate_field_for_game(False)

        for cell, value in filter(
                lambda cell_state: cell_state[1] == 1,
                generator.field_state.get_full_state().items()):
            self.assertTrue(generator.game_field.get_state(cell) == 1)
コード例 #4
0
def main():
    args = parse_args()

    if args.size:
        try:
            if args.maxvalue:
                generator = PuzzleGenerator(args.size, args.maxvalue)
            else:
                generator = PuzzleGenerator(args.size)
            generator.generate_filled_field()

            if args.empty:
                generator.generate_field_for_game(bool(args.unity), args.empty)
            else:
                generator.generate_field_for_game(bool(args.unity))

            write_result(args.puzzle, generator.game_field, args.color)
            write_result(args.solution, generator.field_state, args.color)

        except Exception as e:
            print('Error while generating puzzle\n{}'.format(e),
                  file=sys.stderr)
            sys.exit(ERROR_GENERATING_PUZZLE)
コード例 #5
0
    def test_generate_field_for_game_empty_unities(self):
        percent = 50
        unity = True

        generator = PuzzleGenerator(4)
        generator.generate_filled_field()
        generator.generate_field_for_game(unity, percent)

        empty_cells = list(
            filter(lambda cell: generator.game_field.get_state(cell) == 0,
                   generator.field.get_all_cells()))

        min_empty_count = 0
        for group in generator.groups:
            min_empty_count += int(group.get_value() * percent / 100)

        max_empty_count = min_empty_count + len(generator.groups)
        self.assertTrue(min_empty_count <= len(empty_cells) <= max_empty_count)

        for group in filter(lambda g: g.get_value() != 1, generator.groups):
            self.assertTrue(
                any(
                    generator.field_state.get_state(cell) != 0
                    for cell in group.initial_cells))
コード例 #6
0
    def test_generate_filled_field(self):
        generator = PuzzleGenerator(3)
        generator.generate_filled_field()

        for number in generator.field_state.get_full_state().values():
            self.assertNotEqual(number, 0)