Esempio n. 1
0
def main():
	"""
	**********************************************************************************************************************
	Main code to be run at program execution
	"""
	# pairs = load_clues( CLUES_FILE_PATH )
	puzzle_name = 'oct0515'
	puzzle_structure.read_raw_puzzle( puzzle_name )
	lookup_all_clues( puzzle_name )
Esempio n. 2
0
def main():
    """
	**********************************************************************************************************************
	Main code to be run at program execution
	"""
    # pairs = load_clues( CLUES_FILE_PATH )
    puzzle_name = 'oct0515'
    puzzle_structure.read_raw_puzzle(puzzle_name)
    lookup_all_clues(puzzle_name)
Esempio n. 3
0
def main():
    puzzle_structure.read_raw_puzzle(puzzle_name)
    lookup_all_clues(puzzle_name)
Esempio n. 4
0
def fill(puzzle_name):
    """
	**********************************************************************************************************************
	This does all the work solving the puzzle, starting with reading the raw
	input, then generating all candidate answers and filling the grid

	@param: {string} puzzle_name
	"""
    ## read the raw puzzle input ##
    puzzle_structure.read_raw_puzzle(puzzle_name)
    ## create a blank skeleton ##
    puzzle = puzzle_structure.create_puzzle(puzzle_name, 'skeleton')
    ## scrape all the clues ##
    clue_scraper.lookup_all_clues(puzzle_name)

    ## ask for input to keep solving ##
    # print( 'Answers computed. Proceed with solving? ' )
    # cont = sys.stdin.readline()

    ## keep track of the puzzle at the previous iteration to control ##
    ## how long to solve at each step ##
    previous_puzzle_state = []

    puzzle_structure.sort_answers(puzzle_name)
    f = open('puzzles/' + puzzle_name + '/' + puzzle_name + '-answers.txt',
             'r')
    answers = f.read().splitlines()[3:]

    ## extract answer data into list ##
    for i in range(len(answers)):
        answers[i] = answers[i].strip().split('\t')
        answers[i][0] = int(answers[i][0])
        answers[i][1] = int(answers[i][1])
        answers[i][3] = ast.literal_eval(answers[i][3])
        answers[i][4] = ast.literal_eval(answers[i][4])

    ## fill singleton answers and update the candidates until this no longer ##
    ## yields any change in the puzzle ##
    while puzzle != previous_puzzle_state:
        ## update previous state ##
        previous_puzzle_state = [row[:] for row in puzzle]
        ## fill all singletons, update possibilites, and resort ##
        answers, puzzle = fill_all_singletons(answers, puzzle, True)
        answers = update_candidates(answers, puzzle)
        answers = sorted(answers, cmp=puzzle_structure.compare_answers)
        answers = refactor_answers(answers)

    previous_puzzle_state = []
    ## update answers with single word and wikipedia title searches ##
    ## then fill singletons until this no longer yields any change ##
    while puzzle != previous_puzzle_state:
        ## update previous state ##
        previous_puzzle_state = [row[:] for row in puzzle]
        answers = search_dictionaries(answers)
        answers = sorted(answers, cmp=puzzle_structure.compare_answers)
        answers = refactor_answers(answers)
        ## fill the singletons ##
        answers, puzzle = fill_all_singletons(answers, puzzle, False)
        answers = update_candidates(answers, puzzle)

    ## fill based on the first candidate. this is pretty arbitrary ##
    for answer in answers:
        if len(answer[4]) > 0:
            puzzle = fill_answer(answer[4][0], puzzle, answer[0], answer[1],
                                 answer[2])
        ## clear console using escape sequence ##
        print(chr(27) + '[2J')
        ## print the puzzle to stdout ##
        puzzle_structure.print_puzzle(puzzle)
        time.sleep(TIME_DELAY)

    ## fill the rest of the squares with 'E'. this is extremely arbitrary ##
    puzzle = fill_empty_squares(puzzle)

    ## write the final output for evaluation ##
    puzzle_structure.write_puzzle(puzzle_name, puzzle)
Esempio n. 5
0
def fill( puzzle_name ):
	"""
	**********************************************************************************************************************
	This does all the work solving the puzzle, starting with reading the raw
	input, then generating all candidate answers and filling the grid

	@param: {string} puzzle_name
	"""
	## read the raw puzzle input ##
	puzzle_structure.read_raw_puzzle( puzzle_name )
	## create a blank skeleton ##
	puzzle = puzzle_structure.create_puzzle( puzzle_name, 'skeleton' )
	## scrape all the clues ##
	clue_scraper.lookup_all_clues( puzzle_name )

	## ask for input to keep solving ##
	# print( 'Answers computed. Proceed with solving? ' )
	# cont = sys.stdin.readline()

	## keep track of the puzzle at the previous iteration to control ##
	## how long to solve at each step ##
	previous_puzzle_state = []

	puzzle_structure.sort_answers( puzzle_name )
	f = open( 'puzzles/' + puzzle_name + '/' + puzzle_name + '-answers.txt', 'r' )
	answers = f.read().splitlines()[3:]

	## extract answer data into list ##
	for i in range( len( answers ) ):
		answers[i] = answers[i].strip().split( '\t' )
		answers[i][0] = int( answers[i][0] )
		answers[i][1] = int( answers[i][1] )
		answers[i][3] = ast.literal_eval( answers[i][3] )
		answers[i][4] = ast.literal_eval( answers[i][4] )

	## fill singleton answers and update the candidates until this no longer ##
	## yields any change in the puzzle ##
	while puzzle != previous_puzzle_state:
		## update previous state ##
		previous_puzzle_state = [ row[:] for row in puzzle ]
		## fill all singletons, update possibilites, and resort ##
		answers, puzzle = fill_all_singletons( answers, puzzle, True )
		answers = update_candidates( answers, puzzle )
		answers = sorted( answers, cmp=puzzle_structure.compare_answers )
		answers = refactor_answers( answers )


	previous_puzzle_state = []
	## update answers with single word and wikipedia title searches ##
	## then fill singletons until this no longer yields any change ##
	while puzzle != previous_puzzle_state:
		## update previous state ##
		previous_puzzle_state = [ row[:] for row in puzzle ]
		answers = search_dictionaries( answers )
		answers = sorted( answers, cmp=puzzle_structure.compare_answers )
		answers = refactor_answers( answers )
		## fill the singletons ##
		answers, puzzle = fill_all_singletons( answers, puzzle, False )
		answers = update_candidates( answers, puzzle )


	## fill based on the first candidate. this is pretty arbitrary ##
	for answer in answers:
		if len( answer[4] ) > 0:
			puzzle = fill_answer( answer[4][0], puzzle, answer[0], answer[1], answer[2] )
		## clear console using escape sequence ##
		print( chr( 27 ) + '[2J' )
		## print the puzzle to stdout ##
		puzzle_structure.print_puzzle( puzzle )
		time.sleep( TIME_DELAY )

	## fill the rest of the squares with 'E'. this is extremely arbitrary ##
	puzzle = fill_empty_squares( puzzle )

	## write the final output for evaluation ##
	puzzle_structure.write_puzzle( puzzle_name, puzzle )