From ee26903b338a361435edbf0131d2ede88b999cb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gon=C3=A7alo=20S=2E=20Martins?= Date: Tue, 17 May 2016 20:54:03 +0100 Subject: [PATCH] First commit: add a first stub of the code. --- crossword_generator.py | 46 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100755 crossword_generator.py diff --git a/crossword_generator.py b/crossword_generator.py new file mode 100755 index 0000000..766d980 --- /dev/null +++ b/crossword_generator.py @@ -0,0 +1,46 @@ +#!/usr/bin/python3 +""" Crossword Generator + +This script takes a list of words and creates a new latex table representing a +crosswod puzzle, which is then printed to PDF, and can be printed to actual, +if you're one of those people. +""" + + +def read_word_list(filename): + """ This function reads the file and returns the words read. It expects a + file where each word is in a line. + """ + # Initialize words list + words = [] + + # Quick'n'dirty file reading + with open(filename) as words_file: + for line in words_file: + words.append(line.strip()) + + return words + +def generate_grid(words, dim): + """ This function receives a list of words and creates a new grid, which + represents our puzzle. The newly-created grid is of dimensions + dim[0] * dim[1] (rows * columns). + TODO: detail algorithm + """ + +def write_grid(grid, screen = False): + """ This function receives the generated grid and writes it to the file (or + to the screen, if that's what we want). The grid is expected to be a list + of lists. + """ + if screen is True: + # Print grid to the screen + print(grid) + else: + # Print grid to the file and compile + ... + +if __name__ == "__main__": + words = read_word_list("words.txt") + grid = generate_grid(words, [20,20]) + write_grid(grid)