mirror of
https://github.com/Xevion/contest.git
synced 2025-12-06 19:14:38 -06:00
snake game raw output portion
This commit is contained in:
4
.gitignore
vendored
4
.gitignore
vendored
@@ -1,3 +1,6 @@
|
|||||||
|
# Custom Files
|
||||||
|
uil/october-2013/3/input-generator/output/output.dat
|
||||||
|
|
||||||
# Byte-compiled / optimized / DLL files
|
# Byte-compiled / optimized / DLL files
|
||||||
__pycache__/
|
__pycache__/
|
||||||
*.py[cod]
|
*.py[cod]
|
||||||
@@ -122,4 +125,3 @@ dmypy.json
|
|||||||
|
|
||||||
# Pyre type checker
|
# Pyre type checker
|
||||||
.pyre/
|
.pyre/
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import math, time, random
|
import os, sys, math, time, random
|
||||||
|
|
||||||
class Node(object):
|
class Node(object):
|
||||||
def __init__(self, parent=None, position=None):
|
def __init__(self, parent=None, position=None):
|
||||||
@@ -198,6 +198,9 @@ class SnakeGrid(object):
|
|||||||
def available(self, pos, look=' '):
|
def available(self, pos, look=' '):
|
||||||
return (self.matrix[pos[0]][pos[1]] == look) if self.inBounds(pos) else False
|
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):
|
def __repr__(self):
|
||||||
length = max([max(len(item) for item in sub) for sub in self.matrix])
|
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)
|
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
|
dividerTotal = (4 * size[0]) - centerSize
|
||||||
dividerCustom = ('-' * (dividerTotal // 2)) + ' {} ' + ('-' * (dividerTotal // 2))
|
dividerCustom = ('-' * (dividerTotal // 2)) + ' {} ' + ('-' * (dividerTotal // 2))
|
||||||
dividerTotal = '-' * (dividerTotal + 4)
|
dividerTotal = '-' * (dividerTotal + 4)
|
||||||
|
path = os.path.join(sys.path[0], 'output', 'output.dat')
|
||||||
|
file = open(path, 'w+')
|
||||||
t1 = time.time()
|
t1 = time.time()
|
||||||
|
|
||||||
# Build and prints matrixes
|
# Build and prints matrixes
|
||||||
for x in range(iterations):
|
for x in range(iterations):
|
||||||
snakegrid = SnakeGrid(size[0], size[1], 3)
|
snakegrid = SnakeGrid(size[0], size[1], 3)
|
||||||
|
|
||||||
print(dividerCustom.format(str(x+1).zfill(len(str(iterations)))))
|
print(dividerCustom.format(str(x+1).zfill(len(str(iterations)))))
|
||||||
|
file.write(snakegrid.toRawString() + '\n')
|
||||||
for position in snakegrid.pellets():
|
for position in snakegrid.pellets():
|
||||||
pelletCount, solution = snakegrid.solution(startpos=position)
|
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(dividerTotal)
|
||||||
print(snakegrid)
|
print(snakegrid)
|
||||||
|
|
||||||
# snakegrid.sleep(timing)
|
# snakegrid.sleep(timing)
|
||||||
print(dividerTotal)
|
print(dividerTotal)
|
||||||
|
|
||||||
# Finish and print timing statistics
|
# Finish and print timing statistics
|
||||||
|
file.close()
|
||||||
t2 = time.time()
|
t2 = time.time()
|
||||||
print(f'Processing Time : {roundTime(t2 - t1 - snakegrid.sleepTime)}')
|
print(f'Processing Time : {roundTime(t2 - t1 - snakegrid.sleepTime)}')
|
||||||
print(f'Artificial Time : {roundTime(snakegrid.sleepTime)}')
|
print(f'Artificial Time : {roundTime(snakegrid.sleepTime)}')
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
|
||||||
|
F
|
||||||
|
F
|
||||||
|
|
||||||
|
F
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
XXX
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
F
|
||||||
|
F
|
||||||
|
|
||||||
|
UUUUULL
|
||||||
|
UULULUL
|
||||||
|
UUUUUURUULL
|
||||||
|
DRDRDD
|
||||||
|
|||||||
Reference in New Issue
Block a user