From 5e6514449e232d30f318f4f84c3b843aec2f43d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gon=C3=A7alo=20S=2E=20Martins?= Date: Tue, 17 May 2016 23:53:27 +0100 Subject: [PATCH] Black cells are now produced as such. --- crossword_generator.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/crossword_generator.py b/crossword_generator.py index 2a0049e..f3e7f33 100755 --- a/crossword_generator.py +++ b/crossword_generator.py @@ -129,8 +129,8 @@ def generate_grid(words, dim): This function operates by taking the words it receives and generating an expanded dictionary with all possible locations and directions of each word. It then adds words at random and, for each word added, removes all - possibilities that are now invalid. This is done until the grid is complete - or there are no more possibilities. + possibilities that are now invalid. This is done until the grid is above a + certain completion level. Each possibility is a dictionary of the kind: p["word"] = the actual string @@ -202,6 +202,7 @@ def write_grid(grid, screen=False, out_file="table.tex"): # Write preamble texfile.write("\documentclass{article}" + "\n") texfile.write(r"\usepackage[utf8]{inputenc}" + "\n") + texfile.write(r"\usepackage[table]{xcolor}" + "\n") texfile.write("\n") texfile.write(r"\begin{document}" + "\n") @@ -209,18 +210,21 @@ def write_grid(grid, screen=False, out_file="table.tex"): texfile.write(r"\begin{tabular}{|") for i in range(len(grid[0])): texfile.write(r"c|") - texfile.write("}\n") + texfile.write("}\n\hline\n") # Write actual table for line in grid: for index, element in enumerate(line): - # This feels a bit hacky, suggestions appreciated - if index == len(line)-1: - texfile.write(str(element)) + if element == 0: + texfile.write(r"\cellcolor{black}0") else: - texfile.write(str(element) + " & ") + texfile.write(str(element)) + # This feels a bit hacky, suggestions appreciated + if index != len(line)-1: + texfile.write(" & ") - texfile.write(r"\\" + "\n") + + texfile.write(r"\\ \hline" + "\n") # End environments texfile.write("\end{tabular}\n")