Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: SChem build and test
on:
push:
workflow_dispatch:
pull_request:

jobs:
run:
runs-on: windows-latest

steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: '3.x'
- run: pip install -r requirements.txt
- run: python -m unittest discover -s tests
timeout-minutes: 120
env:
PYTHONIOENCODING: UTF-8
48 changes: 48 additions & 0 deletions tools/derandomize.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
from pathlib import Path
import sys

# Insert the parent directory to sys path so schem is accessible even if it's not available system-wide
sys.path.insert(1, str(Path(__file__).parent.parent))

from schem.components import RandomInput
from schem.schem_random import SChemRandom

# Not all random sequences start from seed 0; use this tool to figure out what seed the random is using.
# In this case, the sequence is: Number of uranium atoms in the random inputs of "No Need for Introductions"
expected_sequence = [
1, 0, 0, 2, 2,
1, 1, 2, 0, 0,
1, 2, 2, 0, 1,
]

candidate_seeds = []
for seed in range(1000):
random_generator = SChemRandom(seed=seed)
random_bucket = []

for i, expected in enumerate(expected_sequence):
if not random_bucket:
random_bucket = [0] * 2 + [1] * 2 + [2] * 2

if random_bucket.pop(random_generator.next(len(random_bucket))) != expected:
break

if i == len(expected_sequence) - 1:
candidate_seeds.append(seed)


print(f'Found {len(candidate_seeds)} candidate seeds:')
for seed in candidate_seeds:
print(f'Seed {seed} predicts the following outputs after the expected sequence:')

random_generator = SChemRandom(seed=seed)
random_bucket = []

for i in range(len(expected_sequence) + 10):
if not random_bucket:
random_bucket = [0] * 2 + [1] * 2 + [2] * 2

actual = random_bucket.pop(random_generator.next(len(random_bucket)))

if i > len(expected_sequence) - 1:
print(actual, end = ', ')
83 changes: 83 additions & 0 deletions tools/level_builder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
from pathlib import Path
import sys

# Insert the parent directory to sys path so schem is accessible even if it's not available system-wide
sys.path.insert(1, str(Path(__file__).parent.parent))

from schem.level import Level, DefenseLevel
from schem.levels import levels
from pprint import PrettyPrinter
import json

# Dump all existing levels (for reference purposes)
with open('out.txt', 'w', encoding='utf-8') as f:
pp = PrettyPrinter(indent=2, stream=f)
for name, level in levels.items():
pp.pprint(name)
try:
l = Level(level)
pp.pprint(l.dict)
except:
pass

# Here are a couple of defence levels to get you started
l = DefenseLevel(None)
l.dict = {
'name': 'A Most Unfortunate Malfunction',
'author': 'Zach',
'type': 'defense',
'boss': 'Isambard MMD',
'max-reactors': 3,
'control-switches-allowed': True,
'has-starter': True,
'has-storage': True,
'fixed-input-zones': {'0': 'Methane;CH~04;01110;10101;21100;12100;11611'},
'other-components': [{
'molecules': [{'count': 36, 'molecule': 'Methane;CH~04;01110;10101;21100;12100;11611'}],
'type': 'drag-weapon-oxygentank',
'x': 12,
'y': 12,
}, {
'molecules': [{'count': 36, 'molecule': 'Methane;CH~04;01110;10101;21100;12100;11611'}],
'type': 'drag-weapon-oxygentank',
'x': 18,
'y': 12,
}, {
'molecules': [{'count': 36, 'molecule': 'Methane;CH~04;01110;10101;21100;12100;11611'}],
'type': 'drag-weapon-oxygentank',
'x': 24,
'y': 12,
}],
}
print(l.code)


l = DefenseLevel(None)
l.dict = {
'name': 'No Need for Introductions',
'author': 'Zach',
'type': 'defense',
'boss': 'Quororque',
'max-reactors': 4,
'control-switches-allowed': True,
'has-advanced': True,
'has-storage': True,
'other-components': [{
'molecules': [
{'count': 36, 'molecule': 'Methane;CH~04;01110;10101;21100;12100;11611'},
{'count': 36, 'molecule': 'Methane;CH~04;01110;10101;21100;12100;11611'}
],
'type': 'drag-weapon-particleaccelerator',
'x': 16,
'y': 11,
}],
'random-input-zones': {'0': {
'inputs': [
{'count': 2, 'molecule': 'Water;H~02O;11110;22100;21801'},
{'count': 2, 'molecule': 'Tainted Water;UOH;21801;11110;229200'},
{'count': 2, 'molecule': 'Tainted Water;U~02O;21801;119210;229200'},
],
'random-seed': 19,
}},
}
print(l.code)