Skip to content

Commit c9a528d

Browse files
tanjo3wooferzfg
andauthored
S7 update (#109)
* Update bot for S7 * Remove outdated dev build * Formatting fixes * Add s7 build * Remove mixed pools build --------- Co-authored-by: wooferzfg <spapushin@gmail.com>
1 parent cb513f9 commit c9a528d

11 files changed

+230
-372
lines changed

.flake8

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
[flake8]
2-
exclude = wwrando, wwrando-dev-tanjo3, wwrando-random-settings, wwrando-mixed-pools
2+
exclude = wwrando, wwrando-s7, wwrando-random-settings
33
max-line-length = 120
44
extend-ignore = E203, W503

.github/workflows/ci.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,7 @@ jobs:
6262
sudo rm -r tww-rando-bot || true
6363
git clone --recursive https://github.com/wooferzfg/tww-rando-bot.git
6464
echo "${{ secrets.WWRANDO_SEED_KEY }}" > tww-rando-bot/wwrando/keys/seed_key.py
65-
echo "${{ secrets.WWRANDO_MP_SEED_KEY }}" > tww-rando-bot/wwrando-mixed-pools/keys/seed_key.py
66-
echo "${{ secrets.WWRANDO_DEV_TANJO3_SEED_KEY }}" > tww-rando-bot/wwrando-dev-tanjo3/keys/seed_key.py
65+
echo "${{ secrets.WWRANDO_DEV_TANJO3_SEED_KEY }}" > tww-rando-bot/wwrando-s7/keys/seed_key.py
6766
echo "${{ secrets.WWRANDO_RS_SEED_KEY }}" > tww-rando-bot/wwrando-random-settings/keys/seed_key.py
6867
cd tww-rando-bot
6968
export GITHUB_TOKEN=${{ secrets.BOT_GITHUB_TOKEN }}

.gitmodules

+4-8
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,11 @@
22
path = wwrando
33
url = https://github.com/wooferzfg/wwrando.git
44
branch = no-ui-spoiler-log
5-
[submodule "wwrando-dev-tanjo3"]
6-
path = wwrando-dev-tanjo3
7-
url = https://github.com/wooferzfg/wwrando.git
8-
branch = dev-build-no-ui
5+
[submodule "wwrando-s7"]
6+
path = wwrando-s7
7+
url = https://github.com/tanjo3/wwrando.git
8+
branch = s7-tournament
99
[submodule "wwrando-random-settings"]
1010
path = wwrando-random-settings
1111
url = https://github.com/Aelire/wwrando.git
1212
branch = randobot-support-keep-gclib
13-
[submodule "wwrando-mixed-pools"]
14-
path = wwrando-mixed-pools
15-
url = https://github.com/wooferzfg/wwrando.git
16-
branch = mixed-pools

randobot/constants.py

+25-30
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,6 @@ class SeedType(Enum):
1818
("s3", "MS4xMC4wAEEAFwMEAAQAvhMM8AADAAAAAAGAIAAA"),
1919
])
2020

21-
RUNNER_AGREEMENTS = OrderedDict([
22-
("4drm", "4-Dungeon Race Mode"),
23-
("nosword", "No Starting Sword"),
24-
("der", "Randomized Dungeon Entrances"),
25-
("keys", "Key-Lunacy"),
26-
("tingle", "Tingle Chests"),
27-
("expen", "Expensive Purchases"),
28-
("subs", "Submarines"),
29-
("minis", "Minigames"),
30-
("combat", "Combat Secret Caves"),
31-
])
32-
3321
STANDARD_DEFAULT = ["s6"]
3422
STANDARD_PATH = "wwrando"
3523

@@ -57,28 +45,36 @@ class SeedType(Enum):
5745
DEFAULT_PLANNING_TIME = 60
5846
MINIMUM_PLANNING_TIME = 20
5947

60-
DEV_PERMALINKS = OrderedDict([
61-
("default", "eJwz1LPUMzSIT0ktY3BkYGdkZigwYXjAWMDAKMUABg0MJAAAZlcFog=="),
48+
S7_PERMALINKS = OrderedDict([
49+
("s7", "eJwz1DM00DOIt7RITrQwM2VwZLhrVMTF0czAwMDCAAUcIEKAgYGJg3GlykMQAyoRwuLAsmajv8G85QwMk/iB6jUB5s8MHw=="),
50+
("miniblins", "eJwz1DM00DOIt7RITrQwM2VwZPA1cGAgEvgwOLAIXfS3uMvOwDJJfwlDgxIAVbMJPQ=="),
51+
("mixed-pools", "eJwz1DM00DOIt7RITrQwM2VwZLi/IYGBSPDmgT/LkYv+BnPYGRgm8QMFFAG7egse"),
6252
])
53+
S7_DEFAULT = ["s7"]
6354

64-
DEV_DEFAULT = ["default"]
65-
DEV_PATH = "wwrando-dev-tanjo3"
66-
DEV_VERSION = "1.9.10_dev"
67-
DEV_DOWNLOAD = "https://github.com/tanjo3/wwrando/releases"
68-
69-
MP_PERMALINKS = OrderedDict([
70-
("miniblins", "MS4xMC4wXzVmMWJhZTYAQQBNMEBMAEAEEvETzn8AEEh+SAEAIw=="),
71-
("mixed-pools", "MS4xMC4wXzVmMWJhZTYAQQDfsGDs4E8ExPETjHsAAEg+AAAAIA=="),
55+
S7_SL_PERMALINKS = OrderedDict([
56+
("s7-sl", "eJwz1DM00DOIt7RITrQwM2VwZLhrVMTF0czAwMDCAAUcIEKAgYGJg3GlykMQAyoRwuLAsmajv8G85QwMk/iB6jkB5q8L/w=="),
57+
("miniblins-sl", "eJwz1DM00DOIt7RITrQwM2VwZPA1cGAgEvgwOLAIXfS3uMvOwDJJfwlDAxMAVZMJHQ=="),
58+
("mixed-pools-sl", "eJwz1DM00DOIt7RITrQwM2VwZLi/IYGBSPDmgT/LkYv+BnPYGRgm8QMFGAG7Wgr+"),
7259
])
73-
MP_DEFAULT = ["mixed-pools"]
60+
S7_SL_DEFAULT = ["s7-sl"]
7461

75-
MP_SL_PERMALINKS = OrderedDict([
76-
("mixed-pools-sl", "MS4xMC4wXzVmMWJhZTYAQQDfsGDs4E8ExPETjHsAAEg+AAAAAA=="),
62+
RUNNER_AGREEMENTS = OrderedDict([
63+
("4rbm", "4-Required Bosses Mode"),
64+
("nosword", "No Starting Sword"),
65+
("der", "Randomized Dungeon Entrances"),
66+
("ber", "Randomized Boss Entrances"),
67+
("keys", "Key-Lunacy"),
68+
("tingle", "Tingle Chests replacing Dungeon Secrets"),
69+
("expen", "Expensive Purchases"),
70+
("subs", "Submarines"),
71+
("minis", "Minigames"),
72+
("plats", "Lookout Platforms on Islet of Steel, Southern Fairy, and Seven-Star"),
7773
])
78-
MP_SL_DEFAULT = ["mixed-pools-sl"]
7974

80-
MP_PATH = "wwrando-mixed-pools"
81-
MP_DOWNLOAD = "https://github.com/wooferzfg/wwrando/releases/tag/mixed-pools-build"
75+
S7_PATH = "wwrando-s7"
76+
S7_DOWNLOAD = "https://github.com/tanjo3/wwrando/releases/tag/s7-v1"
77+
S7_TRACKER = "https://wooferzfg.me/tww-rando-tracker/s7-tournament"
8278

8379
RS_PATH = "wwrando-random-settings"
8480
RS_VERSION = "RS1.4.0-dev3"
@@ -87,8 +83,7 @@ class SeedType(Enum):
8783
RS_DEFAULT = ["random-settings"]
8884
RS_PERMALINKS = OrderedDict([
8985
("random-settings", "UlMxLjQuMC1kZXYzAEEAgQU="),
90-
]
91-
)
86+
])
9287

9388
BANNABLE_PRESETS = SPOILER_LOG_DEFAULT
9489

randobot/generator.py

+25-123
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,58 @@
1-
import base64
21
import enum
32
import os
43
import random
54
import re
65
import string
7-
import struct
86
from datetime import datetime
97

108
import shortuuid
119
from github import Auth, Github, InputFileContent
1210

1311

1412
class ArgFormat(enum.Enum):
15-
V110 = '-noui -seed={seed_name} -permalink={permalink}'
16-
V111 = '--noui --dry --seed={seed_name} --permalink={permalink}'
17-
RS14 = '--randobot --noui --dry --seed={seed_name} --permalink={permalink}'
13+
V110 = "-noui -seed={seed_name} -permalink={permalink}"
14+
V111 = "--noui --dry --seed={seed_name} --permalink={permalink}"
15+
VS7 = "--noui --dry --seed={seed_name} --permalink={permalink} --modifiers={modifiers}"
16+
RS14 = "--randobot --noui --dry --seed={seed_name} --permalink={permalink}"
1817

1918

2019
class Generator:
21-
def __init__(self, github_token):
20+
def __init__(self, github_token: str):
2221
self.github_token = github_token
2322

24-
def generate_seed(self, randomizer_path, permalink, username, generate_spoiler_log,
25-
args_format: ArgFormat = ArgFormat.V110):
26-
trimmed_name = re.sub(r'\W+', '', username)[:12]
23+
def generate_seed(
24+
self,
25+
randomizer_path: str,
26+
permalink: str,
27+
username: str,
28+
generate_spoiler_log: bool,
29+
modifiers: str = "",
30+
args_format: ArgFormat = ArgFormat.V110,
31+
) -> dict[str, str | None]:
32+
trimmed_name = re.sub(r"\W+", "", username)[:12]
2733
random_suffix = shortuuid.ShortUUID().random(length=10)
2834
seed_name = f"{trimmed_name}{random_suffix}"
2935
file_name = "".join(random.choice(string.digits) for _ in range(6))
3036

3137
os.system(
32-
f"/venv/{randomizer_path}/bin/python {randomizer_path}/wwrando.py " +
33-
args_format.value.format(seed_name=seed_name, permalink=permalink)
38+
f"/venv/{randomizer_path}/bin/python {randomizer_path}/wwrando.py "
39+
+ args_format.value.format(seed_name=seed_name, permalink=permalink, modifiers=modifiers)
3440
)
3541

3642
permalink_file_name = f"permalink_{seed_name}.txt"
37-
permalink_file = open(permalink_file_name, "r")
38-
permalink = permalink_file.read()
39-
permalink_file.close()
43+
with open(permalink_file_name, "r") as permalink_file:
44+
permalink = permalink_file.read()
4045
os.remove(permalink_file_name)
4146

4247
seed_hash_file_name = f"seed_hash_{seed_name}.txt"
43-
seed_hash_file = open(seed_hash_file_name, "r")
44-
seed_hash = seed_hash_file.read()
45-
seed_hash_file.close()
48+
with open(seed_hash_file_name, "r") as seed_hash_file:
49+
seed_hash = seed_hash_file.read()
4650
os.remove(seed_hash_file_name)
4751

4852
if generate_spoiler_log:
4953
spoiler_log_file_name = f"spoiler_log_{seed_name}.txt"
50-
spoiler_log_file = open(spoiler_log_file_name, "r")
51-
spoiler_log = spoiler_log_file.read()
52-
spoiler_log_file.close()
54+
with open(spoiler_log_file_name, "r") as spoiler_log_file:
55+
spoiler_log = spoiler_log_file.read()
5356
os.remove(spoiler_log_file_name)
5457

5558
timestamp = datetime.now().strftime("%Y-%m-%d-%H:%M:%S")
@@ -59,7 +62,7 @@ def generate_seed(self, randomizer_path, permalink, username, generate_spoiler_l
5962
gist = gh_auth_user.create_gist(
6063
public=False,
6164
files={f"spoiler_log_{timestamp}.txt": InputFileContent(spoiler_log)},
62-
description="The Wind Waker Randomizer Spoiler Log"
65+
description="The Wind Waker Randomizer Spoiler Log",
6366
)
6467
spoiler_log_url = gist.html_url
6568
else:
@@ -69,106 +72,5 @@ def generate_seed(self, randomizer_path, permalink, username, generate_spoiler_l
6972
"file_name": file_name,
7073
"permalink": permalink,
7174
"seed_hash": seed_hash,
72-
"spoiler_log_url": spoiler_log_url
75+
"spoiler_log_url": spoiler_log_url,
7376
}
74-
75-
@staticmethod
76-
def encode_permalink(version, seed, bit_array):
77-
# NOTE: This function only works with the official 1.10 version of the randomizer!
78-
79-
# Start the permalink with the version number and seed name
80-
permalink = b""
81-
permalink += version
82-
permalink += b"\0"
83-
permalink += seed
84-
permalink += b"\0"
85-
86-
# Unpack the bytes object as a bit array
87-
bit_array = bit_array[::-1]
88-
bytes_array = [bit_array[i : i + 8] for i in range(0, len(bit_array), 8)]
89-
for byte in bytes_array:
90-
byte = int("".join(byte[::-1]), 2)
91-
permalink += struct.pack(">B", byte)
92-
93-
return base64.b64encode(permalink).decode("ascii")
94-
95-
@staticmethod
96-
def decode_permalink(base64_encoded_permalink):
97-
# NOTE: This function only works with the official 1.10 version of the randomizer!
98-
99-
# Decode permalink into a bytes object
100-
permalink = base64.b64decode(base64_encoded_permalink)
101-
102-
# Split the permalink into the version, seed name, and option bits
103-
version, seed, options_bytes = permalink.split(b"\0", 2)
104-
105-
# Unpack the option bytes object as a bit array
106-
option_bytes = struct.unpack(f">{'B'*len(options_bytes)}", options_bytes)
107-
bit_array = []
108-
for byte in option_bytes:
109-
bit_array.extend(list(bin(byte)[2:].zfill(8))[::-1])
110-
bit_array = bit_array[::-1]
111-
112-
return version, seed, bit_array
113-
114-
@staticmethod
115-
def apply_ra_modifier(base_permalink, modifier):
116-
# NOTE: This function only works with the official 1.10 version of the randomizer!
117-
118-
# Convert the permalink to a bit array
119-
version, seed, bit_array = Generator.decode_permalink(base_permalink)
120-
121-
# Modify bit array depending on modifier
122-
match modifier:
123-
case "4drm":
124-
bit_array[87] = "0"
125-
bit_array[88] = "1"
126-
bit_array[89] = "1"
127-
case "nosword":
128-
bit_array[98] = "0"
129-
bit_array[99] = "1"
130-
case "der":
131-
bit_array[142] = "0"
132-
bit_array[143] = "0"
133-
bit_array[144] = "1"
134-
case "keys":
135-
bit_array[145] = "1"
136-
case "tingle":
137-
bit_array[149] = "1"
138-
case "expen":
139-
bit_array[151] = "1"
140-
case "subs":
141-
bit_array[156] = "1"
142-
case "minis":
143-
bit_array[160] = "1"
144-
case "combat":
145-
bit_array[164] = "1"
146-
147-
# Encode updated bit array back into a permalink
148-
updated_permalink = Generator.encode_permalink(version, seed, bit_array)
149-
150-
return updated_permalink
151-
152-
@staticmethod
153-
def update_hint_distribution_for_ra(base_permalink):
154-
# NOTE: This function only works with the official 1.10 version of the randomizer!
155-
156-
# Convert the permalink to a bit array
157-
version, seed, bit_array = Generator.decode_permalink(base_permalink)
158-
159-
# Set the number of location hints to 8
160-
bit_array[119] = "1"
161-
bit_array[120] = "0"
162-
bit_array[121] = "0"
163-
bit_array[122] = "0"
164-
165-
# Set the number of barren hints to 5
166-
bit_array[123] = "0"
167-
bit_array[124] = "1"
168-
bit_array[125] = "0"
169-
bit_array[126] = "1"
170-
171-
# Encode updated bit array back into a permalink
172-
updated_permalink = Generator.encode_permalink(version, seed, bit_array)
173-
174-
return updated_permalink

0 commit comments

Comments
 (0)