From d8f2966755deb9561603d0767b559c5acc45e76d Mon Sep 17 00:00:00 2001 From: Xevion Date: Tue, 17 Sep 2019 00:38:16 -0500 Subject: [PATCH] snake game raw output portion --- .gitignore | 4 +++- uil/october-2013/3/input-generator/main.py | 15 ++++++++++---- .../3/input-generator/output/output.dat | 20 +++++++++++++++++++ 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 03baad0..31a1bab 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ +# Custom Files +uil/october-2013/3/input-generator/output/output.dat + # Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] @@ -122,4 +125,3 @@ dmypy.json # Pyre type checker .pyre/ - diff --git a/uil/october-2013/3/input-generator/main.py b/uil/october-2013/3/input-generator/main.py index 0eb30a5..9b09e59 100644 --- a/uil/october-2013/3/input-generator/main.py +++ b/uil/october-2013/3/input-generator/main.py @@ -1,4 +1,4 @@ -import math, time, random +import os, sys, math, time, random class Node(object): def __init__(self, parent=None, position=None): @@ -198,6 +198,9 @@ class SnakeGrid(object): def available(self, pos, look=' '): return (self.matrix[pos[0]][pos[1]] == look) if self.inBounds(pos) else False + def toRawString(self): + return '\n'.join(''.join(line) for line in self.matrix) + def __repr__(self): length = max([max(len(item) for item in sub) for sub in self.matrix]) return '\n'.join(' - '.join(map(lambda item : item.ljust(length) if item != ' ' else (' ' * length), line)) for line in self.matrix) @@ -215,23 +218,27 @@ if __name__ == "__main__": dividerTotal = (4 * size[0]) - centerSize dividerCustom = ('-' * (dividerTotal // 2)) + ' {} ' + ('-' * (dividerTotal // 2)) dividerTotal = '-' * (dividerTotal + 4) + path = os.path.join(sys.path[0], 'output', 'output.dat') + file = open(path, 'w+') t1 = time.time() # Build and prints matrixes for x in range(iterations): snakegrid = SnakeGrid(size[0], size[1], 3) - print(dividerCustom.format(str(x+1).zfill(len(str(iterations))))) + file.write(snakegrid.toRawString() + '\n') for position in snakegrid.pellets(): pelletCount, solution = snakegrid.solution(startpos=position) - print(f'{solution} - {pelletCount}') + if len(solution) >= 5 and pelletCount > 0: + file.write(solution + '\n') + print(f'{solution} - {pelletCount}') print(dividerTotal) print(snakegrid) - # snakegrid.sleep(timing) print(dividerTotal) # Finish and print timing statistics + file.close() t2 = time.time() print(f'Processing Time : {roundTime(t2 - t1 - snakegrid.sleepTime)}') print(f'Artificial Time : {roundTime(snakegrid.sleepTime)}') diff --git a/uil/october-2013/3/input-generator/output/output.dat b/uil/october-2013/3/input-generator/output/output.dat index e69de29..e27530e 100644 --- a/uil/october-2013/3/input-generator/output/output.dat +++ b/uil/october-2013/3/input-generator/output/output.dat @@ -0,0 +1,20 @@ + + F + F + + F + + + + + XXX + + + + F + F + +UUUUULL +UULULUL +UUUUUURUULL +DRDRDD