Skip to content

Commit 6997fcc

Browse files
committed
avoid hardcoding pzprxs URLs in cspuz_rs_puzzles
1 parent ad7bd84 commit 6997fcc

21 files changed

Lines changed: 77 additions & 107 deletions

cspuz_rs/src/serializer.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1767,13 +1767,44 @@ where
17671767
.map(|body| prefix + puzzle_kind + "/" + &body)
17681768
}
17691769

1770+
pub fn problem_to_url_with_context_pzprxs<T, C>(
1771+
combinator: C,
1772+
puzzle_kind: &str,
1773+
problem: T,
1774+
ctx: &Context,
1775+
) -> Option<String>
1776+
where
1777+
C: Combinator<T>,
1778+
{
1779+
problem_to_url_with_context_and_site(
1780+
combinator,
1781+
puzzle_kind,
1782+
"https://pzprxs.vercel.app/p?",
1783+
problem,
1784+
ctx,
1785+
)
1786+
}
1787+
17701788
pub fn problem_to_url<T, C>(combinator: C, puzzle_kind: &str, problem: T) -> Option<String>
17711789
where
17721790
C: Combinator<T>,
17731791
{
17741792
problem_to_url_with_context(combinator, puzzle_kind, problem, &Context::new())
17751793
}
17761794

1795+
pub fn problem_to_url_pzprxs<T, C>(combinator: C, puzzle_kind: &str, problem: T) -> Option<String>
1796+
where
1797+
C: Combinator<T>,
1798+
{
1799+
problem_to_url_with_context_and_site(
1800+
combinator,
1801+
puzzle_kind,
1802+
"https://pzprxs.vercel.app/p?",
1803+
problem,
1804+
&Context::new(),
1805+
)
1806+
}
1807+
17771808
pub fn url_to_puzzle_kind(serialized: &str) -> Option<String> {
17781809
let serialized = serialized
17791810
.strip_prefix("http://")

cspuz_rs_puzzles/src/puzzles/archipelago.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use crate::util;
22
use cspuz_rs::graph;
33
use cspuz_rs::serializer::{
4-
problem_to_url_with_context_and_site, url_to_problem, Choice, Combinator, Context, Dict, Grid,
5-
HexInt, Optionalize, Spaces,
4+
problem_to_url_pzprxs, url_to_problem, Choice, Combinator, Dict, Grid, HexInt, Optionalize,
5+
Spaces,
66
};
77
use cspuz_rs::solver::{Solver, TRUE};
88
use std::collections::VecDeque;
@@ -344,15 +344,7 @@ fn combinator() -> impl Combinator<Problem> {
344344
}
345345

346346
pub fn serialize_problem(problem: &Problem) -> Option<String> {
347-
let height = problem.len();
348-
let width = problem[0].len();
349-
problem_to_url_with_context_and_site(
350-
combinator(),
351-
"archipelago",
352-
"https://pzprxs.vercel.app/p?",
353-
problem.clone(),
354-
&Context::sized(height, width),
355-
)
347+
problem_to_url_pzprxs(combinator(), "archipelago", problem.clone())
356348
}
357349

358350
pub fn deserialize_problem(url: &str) -> Option<Problem> {

cspuz_rs_puzzles/src/puzzles/balloon.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::util;
22
use cspuz_rs::graph;
33
use cspuz_rs::serializer::{
4-
problem_to_url_with_context_and_site, url_to_problem, Choice, Combinator, Context,
4+
problem_to_url_with_context_pzprxs, url_to_problem, Choice, Combinator, Context,
55
ContextBasedGrid, Dict, HexInt, MultiDigit, Optionalize, PrefixAndSuffix, Size, Spaces, Tuple2,
66
};
77
use cspuz_rs::solver::{count_true, IntVarArray1D, Solver};
@@ -189,10 +189,9 @@ fn combinator() -> impl Combinator<Problem> {
189189

190190
pub fn serialize_problem(problem: &Problem) -> Option<String> {
191191
let (h, w) = util::infer_shape(&problem.0);
192-
problem_to_url_with_context_and_site(
192+
problem_to_url_with_context_pzprxs(
193193
combinator(),
194194
"balloon",
195-
"https://pzprxs.vercel.app/p?",
196195
problem.clone(),
197196
&Context::sized(h, w),
198197
)

cspuz_rs_puzzles/src/puzzles/city_space.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use crate::util;
22
use cspuz_rs::graph;
33
use cspuz_rs::serializer::{
4-
problem_to_url_with_context_and_site, url_to_problem, Choice, Combinator, Context, Dict, Grid,
5-
HexInt, Optionalize, Spaces,
4+
problem_to_url_pzprxs, url_to_problem, Choice, Combinator, Dict, Grid, HexInt, Optionalize,
5+
Spaces,
66
};
77
use cspuz_rs::solver::{Solver, FALSE, TRUE};
88

@@ -82,15 +82,7 @@ fn combinator() -> impl Combinator<Problem> {
8282
}
8383

8484
pub fn serialize_problem(problem: &Problem) -> Option<String> {
85-
let height = problem.len();
86-
let width = problem[0].len();
87-
problem_to_url_with_context_and_site(
88-
combinator(),
89-
"cityspace",
90-
"https://pzprxs.vercel.app/p?",
91-
problem.clone(),
92-
&Context::sized(height, width),
93-
)
85+
problem_to_url_pzprxs(combinator(), "cityspace", problem.clone())
9486
}
9587

9688
pub fn deserialize_problem(url: &str) -> Option<Problem> {

cspuz_rs_puzzles/src/puzzles/coral.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use cspuz_rs::graph;
22
use cspuz_rs::serializer::{
3-
problem_to_url_with_context_and_site, url_to_problem, Combinator, Context, HexInt,
3+
problem_to_url_with_context_pzprxs, url_to_problem, Combinator, Context, HexInt,
44
OutsideSequences, Size,
55
};
66
use cspuz_rs::solver::{any, count_true, BoolVarArray1D, Solver, TRUE};
@@ -81,10 +81,9 @@ fn combinator() -> impl Combinator<Problem> {
8181
pub fn serialize_problem(problem: &Problem) -> Option<String> {
8282
let height = problem.1.len();
8383
let width = problem.0.len();
84-
problem_to_url_with_context_and_site(
84+
problem_to_url_with_context_pzprxs(
8585
combinator(),
8686
"coral",
87-
"https://pzprxs.vercel.app/p?",
8887
problem.clone(),
8988
&Context::sized(height, width),
9089
)

cspuz_rs_puzzles/src/puzzles/energywalk.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::puzzles::walk_common::{merge_walk_answers, walk_not_passing_colored_c
22
use crate::util;
33
use cspuz_rs::graph;
44
use cspuz_rs::serializer::{
5-
problem_to_url_with_context_and_site, url_to_problem, Choice, Combinator, Context,
5+
problem_to_url_with_context_pzprxs, url_to_problem, Choice, Combinator, Context,
66
ContextBasedGrid, Dict, HexInt, Map, MultiDigit, Optionalize, Size, Spaces, Tuple2,
77
};
88
use cspuz_rs::solver::{count_true, BoolExpr, Solver};
@@ -171,10 +171,9 @@ fn combinator() -> impl Combinator<Problem> {
171171

172172
pub fn serialize_problem(problem: &Problem) -> Option<String> {
173173
let (h, w) = util::infer_shape(&problem.0);
174-
problem_to_url_with_context_and_site(
174+
problem_to_url_with_context_pzprxs(
175175
combinator(),
176176
"energywalk",
177-
"https://pzprxs.vercel.app/p?",
178177
problem.clone(),
179178
&Context::sized(h, w),
180179
)

cspuz_rs_puzzles/src/puzzles/firewalk.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::util;
33
use cspuz_rs::complex_constraints::walk_line_size;
44
use cspuz_rs::graph;
55
use cspuz_rs::serializer::{
6-
problem_to_url_with_context_and_site, url_to_problem, Choice, Combinator, Context,
6+
problem_to_url_with_context_pzprxs, url_to_problem, Choice, Combinator, Context,
77
ContextBasedGrid, HexInt, Map, MultiDigit, Optionalize, Size, Spaces, Tuple2,
88
};
99
use cspuz_rs::solver::{Solver, FALSE, TRUE};
@@ -204,10 +204,9 @@ fn combinator() -> impl Combinator<Problem> {
204204
pub fn serialize_problem(problem: &Problem) -> Option<String> {
205205
let height = problem.0.len();
206206
let width = problem.0[0].len();
207-
problem_to_url_with_context_and_site(
207+
problem_to_url_with_context_pzprxs(
208208
combinator(),
209209
"firewalk",
210-
"https://pzprxs.vercel.app/p?",
211210
problem.clone(),
212211
&Context::sized(height, width),
213212
)

cspuz_rs_puzzles/src/puzzles/forestwalk.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::util;
33
use cspuz_rs::complex_constraints::walk_line_size;
44
use cspuz_rs::graph;
55
use cspuz_rs::serializer::{
6-
problem_to_url_with_context_and_site, url_to_problem, Choice, Combinator, Context,
6+
problem_to_url_with_context_pzprxs, url_to_problem, Choice, Combinator, Context,
77
ContextBasedGrid, Dict, HexInt, Map, MultiDigit, Optionalize, Size, Spaces, Tuple2,
88
};
99
use cspuz_rs::solver::Solver;
@@ -81,10 +81,9 @@ fn combinator() -> impl Combinator<Problem> {
8181

8282
pub fn serialize_problem(problem: &Problem) -> Option<String> {
8383
let (h, w) = util::infer_shape(&problem.0);
84-
problem_to_url_with_context_and_site(
84+
problem_to_url_with_context_pzprxs(
8585
combinator(),
8686
"forestwalk",
87-
"https://pzprxs.vercel.app/p?",
8887
problem.clone(),
8988
&Context::sized(h, w),
9089
)

cspuz_rs_puzzles/src/puzzles/japanese_sums.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use cspuz_rs::complex_constraints::japanese;
22
use cspuz_rs::serializer::{
3-
problem_to_url_with_context_and_site, url_to_problem, Choice, Combinator, Context,
3+
problem_to_url_with_context_pzprxs, url_to_problem, Choice, Combinator, Context,
44
ContextBasedGrid, DecInt, Dict, HexInt, Optionalize, OutsideSequences, PrefixAndSuffix, Size,
55
Spaces, Tuple3,
66
};
@@ -82,10 +82,9 @@ fn combinator() -> impl Combinator<Problem> {
8282
pub fn serialize_problem(problem: &Problem) -> Option<String> {
8383
let height = problem.1 .1.len();
8484
let width = problem.1 .0.len();
85-
problem_to_url_with_context_and_site(
85+
problem_to_url_with_context_pzprxs(
8686
combinator(),
8787
"japanesesums",
88-
"https://pzprxs.vercel.app/p?",
8988
problem.clone(),
9089
&Context::sized(height, width),
9190
)

cspuz_rs_puzzles/src/puzzles/keywest.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
use crate::util;
22
use cspuz_rs::graph;
33
use cspuz_rs::serializer::{
4-
problem_to_url_with_context_and_site, url_to_problem, Choice, Combinator, Context, Dict, Grid,
5-
NumSpaces, Spaces,
4+
problem_to_url_pzprxs, url_to_problem, Choice, Combinator, Dict, Grid, NumSpaces, Spaces,
65
};
76
use cspuz_rs::solver::Solver;
87

@@ -61,14 +60,7 @@ fn combinator() -> impl Combinator<Problem> {
6160
}
6261

6362
pub fn serialize_problem(problem: &Problem) -> Option<String> {
64-
let (h, w) = util::infer_shape(&problem);
65-
problem_to_url_with_context_and_site(
66-
combinator(),
67-
"keywest",
68-
"https://pzprxs.vercel.app/p?",
69-
problem.clone(),
70-
&Context::sized(h, w),
71-
)
63+
problem_to_url_pzprxs(combinator(), "keywest", problem.clone())
7264
}
7365

7466
pub fn deserialize_problem(url: &str) -> Option<Problem> {

0 commit comments

Comments
 (0)