Skip to content
Merged
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
16 changes: 8 additions & 8 deletions SHA256SUMS
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
effebd70742b26c7000ead248418c3d560d93062ccfe1ff68ef5e456a2a4da77 cpp/frontier_iii14_iii20_prover.cpp
307e856631aad36762d7cceb6255e3314185ed33aa3700a63fb93bee10f4c872 cpp/soko_engine.cpp
4da54c90582c69327f29105b426df475dd613668486e5bdfabc3c697835aa699 cpp/soko_engine.cpp
78f661f4f89d8cd4a28364a4386742420837367f7f752f8f514273be6e939b24 soko_mcp/__init__.py
1e27da781dc8bd819a0653df324608a15c919e4b21f5042a7814a3f33eae8848 soko_mcp/__main__.py
4c7660e4c53f7b47c4b36fe2334dc52e46e01679b7a5e77ba43c562162642e1e soko_mcp/analyzer.py
43d8b8aaf29c3e9fb857ea803a40edf5cc6e230e8e81e2c8eb002d41364f75ed soko_mcp/catalog.py
336da844367ed6808c60cbb2b7f9af065f728f04cb168d8efd13ffe6770b3328 soko_mcp/checker_auditor.py
24fdc7a595cae79cc48ca059980c36aec95be916817fb4380e650331540b4259 soko_mcp/checker_auditor.py
c8c5b01f4e6ad49c6586439082778d3f806c6891d07d1a76912c261533c247ac soko_mcp/data/catalog.json
22d12d869a96f59fb21f0e03cbb378570feddb36e4c9d523a3ff7c265c26b82e soko_mcp/engine_bridge.py
2bad704a7d39ee3a63505918e5917a097a0ba6da27a3e6b0bf246edc9dc76d7c soko_mcp/evidence.py
447b6c006dfe36347a96bd519b5ff23b76ed40352c0e5ccb32d42f496f402951 soko_mcp/flat_oracle.py
c84eef014119ff2e0c1ba815c3c696700fff82713981edd78eabcde9d017b450 soko_mcp/engine_bridge.py
84797aa46359316ecf75c48483865ceeee21441a690ef3896000ee76da115ab3 soko_mcp/evidence.py
9e8540bfda9cb467bc842711296948172bca50ea35a70b8387d7e7de2ad110e7 soko_mcp/flat_oracle.py
0a3557fa10865270258570aed9f310a4860870a4469e583d61bb3693a3234e49 soko_mcp/formal_kernel.py
b3ab54723b90072e92fd91affe560b2a07c957f42b3137ed3870478be200f2b2 soko_mcp/integrity.py
6adb9f952fd12f0385444be24f4ba45b3470873168fc43663f37026177c92d40 soko_mcp/invariant_synth.py
660cf96934654d3ab95f83ab7ef3bae4900771bf4159166ec870104c69c9f828 soko_mcp/lean4_auditor.py
8145f311051a3f6bfa94467da7a6d9a30535f9edf1bb00662982da70e9cc9853 soko_mcp/oracle.py
e9b288556c51363e1edbb161c2c119c540ad8aa6e5ae31e23739a6284f2800a6 soko_mcp/original.py
fe92ee760e3282c941641bebb47f7b19adfc2011279f1c0fde10f926ed14e99a soko_mcp/play.py
e8602e188cbcd8bffc997fe2d38404f4f7646d2259b4fc06aad28cde9490f0ca soko_mcp/server.py
01c6dc6046cca9771b64b6a51ac980f589e6623beb53e64ad99561c619416776 tracks/iii-14/verify.py
e2e855c4501c479db8f3c2f34f9e2f858099d8d99a6a3a79a3dd12187ba4ecf3 tracks/iii-20/verify.py
e37d920de311e77208627487ac01c9fda674241488d7ad862a9856150f48e228 soko_mcp/server.py
201bd6a5026cc666ba9faa09f276cad6d08cfef798fdbbd8ffaa7ca7dc6bfa69 tracks/iii-14/verify.py
e4c7451233f2e018d6489fc2c226ac951a9e5835e5c3611384bca7800d72174b tracks/iii-20/verify.py
63 changes: 48 additions & 15 deletions cpp/soko_engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,31 @@
* - Collision-safe bucket chaining in `exact_window_shortcut`.
*/

#include <bits/stdc++.h>
#include <algorithm>
#include <array>
#include <atomic>
#include <chrono>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <mutex>
#include <numeric>
#include <queue>
#include <sstream>
#include <string>
#include <thread>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;

static constexpr int MAX_CELLS = 512;
static constexpr uint8_t OBJ_CORPSE = 21;
static const int DX[4] = {0, 0, -1, 1};
static const int DY[4] = {-1, 1, 0, 0};
static const char DCH[5] = {'U', 'D', 'L', 'R', 'A'};
Expand Down Expand Up @@ -145,6 +166,7 @@ bool run_late(const LevelMeta& M, DynState& s) {
}
}
}
bool corpse = false;
if (M.part >= 2) {
for (int y = 0; y < M.h; ++y)
for (int x = 0; x < M.w; ++x)
Expand All @@ -169,7 +191,7 @@ bool run_late(const LevelMeta& M, DynState& s) {
for (int i = 0; i < M.n; ++i) {
if (dying[i]) {
if (is_monster(M.part, s.obj[i])) s.obj[i] = 0;
else if (is_hero(s.obj[i])) return true;
else if (is_hero(s.obj[i])) { s.obj[i] = OBJ_CORPSE; corpse = true; }
}
}
}
Expand All @@ -181,7 +203,7 @@ bool run_late(const LevelMeta& M, DynState& s) {
for (int idx : M.y_doors_init) if (s.obj[idx] == 18) s.obj[idx] = 0;
} else if (any_u && s.y_open) {
s.y_open = 0;
for (int idx : M.y_doors_init) { if (is_hero(s.obj[idx])) return true; s.obj[idx] = 18; }
for (int idx : M.y_doors_init) { if (is_hero(s.obj[idx])) corpse = true; s.obj[idx] = 18; }
}
}
if (!M.p_switches.empty()) {
Expand All @@ -192,7 +214,7 @@ bool run_late(const LevelMeta& M, DynState& s) {
for (int idx : M.p_doors_init) if (s.obj[idx] == 19) s.obj[idx] = 0;
} else if (any_u && s.p_open) {
s.p_open = 0;
for (int idx : M.p_doors_init) { if (is_hero(s.obj[idx])) return true; s.obj[idx] = 19; }
for (int idx : M.p_doors_init) { if (is_hero(s.obj[idx])) corpse = true; s.obj[idx] = 19; }
}
}
// The monster gate opens after the door phase: a closing colored door may
Expand All @@ -205,7 +227,7 @@ bool run_late(const LevelMeta& M, DynState& s) {
if (M.has_bard) {
for (int i = 0; i < M.n; ++i) if (s.has_note(i) && !is_moveable(M.part, s.obj[i])) s.notes[i >> 6] &= ~(1ULL << (i & 63));
}
return false;
return corpse;
}

inline bool check_win(const LevelMeta& M, const DynState& s) {
Expand Down Expand Up @@ -535,6 +557,7 @@ string render_ascii(const LevelMeta& M, const DynState& s) {
else if (o == 15) ch = 'O'; else if (o == 16) ch = 'L';
else if (o == 17) ch = 'R'; else if (o == 18) ch = '[';
else if (o == 19) ch = ']'; else if (o == 20) ch = 'M';
else if (o == OBJ_CORPSE) ch = 'X';
else if (M.floor_grid[i] == 1) ch = 'G';
else if (M.floor_grid[i] == 2) ch = '{';
else if (M.floor_grid[i] == 3) ch = '}';
Expand Down Expand Up @@ -590,7 +613,8 @@ inline int compact_bucket16(const LevelMeta& M, const DynState& s) {
}

string tube_beam_refine(const LevelMeta& M, const DynState& start, const vector<DynState>& target,
int max_d, int beam_w, int cap_bkt, bool role_agnostic, double budget_s) {
int max_d, int beam_w, int cap_bkt, bool role_agnostic, double budget_s,
size_t max_states = 13000000, uint64_t* states_accum = nullptr) {
auto t0 = chrono::steady_clock::now();
int N = (int)target.size() - 1;
auto norm_v = [&](uint8_t v) -> uint8_t {
Expand All @@ -612,7 +636,7 @@ string tube_beam_refine(const LevelMeta& M, const DynState& start, const vector<
string best_win;

for (int d = 1; d <= max_d; ++d) {
if (chrono::duration<double>(chrono::steady_clock::now() - t0).count() > budget_s || seen.cnt > 13000000) break;
if ((budget_s > 0.0 && chrono::duration<double>(chrono::steady_clock::now() - t0).count() > budget_s) || seen.cnt > max_states) break;
vector<DynState> c_states;
vector<PRec> c_precs;
vector<int> c_bkt;
Expand Down Expand Up @@ -676,6 +700,7 @@ string tube_beam_refine(const LevelMeta& M, const DynState& start, const vector<
}
cur.swap(nxt);
}
if (states_accum) *states_accum += seen.cnt;
return best_win;
}

Expand Down Expand Up @@ -1354,14 +1379,18 @@ int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);

string header_line;
if (!getline(cin, header_line)) return 1;
istringstream hs(header_line);
string mode;
int part, w, h, p1, p2, p3;
if (!(cin >> mode >> part >> w >> h >> p1 >> p2 >> p3)) return 1;
long long p4 = 0;
if (!(hs >> mode >> part >> w >> h >> p1 >> p2 >> p3)) return 1;
hs >> p4;
if (w * h > MAX_CELLS) {
cout << "{\"error\":\"grid exceeds MAX_CELLS (512)\"}\n";
return 1;
}
string dummy; getline(cin, dummy);
vector<string> rows(h);
for (int y = 0; y < h; ++y) getline(cin, rows[y]);
string seed_route;
Expand Down Expand Up @@ -1433,13 +1462,15 @@ int main() {
int beam_w = max(2000, p1);
int win_len = max(8, p2);
double total_budget = max(0.0, (double)p3);
size_t stage_state_cap = p4 > 0 ? (size_t)p4 : (size_t)13000000;
string best = seed_route;
vector<string> log_entries;
uint64_t opt_states_seen = 0;
auto opt_t0 = chrono::steady_clock::now();
if (total_budget <= 0.0) {
if (total_budget <= 0.0 && p4 <= 0) {
cout << "{\"initial_len\":" << seed_route.size() << ",\"best_len\":" << seed_route.size()
<< ",\"improved\":false,\"best_route\":\"" << seed_route << "\",\"stages\":[]"
<< ",\"timed_out\":true}\n";
<< ",\"states_seen\":0,\"timed_out\":true}\n";
return 0;
}

Expand All @@ -1464,15 +1495,15 @@ int main() {
vector<pair<int, int>> axes;
for (int sm : {1, 2, 3}) axes.push_back({sym_diff(sm), sm});
sort(axes.begin(), axes.end());
double per_stage = total_budget / 2.2;
double per_stage = total_budget > 0.0 ? (total_budget / 2.2) : 0.0;

if (axes[0].first <= M.n / 5) {
int best_sym = axes[0].second;
vector<DynState> mir_traj;
DynState cur = s0;
mir_traj.push_back(transform_state(M, cur, best_sym));
for (char c : best) { step_state(M, cur, d_idx(c), false); mir_traj.push_back(transform_state(M, cur, best_sym)); }
string m_hit = tube_beam_refine(M, s0, mir_traj, (int)best.size() - 1, beam_w, 240, true, per_stage);
string m_hit = tube_beam_refine(M, s0, mir_traj, (int)best.size() - 1, beam_w, 240, true, per_stage, stage_state_cap, &opt_states_seen);
if (!m_hit.empty() && m_hit.size() < best.size()) {
log_entries.push_back("chiral_sym_" + to_string(best_sym) + ":" + to_string(best.size()) + "->" + to_string(m_hit.size()));
best = m_hit;
Expand All @@ -1482,7 +1513,7 @@ int main() {
for (int iter = 0; iter < 2; ++iter) {
vector<DynState> ref_traj = {s0};
for (char c : best) { DynState nx = ref_traj.back(); step_state(M, nx, d_idx(c), false); ref_traj.push_back(nx); }
string r_hit = tube_beam_refine(M, s0, ref_traj, (int)best.size() - 1, max(32000, (beam_w * 4) / 5), 240, true, per_stage);
string r_hit = tube_beam_refine(M, s0, ref_traj, (int)best.size() - 1, max(32000, (beam_w * 4) / 5), 240, true, per_stage, stage_state_cap, &opt_states_seen);
if (!r_hit.empty() && r_hit.size() < best.size()) {
log_entries.push_back("iter_tube_" + to_string(iter + 1) + ":" + to_string(best.size()) + "->" + to_string(r_hit.size()));
best = r_hit;
Expand All @@ -1500,12 +1531,14 @@ int main() {
if (i) log_str += ",";
log_str += "\"" + log_entries[i] + "\"";
}
bool timed_out_flag = (total_budget > 0.0) && (chrono::duration<double>(chrono::steady_clock::now() - opt_t0).count() > total_budget);
cout << "{\"initial_len\":" << seed_route.size()
<< ",\"best_len\":" << best.size()
<< ",\"improved\":" << (best.size() < seed_route.size() ? "true" : "false")
<< ",\"best_route\":\"" << best << "\""
<< ",\"stages\":[" << log_str << "]"
<< ",\"timed_out\":" << (chrono::duration<double>(chrono::steady_clock::now() - opt_t0).count() > total_budget ? "true" : "false")
<< ",\"states_seen\":" << opt_states_seen
<< ",\"timed_out\":" << (timed_out_flag ? "true" : "false")
<< "}\n";
return 0;
}
Expand Down
4 changes: 2 additions & 2 deletions soko_mcp/checker_auditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def audit_dual_checkers(
if impl_source is None or not impl_source.strip():
verdict = "PASS" if s_rep["clean"] else "FAIL"
return {
"epistemic_status": "VERIFIED" if verdict == "PASS" else "REJECTED_CHECKER_HAZARD",
"epistemic_status": "LINT_PASS" if verdict == "PASS" else "REJECTED_CHECKER_HAZARD",
"mode": "single_checker",
"verdict": verdict,
"spec_audit": s_rep,
Expand All @@ -203,7 +203,7 @@ def audit_dual_checkers(
distinct = s_skel != i_skel
verdict = "PASS" if (distinct and s_rep["clean"] and i_rep["clean"]) else "FAIL"
return {
"epistemic_status": "VERIFIED" if verdict == "PASS" else "REJECTED_CHECKER_HAZARD",
"epistemic_status": "LINT_PASS" if verdict == "PASS" else "REJECTED_CHECKER_HAZARD",
"mode": "dual_checker",
"verdict": verdict,
"distinct_alpha_skeleton": distinct,
Expand Down
Loading
Loading