def main():

    # try to read an existing or new puzzle from command line (not required)
    try:
        puzzle_idx = sys.argv[1].strip().upper()
    except:
        print('Please enter a puzzle. Exiting...')
        exit(0)

    if puzzle_idx is not None:

        # check validity of letters
        utils.check_letters(puzzle_idx)

        # choose standard sorting for all puzzle file names
        puzzle_idx = utils.sort_letters(puzzle_idx)

    # select puzzle, generate it if it doesn't exist
    puzl_path = utils.select_puzzle(puzzle_idx)

    # load json puzzle data
    puzl = utils.read_puzzle(puzl_path)

    # solve puzzle (cheat mode)
    solve(puzl)
def main(puzzle_input=None):

    # get array of previously generated puzzles, to check against
    existing_puzzles = get_existing_puzzles()

    words = get_words(params.WORD_LIST_PATH)
    #words = words[0:10000] #debug
    print('total words: ', len(words))
    pool = get_pangramable_letter_pool(words)
    print(f'unique {params.TOTAL_LETTER_COUNT}-letter pool: ' + str(len(pool)))

    # header for csv output
    print('\t'.join(
        ('letters', 'word_count', 'total_score', 'pangram_count', 'is_valid')))

    if len(sys.argv) > 1:
        puzzle_input = sys.argv[1].strip().upper()
    else:
        puzzle_input = None

    # user has requested a specific puzzle be created
    if puzzle_input is not None:
        # check validity of letters
        utils.check_letters(puzzle_input)

        # manually request one puzzle by defining letters  on command line
        # alphabetize the non-center letters (all but first in array)
        puzzle_input = utils.sort_letters(puzzle_input)

        make_puzzles(words, pool, existing_puzzles, puzzle_input)

    # user/code has no specific puzzle to create, generating many
    else:
        idx_valid = 0

        # generating N puzzles based on params
        for _ in range(params.MAX_PUZZLE_TRIES):
            idx_valid += make_puzzles(words, pool, existing_puzzles, None)

            # reached target count of puzzles, exiting loop
            if idx_valid >= params.PUZZLE_COUNT:
                exit(0)

    return puzzle_input
def main():
    
    # try to read an existing or new puzzle from command line (not required)
    try:
        puzzle_idx = sys.argv[1].strip().upper()
    except:
        puzzle_idx = None

    if puzzle_idx is not None:
        
        # check validity of letters
        utils.check_letters(puzzle_idx)

        # choose standard sorting for all puzzle file names
        puzzle_idx = utils.sort_letters(puzzle_idx)

    puzl_path = utils.select_puzzle(puzzle_idx)

    puzl = utils.read_puzzle(puzl_path)

    play(puzl)
Beispiel #4
0
    def test_utils(self):

        self.assertTrue(utils.check_letters('lmRRlMLRRLMrmlRmlMR'))
        self.assertTrue(utils.check_letters(''))
        self.assertTrue(utils.check_letters('LMRrml'))
        self.assertFalse(utils.check_letters('0'))
        self.assertFalse(utils.check_letters('LMRrml0'))
        self.assertFalse(utils.check_letters('lmRRlMLRRLMrmlRmlMR '))
def main(puzzle_input=None):

    words = get_words(params.WORD_LIST_PATH)
    #words = words[0:10000] #debug

    # header for csv output
    print('\t'.join(('index', 'letters', 'word_count', 'total_score',
                     'pangram_count', 'is_valid')))

    if len(sys.argv) > 1:
        puzzle_input = sys.argv[1].strip().upper()
    else:
        puzzle_input = None

    # user has requested a specific puzzle be created
    if puzzle_input is not None:
        # check validity of letters
        utils.check_letters(puzzle_input)

        # manually request one puzzle by defining letters  on command line
        # alphabetize the non-center letters (all but first in array)
        puzzle_input = utils.sort_letters(puzzle_input)

        make_puzzles(words, puzzle_input)

    # user/code has no specific puzzle to create, generating many
    else:
        idx_valid = 0

        # generating N puzzles based on params
        for i in range(params.MAX_PUZZLE_TRIES):
            idx_valid += make_puzzles(words, None)

            # reached target count of puzzles, exiting loop
            if idx_valid >= params.PUZZLE_COUNT:
                exit(0)

    return puzzle_input
Beispiel #6
0
def populate(g):
	directions = ('n','s','e','w')
	moves = ('l', 'r', 'm')
	rovers = []
	coordinates = None
	sequence = None
	cont = '1'
	while(cont!='0'):
		while(True):
			location = input('Please give the X and Y coordinates of the rover, as well as the cardinal direction (single letter) the rover is facing "X Y D": ')
			try:
				coordinates = location.split()
				if (len(coordinates)<3):
					raise ValueTooSmallError
				elif (len(coordinates)>3):
					raise ValueTooLargeError
				elif(int(coordinates[0])<0 or int(coordinates[1])<0):
					raise ValueError
				elif(coordinates[2].lower() not in directions):
					raise AlphaError
				break

			except ValueTooSmallError:
				print('\nYou entered too few arguments, please give both an X and Y coordinate, and direction.')
			except ValueTooLargeError:
				print('\nYou entered too many arguments, please give only an X and Y coordinate, and direction.')
			except ValueError as e:
				print("\nThe coordinates you entered were not non negative integers. Please make sure that your X and Y arguments are both non negative integers.")
			except NumericError:
				print("\nThe direction you entered was not N, S, E, or W. Please make sure it is a direction")

		while(True):
			sequence = input('Please give the sequence of moves you would like to give the rover in a 1 string sequence (eg. "LMMRRM"): ')
			if(check_letters(sequence)):
				break
			print("Invalid sequence, your sequence must contain only the letters 'L', 'R', and 'M'\n")
		rovers.append(Rover(coordinates[0],coordinates[1],coordinates[2], sequence, g))
		cont = input('Rover added. Enter 0 if you have no more rovers, enter anything else to add another: ')
	return rovers