示例#1
0
def load_sudoku(sudoku):
    """ Create a list of fields with all relevant information based on a sudoku. The sudoku needs to be in the form found in Sudokus.py """
    y = 0
    id_num = 0
    fields = []
    
    for row in sudoku:
        x = 0
        for number in row:
            # Create a field
            field = Field()

            # Set coordinates, 3x3 box and and id
            field.x = x
            field.y = y
            field.box = set_box_number(x, y)
            field.id = id_num
            

            field.number = number

            # If the field has a number, that is the only possibility
            if field.number != 0:
                field.possible = {field.number}

            fields.append(field)

            # Step up all index
            x += 1
            id_num += 1
        y += 1
        
    return fields
示例#2
0
def copy_fields(fields):
    """ Create a copy of the fields in the list called "fields" """
    fields_c = []
    for field in fields:
        # copy all values in the fields and append them to copy list
        f = Field()
        f.x = field.x
        f.y = field.y
        f.box = field.box
        f.id = field.id

        f.number = field.number
        f.possible = field.possible

        fields_c.append(f)
    
    return fields_c