forked from sushobhith/harbormaster
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
1014 lines (987 loc) · 51.4 KB
/
Copy pathindex.html
File metadata and controls
1014 lines (987 loc) · 51.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Harbormaster — Fair Catan Board Generator with Starting Settlements (Base + Seafarers, 3–6 Players)</title>
<meta name="description" content="Free Catan board generator that also deals fair starting settlements, roads, and ports for every player. Balanced base and Seafarers (Heading for New Shores) maps for 3–6 players, shareable links. No signup.">
<meta name="keywords" content="catan board generator, fair catan board, catan setup generator, catan randomizer, settlers of catan generator, balanced catan board, catan starting settlements, catan 5-6 player generator, catan map generator, catan seafarers board generator, seafarers map generator, heading for new shores setup, catan expansion board">
<link rel="canonical" href="https://harbormaster.vercel.app/">
<meta name="robots" content="index, follow, max-image-preview:large">
<meta name="google-site-verification" content="fVmXoXK8LKsyB5JT6KQIy_UPfsYqBhS21jA5Tu-6j4Q">
<meta name="author" content="Sushobhith Sharma">
<meta name="theme-color" content="#c94f38">
<link rel="icon" href="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'><text y='.9em' font-size='90'>⚓</text></svg>">
<meta property="og:type" content="website">
<meta property="og:site_name" content="Harbormaster">
<meta property="og:title" content="Harbormaster — Fair Catan Board Generator with Starting Settlements">
<meta property="og:description" content="Every generator gives you a board. This one deals fair starting settlements, roads, and ports for every player too. Base + Seafarers, 3–6 players, free.">
<meta property="og:url" content="https://harbormaster.vercel.app/">
<meta property="og:image" content="https://harbormaster.vercel.app/og-image.png">
<meta property="og:image:width" content="1200">
<meta property="og:image:height" content="630">
<meta property="og:image:alt" content="A balanced 6-player Catan board with per-player starting settlements and a fairness readout">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:title" content="Harbormaster — Fair Catan Board Generator with Starting Settlements">
<meta name="twitter:description" content="Every generator gives you a board. This one deals fair starting settlements, roads, and ports for every player too. Free, 3–6 players.">
<meta name="twitter:image" content="https://harbormaster.vercel.app/og-image.png">
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "WebApplication",
"name": "Harbormaster",
"alternateName": "Fair Catan Setup Generator",
"url": "https://harbormaster.vercel.app/",
"description": "Free Catan board generator that deals balanced boards plus fair starting settlements, roads, and ports for 3–6 players. Supports the base game and Seafarers (Heading for New Shores).",
"applicationCategory": "GameApplication",
"operatingSystem": "Any",
"browserRequirements": "Requires JavaScript",
"isAccessibleForFree": true,
"offers": { "@type": "Offer", "price": "0", "priceCurrency": "USD" },
"author": { "@type": "Person", "name": "Sushobhith Sharma" }
}
</script>
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "FAQPage",
"mainEntity": [
{ "@type": "Question", "name": "How is this different from other Catan board generators?",
"acceptedAnswer": { "@type": "Answer", "text": "Other generators balance the board. Harbormaster also deals each player two starting settlements, two roads, and a turn order, matched so the start-value gap between the best and worst player is at most 1-2 pips. Prefer drafting yourself? Board-only mode keeps the balanced board and leaves placement to the table." } },
{ "@type": "Question", "name": "Does it support Catan Seafarers?",
"acceptedAnswer": { "@type": "Answer", "text": "Yes. The Seafarers map generates the official Heading for New Shores scenario for 3-6 players: main island, small islands with gold fields, their two separate number-token sets, and harbors on the official scenario edges, all balanced the same way as the base game." } },
{ "@type": "Question", "name": "Can I share a generated board with my group?",
"acceptedAnswer": { "@type": "Answer", "text": "Every board has a seed in the URL. Copy the link and everyone who opens it sees the identical setup, including the starting settlements." } },
{ "@type": "Question", "name": "Is it free?",
"acceptedAnswer": { "@type": "Answer", "text": "Free, no signup, open source. It is a single HTML file that runs entirely in your browser." } }
]
}
</script>
<script defer src="/_vercel/insights/script.js"></script>
<style>
:root{
--bg:#eef2f0; --sea:#cfe0e2; --panel:#ffffff; --panel2:#f4f6f4;
--ink:#22303a; --muted:#5d6d76; --line:#d3dcda;
--accent:#c94f38; --token:#f6ecd4; --token-ink:#2c241c;
--good:#3e7a45; --warn:#b5852c;
--wood:#3e7a45; --brick:#b5643c; --wheat:#d9a83c; --sheep:#8fbf6a; --ore:#7d8494; --desert:#cdb98a;
--gold:#ecc94b; --seahex:#a8c8d8;
--shadow:0 1px 3px rgba(20,40,45,.12);
}
@media (prefers-color-scheme: dark){
:root{
--bg:#16232b; --sea:#0f1a20; --panel:#1e2e37; --panel2:#243541;
--ink:#e8e4d8; --muted:#93a4ab; --line:#31454f;
--token:#efe3c4; --token-ink:#2c241c;
--good:#7fbf85; --warn:#d9b25e;
--gold:#d9b83e; --seahex:#1d3a4a;
--shadow:0 1px 4px rgba(0,0,0,.4);
}
}
:root[data-theme="dark"]{
--bg:#16232b; --sea:#0f1a20; --panel:#1e2e37; --panel2:#243541;
--ink:#e8e4d8; --muted:#93a4ab; --line:#31454f;
--token:#efe3c4; --token-ink:#2c241c;
--good:#7fbf85; --warn:#d9b25e;
--gold:#d9b83e; --seahex:#1d3a4a;
--shadow:0 1px 4px rgba(0,0,0,.4);
}
:root[data-theme="light"]{
--bg:#eef2f0; --sea:#cfe0e2; --panel:#ffffff; --panel2:#f4f6f4;
--ink:#22303a; --muted:#5d6d76; --line:#d3dcda;
--token:#f6ecd4; --token-ink:#2c241c;
--good:#3e7a45; --warn:#b5852c;
--gold:#ecc94b; --seahex:#a8c8d8;
--shadow:0 1px 3px rgba(20,40,45,.12);
}
.sea-only{display:none}
body[data-map="sea"] span.sea-only,body[data-map="sea"] b.sea-only{display:inline}
body[data-map="sea"] li.sea-only{display:list-item}
body[data-map="sea"] ul.sea-only{display:flex}
body[data-map="sea"] .classic-only{display:none}
*{box-sizing:border-box}
body{margin:0;background:var(--bg);color:var(--ink);
font:15px/1.5 system-ui,-apple-system,"Segoe UI",sans-serif;}
.display{font-family:"Iowan Old Style","Palatino Nova",Palatino,Georgia,serif;}
header{display:flex;flex-wrap:wrap;align-items:baseline;gap:.35rem 1rem;
padding:1.1rem 1.4rem .4rem;}
header h1{margin:0;font-size:1.55rem;font-weight:600;letter-spacing:.01em}
header p{margin:0;color:var(--muted);font-size:.9rem}
.gh{margin-left:auto;display:inline-flex;align-items:center;gap:.4rem;
align-self:center;text-decoration:none;color:var(--ink);font-size:.85rem;
font-weight:600;border:1px solid var(--line);border-radius:8px;
padding:.38rem .7rem;background:var(--panel);box-shadow:var(--shadow)}
.gh:hover{border-color:var(--accent);color:var(--accent)}
.gh:focus-visible{outline:2px solid var(--accent);outline-offset:1px}
.toolbar{display:flex;flex-wrap:wrap;align-items:center;gap:.75rem;
padding:.6rem 1.4rem 1rem;}
.seg{display:flex;border:1px solid var(--line);border-radius:8px;overflow:hidden;background:var(--panel)}
.seg button{border:0;background:transparent;color:var(--muted);padding:.42rem .8rem;
font:inherit;font-weight:600;cursor:pointer}
.seg button[aria-pressed="true"]{background:var(--ink);color:var(--bg)}
.seg button:focus-visible,.btn:focus-visible{outline:2px solid var(--accent);outline-offset:1px}
.btn{border:1px solid var(--line);background:var(--panel);color:var(--ink);
padding:.42rem .9rem;border-radius:8px;font:inherit;font-weight:600;cursor:pointer;box-shadow:var(--shadow)}
.btn.primary{background:var(--accent);border-color:var(--accent);color:#fff}
.btn[aria-pressed="true"]{background:var(--ink);border-color:var(--ink);color:var(--bg)}
.btn:active{transform:translateY(1px)}
.seedbox{margin-left:auto;color:var(--muted);font-size:.8rem;
font-family:ui-monospace,SFMono-Regular,Menlo,monospace}
.seedbox b{color:var(--ink);font-weight:600}
.lbl{font-size:.72rem;letter-spacing:.09em;text-transform:uppercase;color:var(--muted);font-weight:700}
main{display:grid;grid-template-columns:minmax(0,1fr) 340px;gap:1rem;padding:0 1.4rem 1.6rem;
max-width:1280px}
@media (max-width:900px){ main{grid-template-columns:1fr} }
.boardwrap{background:var(--sea);border:1px solid var(--line);border-radius:14px;
padding:.6rem;box-shadow:var(--shadow)}
.boardwrap svg{display:block;width:100%;height:auto}
aside{display:flex;flex-direction:column;gap:.75rem;min-width:0}
.card{background:var(--panel);border:1px solid var(--line);border-radius:12px;
padding:.8rem .95rem;box-shadow:var(--shadow)}
.fair{display:flex;align-items:center;gap:.7rem}
.fair .big{font-size:1.5rem;font-weight:700;font-variant-numeric:tabular-nums}
.pill{padding:.15rem .6rem;border-radius:99px;font-size:.75rem;font-weight:700;letter-spacing:.03em}
.pill.good{background:color-mix(in srgb,var(--good) 18%,transparent);color:var(--good)}
.pill.warn{background:color-mix(in srgb,var(--warn) 20%,transparent);color:var(--warn)}
.fair small{color:var(--muted);display:block}
.player{display:flex;flex-direction:column;gap:.45rem}
.player .head{display:flex;align-items:center;gap:.55rem}
.swatch{width:14px;height:14px;border-radius:4px;border:1px solid rgba(0,0,0,.25)}
.player .head b{font-size:.95rem}
.player .head .pips{margin-left:auto;font-variant-numeric:tabular-nums;font-weight:700}
.player .head .pips small{color:var(--muted);font-weight:500}
.bar{height:5px;border-radius:3px;background:var(--panel2);overflow:hidden}
.bar i{display:block;height:100%;border-radius:3px}
.spots{display:flex;flex-direction:column;gap:.3rem;font-size:.85rem}
.spot{display:flex;align-items:center;gap:.45rem;color:var(--muted);flex-wrap:wrap}
.spot .hexes{display:flex;gap:.35rem;flex-wrap:wrap}
.spot .hexes.tgt .chip{opacity:.72}
.arrow{font-size:.68rem;letter-spacing:.05em;text-transform:uppercase;color:var(--muted)}
.coast{font-size:.78rem;color:var(--muted);font-style:italic}
.chip{display:inline-flex;align-items:center;gap:.28rem;background:var(--panel2);
border:1px solid var(--line);border-radius:6px;padding:.08rem .45rem;
font-variant-numeric:tabular-nums;font-weight:600;color:var(--ink)}
.dot{width:9px;height:9px;border-radius:3px;display:inline-block}
.covers{font-size:.78rem;color:var(--muted)}
.covers b{color:var(--ink)}
.boardcol{display:flex;flex-direction:column;gap:.75rem;min-width:0}
.legend{display:flex;flex-wrap:wrap;align-items:center;gap:.35rem 1rem;
font-size:.8rem;color:var(--muted)}
.legend .dot{width:11px;height:11px;margin-right:.15rem;vertical-align:-1px}
.legend .ring{display:inline-block;width:11px;height:11px;border-radius:50%;
border:3px solid var(--wood);background:var(--token);vertical-align:-1px;margin-right:.15rem}
.legend .ring.any{border-color:#8d8065}
.method{font-size:.8rem;color:var(--muted)}
.method b{color:var(--ink)}
.method ul{margin:.35rem 0 .8rem;padding-left:1.1rem;display:flex;
flex-direction:column;gap:.28rem}
.method ul:last-child{margin-bottom:0}
footer{padding:0 1.4rem 2rem;color:var(--muted);font-size:.78rem;max-width:70ch}
@media (prefers-reduced-motion:no-preference){
.btn.primary{transition:transform .06s ease}
}
@media print{
/* force the light palette regardless of theme, keep hex fills */
:root,:root[data-theme="dark"],:root[data-theme="light"]{
--bg:#fff; --sea:#eef4f6; --panel:#fff; --panel2:#f4f4f4;
--ink:#111; --muted:#444; --line:#bbb;
--token:#f6ecd4; --token-ink:#222; --shadow:none;
--wood:#3e7a45; --brick:#b5643c; --wheat:#d9a83c; --sheep:#8fbf6a;
--ore:#7d8494; --desert:#cdb98a; --gold:#ecc94b; --seahex:#cfe3ee;
}
*{-webkit-print-color-adjust:exact;print-color-adjust:exact}
.toolbar,.gh,#methodCard,footer{display:none!important}
header{padding:.2rem 0 0}
main{grid-template-columns:1fr;max-width:100%;padding:0;gap:.5rem}
.boardwrap{border:1px solid #ccc;padding:.3rem;break-inside:avoid}
aside{display:grid;grid-template-columns:repeat(2,1fr);gap:.45rem}
aside .fair{grid-column:1/-1}
.card{break-inside:avoid;padding:.5rem .6rem}
}
</style>
</head>
<body>
<header>
<h1 class="display">Harbormaster</h1>
<p>Balanced Catan boards with fair starting settlements, for 3–6 players.</p>
<a class="gh" href="https://github.com/sushobhith/harbormaster" target="_blank" rel="noopener" aria-label="View source code on GitHub">
<svg viewBox="0 0 16 16" width="16" height="16" aria-hidden="true" fill="currentColor"><path d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.01 8.01 0 0016 8c0-4.42-3.58-8-8-8z"/></svg>
<span>GitHub</span>
</a>
</header>
<div class="toolbar">
<span class="lbl">Map</span>
<div class="seg" id="map" role="group" aria-label="Map type">
<button data-map="classic" aria-pressed="true">Classic</button>
<button data-map="sea">Seafarers</button>
</div>
<span class="lbl">Players</span>
<div class="seg" id="players" role="group" aria-label="Player count">
<button data-n="3">3</button><button data-n="4" aria-pressed="true">4</button>
<button data-n="5">5</button><button data-n="6">6</button>
</div>
<span class="lbl">Setup</span>
<div class="seg" id="mode" role="group" aria-label="Setup mode">
<button data-mode="fair" aria-pressed="true">Fair settlements</button>
<button data-mode="board">Board only</button>
</div>
<button class="btn primary" id="newBoard">New board</button>
<button class="btn" id="reroll">Re-draw settlements</button>
<button class="btn" id="noPorts" aria-pressed="false"
title="Keep starting settlements off ports — pure production starts">No port starts</button>
<button class="btn" id="copy">Copy link</button>
<button class="btn" id="print">Print</button>
<span class="seedbox">seed <b id="seedLabel"></b></span>
</div>
<main>
<div class="boardcol">
<div class="boardwrap"><svg id="board" role="img" aria-label="Generated Catan board"></svg></div>
<div class="card legend">
<span class="lbl">Terrain</span>
<span><span class="dot" style="background:var(--wood)"></span> Wood · forest</span>
<span><span class="dot" style="background:var(--brick)"></span> Brick · hills</span>
<span><span class="dot" style="background:var(--wheat)"></span> Wheat · fields</span>
<span><span class="dot" style="background:var(--sheep)"></span> Sheep · pasture</span>
<span><span class="dot" style="background:var(--ore)"></span> Ore · mountains</span>
<span><span class="dot" style="background:var(--desert)"></span> Desert</span>
<span class="sea-only"><span class="dot" style="background:var(--gold)"></span> Gold · pick any resource</span>
<span class="sea-only"><span class="dot" style="background:var(--seahex)"></span> Sea</span>
<span class="lbl">Ports</span>
<span><i class="ring any"></i> 3:1 any resource</span>
<span><i class="ring" style="border-color:var(--wood)"></i> 2:1 · ring colour = its resource</span>
<span class="lbl">Tokens</span>
<span><b style="color:var(--accent)">6 / 8</b> roll most often</span>
</div>
</div>
<aside>
<div class="card fair" id="fairCard"></div>
<div id="playerCards" style="display:flex;flex-direction:column;gap:.75rem"></div>
<div class="card method" id="methodCard">
<b>Cheat sheet</b>
<ul>
<li><b>⌂ row</b> = one settlement. Chips = the hexes it collects from
(colour = resource, number = dice roll).</li>
<li><b>Pips</b> = the dots under a number = how often it rolls.
More pips = more cards. That's your whole score.</li>
<li><b>road →</b> = point that settlement's free road here.</li>
<li><b>⚓</b> = you start on a port. Counts toward your total,
so port players get slightly fewer pips. Still even.</li>
<li><b>±N</b> at the top = best player minus worst player.
0 or 1 = even game. Above 2 → hit Re-draw.</li>
<li><b>Weakest start plays first.</b> Order is on each card.</li>
</ul>
<b>Built-in rules</b>
<ul>
<li>6 and 8 never touch · twin numbers never touch · 2 never touches 12</li>
<li>No same-resource clumps · every resource gets a fair pip share</li>
<li class="classic-only">Ports fixed to match the real frame · land placed so a 2:1 port
avoids its own resource</li>
<li class="sea-only">Harbors on the official scenario edges, types shuffled ·
2:1 ports kept off their own resource</li>
<li>Settlement distance rule respected · 6/8 access evened across players</li>
</ul>
<b class="sea-only">Seafarers · Heading for New Shores</b>
<ul class="sea-only">
<li>Starting settlements go on the <b>main island</b> only — the island race is
yours to play. Rules allow a ship instead of a starting road; the drawn road
just shows which coast the plan valued.</li>
<li>Small islands use their own tile + number sets, including gold fields
(gold = collect any resource).</li>
<li>First settlement on each small island = <b>2 bonus VP</b> · play to 14 VP.</li>
<li>Robber: 4-player starts on the desert; 3-player has no desert — rulebook parks
it on an island hills hex. Pirate starts on the marked sea hex.</li>
</ul>
</div>
</aside>
</main>
<footer><span class="classic-only">Physical setup: lay tiles row by row as shown, tokens on top, robber on the desert.
Ports are fixed to match the printed frame (photo-verified, both 4-player and 5-6 player) —
rotate your frame so the port sequence lines up with the drawn board, then everything matches.</span>
<span class="sea-only">Physical setup: assemble the Seafarers frame per the "Heading for New Shores" scenario
diagram, then copy this board — the drawn shape, harbor positions, tile pools, and the two
number-token sets all follow the official scenario; only the placement is balanced-random.</span>
Re-draw settlements keeps the board and only re-deals the starting spots and roads.
Free and open source — <a href="https://github.com/sushobhith/harbormaster" target="_blank" rel="noopener" style="color:var(--accent)">view the code on GitHub</a>.
<details style="margin-top:.8rem"><summary style="cursor:pointer;font-weight:600">FAQ</summary>
<p><b>How is this different from other Catan board generators?</b> Others balance the board.
Harbormaster also deals each player two starting settlements, two roads, and a turn order,
matched so the start-value gap is at most 1–2 pips. Prefer drafting? Board-only mode keeps
the balanced board and leaves placement to the table.</p>
<p><b>Does it support Catan Seafarers?</b> Yes — the Seafarers map generates the official
"Heading for New Shores" scenario for 3–6 players: main island, small islands with gold
fields, their two separate number-token sets, and harbors on the official scenario edges.</p>
<p><b>Can I share a board?</b> Every board has a seed in the URL. Copy the link and everyone
sees the identical setup, settlements included.</p>
<p><b>Is it free?</b> Free, no signup, open source. One HTML file, runs entirely in your browser.</p>
</details></footer>
<script>
(() => {
"use strict";
/* ---------- RNG ---------- */
function xmur3(str){let h=1779033703^str.length;for(let i=0;i<str.length;i++){h=Math.imul(h^str.charCodeAt(i),3432918353);h=h<<13|h>>>19}return()=>{h=Math.imul(h^h>>>16,2246822507);h=Math.imul(h^h>>>13,3266489909);return(h^=h>>>16)>>>0}}
function mulberry32(a){return()=>{a|=0;a=a+0x6D2B79F5|0;let t=Math.imul(a^a>>>15,1|a);t=t+Math.imul(t^t>>>7,61|t)^t;return((t^t>>>14)>>>0)/4294967296}}
let rnd=Math.random;
const shuffle=a=>{for(let i=a.length-1;i>0;i--){const j=Math.floor(rnd()*(i+1));[a[i],a[j]]=[a[j],a[i]]}return a};
/* ---------- board data ---------- */
const RES={wood:"var(--wood)",brick:"var(--brick)",wheat:"var(--wheat)",sheep:"var(--sheep)",ore:"var(--ore)",desert:"var(--desert)",gold:"var(--gold)",sea:"var(--seahex)"};
const RESNAME={wood:"Wood",brick:"Brick",wheat:"Wheat",sheep:"Sheep",ore:"Ore",desert:"Desert",gold:"Gold",sea:"Sea"};
const BASE_RES=["wood","brick","wheat","sheep","ore"];
/* Seafarers "Heading for New Shores" — transcribed from the official rulebooks
(Seafarers 2021 3-4p, pp.8-10; Seafarers 5-6 Player Extension 2020, pp.6-7).
grid: flat-top hexes, one string per row; '.'=no hex, '~'=sea (fixed),
'm'=main-island slot, 'i'=small-island slot. Even columns sit half a hex LOWER.
Terrain pools and the two token sets match the rulebook component tables exactly
(main / red island numbers). portEdges = fixed harbor positions from the diagrams,
{r,c,k}: hex at grid[r][c], edge k (0=lower-right,1=bottom,2=lower-left,
3=upper-left,4=top,5=upper-right); port TYPES are drawn at random from portPool,
as the rulebook shuffles harbor tokens face-down. A couple of outer sea hexes are
printed on the physical frame rather than loose tiles — identical in play.
pirate = [r,c] sea hex where the scenario diagram parks the pirate. */
const SETUPS={
base:{rows:[3,4,5,4,3],
res:{wood:4,sheep:4,wheat:4,brick:3,ore:3,desert:1},
tokens:[2,3,3,4,4,5,5,6,6,8,8,9,9,10,10,11,11,12],
// photo-verified port sequence from the physical frame, clockwise from the west edge
portSeq:["any","sheep","any","any","brick","wood","any","wheat","ore"]},
ext:{rows:[3,4,5,6,5,4,3],
res:{wood:6,sheep:6,wheat:6,brick:5,ore:5,desert:2},
tokens:[2,2,3,3,3,4,4,4,5,5,5,6,6,6,8,8,8,9,9,9,10,10,10,11,11,11,12,12],
portSeq:["any","brick","sheep","wood","any","wheat","any","ore","any","sheep","any"]},
sea3:{grid:[
"....~...",
"..mmm~~.",
".mmmmm~i",
".mmmmm~i",
".~~m~~i~",
".ii~iii~",
"...~~~.."],
res:{main:{wood:3,sheep:4,wheat:3,brick:2,ore:2},
island:{gold:2,wheat:1,brick:2,ore:2,sheep:1}},
tokens:{main:[2,3,4,5,5,6,6,8,8,9,10,10,11,11],
island:[3,4,4,5,8,9,10,12]},
portEdges:[{r:1,c:3,k:3},{r:1,c:3,k:5},{r:2,c:1,k:4},{r:2,c:5,k:4},
{r:3,c:1,k:3},{r:3,c:1,k:1},{r:3,c:5,k:1},{r:4,c:3,k:0}],
portPool:["any","any","any","wood","brick","wheat","sheep","ore"],
pirate:[6,4]},
sea4:{grid:[
"....~...",
"..mmm~~.",
".mmmmm~i",
".mmmmm~i",
".mmmmm~~",
".~~m~~ii",
".ii~iii~",
"...~~~.."],
res:{main:{wood:4,sheep:4,wheat:4,brick:3,ore:3,desert:1},
island:{gold:2,wood:1,sheep:1,wheat:1,brick:2,ore:2}},
tokens:{main:[2,3,3,4,4,5,5,6,6,8,8,9,9,10,10,11,11,12],
island:[2,3,4,5,6,8,9,10,11]},
portEdges:[{r:1,c:2,k:4},{r:1,c:4,k:4},{r:2,c:1,k:3},{r:2,c:5,k:5},
{r:3,c:1,k:2},{r:3,c:5,k:0},{r:4,c:2,k:2},{r:4,c:4,k:0},{r:5,c:3,k:1}],
portPool:["any","any","any","any","wood","brick","wheat","sheep","ore"],
pirate:[7,4]},
sea56:{grid:[
"....~....",
".~ii~ii..",
".i~~m~~i.",
"~~mmmmm~~",
"~mmmmmmm~",
"~mmmmmmm~",
"~mmmmmmm~",
".~~mmm~~.",
".i~~~~~i.",
"...i~i~.."],
res:{main:{wood:6,sheep:6,wheat:6,brick:5,ore:5,desert:2},
island:{gold:3,wood:1,sheep:1,wheat:1,brick:2,ore:2}},
tokens:{main:[2,2,3,3,3,4,4,4,5,5,5,6,6,6,8,8,8,9,9,9,10,10,10,11,11,11,12,12],
island:[2,3,4,5,6,8,9,10,11,12]},
portEdges:[{r:2,c:4,k:3},{r:3,c:5,k:4},{r:3,c:2,k:3},{r:5,c:1,k:3},
{r:6,c:1,k:2},{r:6,c:2,k:1},{r:7,c:4,k:2},{r:7,c:5,k:1},
{r:5,c:7,k:0},{r:6,c:6,k:0},{r:3,c:6,k:5}],
portPool:["any","any","any","any","any","wood","brick","wheat","ore","sheep","sheep"],
pirate:null}
};
const PIPS={2:1,3:2,4:3,5:4,6:5,8:5,9:4,10:3,11:2,12:1};
const PLAYERCOLORS=[["Red","#c0392b"],["Blue","#2e6da4"],["White","#e8e6df"],["Orange","#d98032"],["Green","#4c9a52"],["Brown","#8a5a3b"]];
/* ---------- geometry (pointy-top classic, flat-top scenario grids) ---------- */
const S=52, W=Math.sqrt(3)*S;
function buildGeom(setup){
const hexes=[]; let cellIndex=null;
if(setup.grid){
// flat-top offset grid, even columns half a hex lower (matches the rulebook diagrams)
cellIndex=new Map();
setup.grid.forEach((row,r)=>{for(let c=0;c<row.length;c++){
const ch=row[c]; if(ch===".")continue;
const region=ch==="m"?"main":ch==="i"?"island":"sea";
cellIndex.set(r+","+c,hexes.length);
hexes.push({x:c*1.5*S, y:r*W+(c%2===0?W/2:0), id:hexes.length, region});
}});
}else{
setup.rows.forEach((len,r)=>{for(let i=0;i<len;i++)
hexes.push({x:(i-(len-1)/2)*W, y:r*1.5*S, id:hexes.length, region:"main"});});
}
const flat=!!setup.grid;
for(const h of hexes){h.corners=[];for(let k=0;k<6;k++){
const a=Math.PI/180*(flat?60*k:60*k-30);
h.corners.push([h.x+S*Math.cos(a), h.y+S*Math.sin(a)]);}}
// dedupe vertices
const vmap=new Map(), verts=[];
const key=(x,y)=>Math.round(x*10)+"_"+Math.round(y*10);
for(const h of hexes) h.vids=h.corners.map(([x,y])=>{
const k=key(x,y);
if(!vmap.has(k)){vmap.set(k,verts.length);verts.push({x,y,hexes:[],adj:new Set()});}
const id=vmap.get(k); verts[id].hexes.push(h.id); return id;});
// hex adjacency
for(const a of hexes){a.adj=[];for(const b of hexes){
if(a!==b && Math.hypot(a.x-b.x,a.y-b.y)<W*1.1) a.adj.push(b.id);}}
// vertex adjacency (edges of hexes)
for(const h of hexes) for(let k=0;k<6;k++){
const a=h.vids[k], b=h.vids[(k+1)%6];
verts[a].adj.add(b); verts[b].adj.add(a);}
const geom={hexes,verts,cellIndex};
if(setup.grid){
// Seafarers: starting settlements (and road targets) live on the main island only
geom.mainVertIds=new Set();
verts.forEach((v,i)=>{
const regs=v.hexes.map(hid=>hexes[hid].region);
if(regs.includes("main")&&!regs.includes("island"))geom.mainVertIds.add(i);
});
}
return geom;
}
/* ---------- resource placement: no same-type neighbours, keep 2:1 ports off their own resource ----------
Seafarers grids place two independent pools (main island / small islands) into their own
slots; sea hexes are fixed and never enter the search. */
function placeResources(geom,setup,ports){
const regions=setup.grid
?[{slots:geom.hexes.filter(h=>h.region==="main").map(h=>h.id),pool:setup.res.main},
{slots:geom.hexes.filter(h=>h.region==="island").map(h=>h.id),pool:setup.res.island}]
:[{slots:geom.hexes.map(h=>h.id),pool:setup.res}];
const portTouch=ports.filter(p=>p.type!=="any").map(p=>({type:p.type,
hexes:[...new Set([...geom.verts[p.a].hexes,...geom.verts[p.b].hexes])]}));
const bad=arr=>{let v=0;
for(const h of geom.hexes)for(const j of h.adj)
if(j>h.id && arr[h.id]!=="sea" && arr[h.id]===arr[j]) v++;
for(const pt of portTouch)for(const hid of pt.hexes)
if(arr[hid]===pt.type) v++;
return v;};
let best=null,bestV=1e9;
for(let attempt=0;attempt<40;attempt++){
const arr=[];
for(const h of geom.hexes)if(h.region==="sea")arr[h.id]="sea";
for(const rg of regions){
const p=[];
for(const[r,n]of Object.entries(rg.pool))for(let i=0;i<n;i++)p.push(r);
shuffle(p); rg.slots.forEach((id,i)=>arr[id]=p[i]);
}
let v=bad(arr);
for(let it=0;it<600&&v>0;it++){
// extra rnd() draw only on multi-region boards, so classic seeds reproduce exactly
const rg=regions.length>1?regions[Math.floor(rnd()*regions.length)]:regions[0];
const i=rg.slots[Math.floor(rnd()*rg.slots.length)],
j=rg.slots[Math.floor(rnd()*rg.slots.length)];
if(arr[i]===arr[j])continue;
[arr[i],arr[j]]=[arr[j],arr[i]];
const nv=bad(arr);
if(nv<=v)v=nv; else [arr[i],arr[j]]=[arr[j],arr[i]];
}
if(v<bestV){bestV=v;best=arr.slice();}
if(v===0)break;
}
return best;
}
/* ---------- number placement ----------
Seafarers grids carry two independent token sets (main island / small islands,
the rulebook's black and red numbers); tokens stay inside their region. Sea and
desert hexes carry no token; gold fields do. */
function placeNumbers(geom,setup,resArr){
const regions=setup.grid
?[{ids:geom.hexes.filter(h=>h.region==="main"&&resArr[h.id]!=="desert").map(h=>h.id),
toks:setup.tokens.main},
{ids:geom.hexes.filter(h=>h.region==="island").map(h=>h.id),
toks:setup.tokens.island}]
:[{ids:geom.hexes.filter(h=>resArr[h.id]!=="desert").map(h=>h.id),toks:setup.tokens}];
const land=regions.flatMap(rg=>rg.ids);
const score=num=>{
let s=0;
for(const id of land){const h=geom.hexes[id],a=num[id];
for(const j of h.adj){ if(j<=id||num[j]==null)continue;
const b=num[j];
if((a===6||a===8)&&(b===6||b===8)) s+=100;
if(a===b) s+=8;
if((a===2&&b===12)||(a===12&&b===2)) s+=6;
}}
// per-resource pip fairness
const tot={},cnt={};
for(const id of land){const r=resArr[id];tot[r]=(tot[r]||0)+PIPS[num[id]];cnt[r]=(cnt[r]||0)+1;}
const avgs=Object.keys(tot).map(r=>tot[r]/cnt[r]);
const mean=avgs.reduce((a,b)=>a+b,0)/avgs.length;
for(const a of avgs) s+=Math.abs(a-mean)*4;
return s;
};
let best=null,bestS=1e9;
for(let attempt=0;attempt<25;attempt++){
const num={};
for(const rg of regions){
const toks=shuffle(rg.toks.slice());
rg.ids.forEach((id,i)=>num[id]=toks[i]);
}
let s=score(num);
for(let it=0;it<1200;it++){
const rg=regions.length>1?regions[Math.floor(rnd()*regions.length)]:regions[0];
const i=rg.ids[Math.floor(rnd()*rg.ids.length)], j=rg.ids[Math.floor(rnd()*rg.ids.length)];
if(num[i]===num[j])continue;
[num[i],num[j]]=[num[j],num[i]];
const ns=score(num);
if(ns<=s)s=ns; else [num[i],num[j]]=[num[j],num[i]];
}
if(s<bestS){bestS=s;best={...num}}
if(s<3)break;
}
return best;
}
/* ---------- ports: fixed layout matching the physical frame ----------
Seafarers: harbor POSITIONS are fixed by the scenario diagram (portEdges);
harbor TYPES are drawn at random from the official pool, like shuffling the
tokens face-down. */
function placePorts(geom,setup){
if(setup.portEdges){
const types=shuffle(setup.portPool.slice());
return setup.portEdges.map((pe,i)=>{
const h=geom.hexes[geom.cellIndex.get(pe.r+","+pe.c)];
const a=h.vids[pe.k], b=h.vids[(pe.k+1)%6];
const va=geom.verts[a], vb=geom.verts[b];
return {a,b,hex:h.id,mx:(va.x+vb.x)/2,my:(va.y+vb.y)/2,type:types[i]};
});
}
const portSeq=setup.portSeq;
const ecount=new Map(), einfo=new Map();
for(const h of geom.hexes) for(let k=0;k<6;k++){
const a=h.vids[k], b=h.vids[(k+1)%6];
const key=Math.min(a,b)+"_"+Math.max(a,b);
ecount.set(key,(ecount.get(key)||0)+1);
einfo.set(key,{a,b,hex:h.id});
}
let cx=0,cy=0; geom.hexes.forEach(h=>{cx+=h.x;cy+=h.y});
cx/=geom.hexes.length; cy/=geom.hexes.length;
const per=[...ecount.entries()].filter(([,c])=>c===1).map(([k])=>einfo.get(k));
per.forEach(e=>{const va=geom.verts[e.a],vb=geom.verts[e.b];
e.mx=(va.x+vb.x)/2; e.my=(va.y+vb.y)/2;
e.ang=Math.atan2(e.my-cy,e.mx-cx);});
per.sort((p,q)=>p.ang-q.ang); // clockwise, starting at the west edge
const n=portSeq.length;
return portSeq.map((ty,i)=>{
const e=per[Math.round(i*per.length/n)%per.length];
return {a:e.a,b:e.b,hex:e.hex,mx:e.mx,my:e.my,type:ty};
});
}
const portStatic=ty=>ty==null?0:(ty==="any"?1.0:1.5);
/* ---------- settlement selection & fair pairing ---------- */
function vertexInfo(geom,resArr,num,vid){
const v=geom.verts[vid];let pips=0;const res=new Set(),chips=[];
for(const hid of v.hexes){const r=resArr[hid];
if(num[hid]==null)continue; // desert and sea carry no token; gold does
pips+=PIPS[num[hid]]; res.add(r); chips.push([r,num[hid]]);}
return {pips,res,chips};
}
function pairEff(p){
let v=p[0].pips+p[1].pips;
for(const spot of p){
if(!spot.port)continue;
if(spot.port==="any"){v+=1.0;continue;}
let rp=0;
for(const s of p)for(const[r,n]of s.chips)if(r===spot.port)rp+=PIPS[n];
v+=1.5+(rp>=4?0.5:0);
}
return v;
}
function drawSettlements(geom,resArr,num,nPlayers,portMap,noPorts){
const need=nPlayers*2;
let best=null;
for(let attempt=0;attempt<60;attempt++){
// greedy pick with jitter, distance rule; ports raise a spot's value
const scored=geom.verts.map((v,i)=>{
const inf=vertexInfo(geom,resArr,num,i);
const port=portMap.get(i)||null;
const redp=inf.chips.filter(([,n])=>n===6||n===8).length*5;
return {vid:i,pips:inf.pips,res:inf.res,chips:inf.chips,port,redp,
s:inf.pips+inf.res.size*0.7+portStatic(port)+rnd()*1.4};
}).filter(o=>o.pips>=3&&(!geom.mainVertIds||geom.mainVertIds.has(o.vid))
&&(!noPorts||!o.port))
.sort((a,b)=>b.s-a.s);
const blocked=new Set(),picked=[];
for(const o of scored){
if(blocked.has(o.vid))continue;
picked.push(o); blocked.add(o.vid);
for(const nb of geom.verts[o.vid].adj) blocked.add(nb);
if(picked.length===need)break;
}
if(picked.length<need)continue;
// fair pairing: strongest with weakest, by effective value
picked.sort((a,b)=>(b.pips+portStatic(b.port))-(a.pips+portStatic(a.port)));
const pairs=[];
for(let i=0;i<nPlayers;i++) pairs.push([picked[i],picked[need-1-i]]);
// local swaps: shrink value spread, keep diversity, even out 6/8 exposure
const div=p=>new Set([...p[0].res,...p[1].res]).size;
const spread=ps=>Math.max(...ps.map(pairEff))-Math.min(...ps.map(pairEff));
const divmin=ps=>Math.min(...ps.map(div));
const redspan=ps=>{const r=ps.map(p=>p[0].redp+p[1].redp);
return Math.max(...r)-Math.min(...r);};
const key=ps=>[spread(ps),-divmin(ps),redspan(ps)];
const worse=(k1,k0)=>{for(let i=0;i<k1.length;i++){
if(k1[i]>k0[i]+1e-9)return true; if(k1[i]<k0[i]-1e-9)return false;}
return false;};
for(let it=0;it<600;it++){
const a=Math.floor(rnd()*nPlayers),b=Math.floor(rnd()*nPlayers);
if(a===b)continue;
const ia=Math.floor(rnd()*2),ib=Math.floor(rnd()*2);
const k0=key(pairs);
[pairs[a][ia],pairs[b][ib]]=[pairs[b][ib],pairs[a][ia]];
if(worse(key(pairs),k0))
[pairs[a][ia],pairs[b][ib]]=[pairs[b][ib],pairs[a][ia]];
}
const cand={pairs,spread:spread(pairs),divmin:divmin(pairs),
redspan:redspan(pairs),total:pairs.reduce((t,p)=>t+pairEff(p),0)};
const candKey=c=>[c.spread,-c.divmin,c.redspan,-c.total];
if(!best||worse(candKey(best),candKey(cand))) best=cand;
if(best.spread<0.6&&best.divmin>=4&&best.redspan<=5)break;
}
// port-free spots can run out on small boards — fall back to allowing ports
if(!best&&noPorts)return drawSettlements(geom,resArr,num,nPlayers,portMap,false);
return best;
}
/* ---------- starting roads: point at best unclaimed expansion spot ---------- */
function planRoads(geom,resArr,num,pairs,portMap){
const blocked=new Set();
for(const p of pairs)for(const s of p){blocked.add(s.vid);
for(const nb of geom.verts[s.vid].adj)blocked.add(nb);}
const sums=pairs.map(p=>p[0].pips+p[1].pips);
const order=pairs.map((_,i)=>i).sort((a,b)=>sums[a]-sums[b]);
const claimed=new Set();
const findTarget=(spot,ignoreClaims)=>{
let best=null;
for(const v2 of geom.verts[spot.vid].adj){
if(geom.mainVertIds&&!geom.mainVertIds.has(v2))continue; // roads stay on the main island
for(const v3 of geom.verts[v2].adj){
if(v3===spot.vid||blocked.has(v3))continue;
if(geom.mainVertIds&&!geom.mainVertIds.has(v3))continue;
if(!ignoreClaims&&claimed.has(v3))continue;
const inf=vertexInfo(geom,resArr,num,v3);
if(inf.pips<1)continue;
const val=inf.pips+inf.res.size*0.7+portStatic(portMap.get(v3)||null);
if(!best||val>best.val)
best={to:v2,target:v3,val,pips:inf.pips,chips:inf.chips};
}
}
return best;
};
for(const pi of order){
for(const spot of pairs[pi]){
let best=findTarget(spot,false); // prefer a spot nobody else aims at
if(best)claimed.add(best.target);
else best=findTarget(spot,true) // contested spot beats no spot
||{to:[...geom.verts[spot.vid].adj].find(v=>!geom.mainVertIds||geom.mainVertIds.has(v))
??[...geom.verts[spot.vid].adj][0],target:null,val:0,pips:0,chips:[]};
spot.road=best;
}
}
}
/* ---------- render ---------- */
const svg=document.getElementById("board");
const NS="http://www.w3.org/2000/svg";
function el(name,attrs,parent){const e=document.createElementNS(NS,name);
for(const[k,v]of Object.entries(attrs))e.setAttribute(k,v);
(parent||svg).appendChild(e);return e;}
function render(geom,resArr,num,ports,placement,setup){
svg.innerHTML="";
const xs=geom.verts.map(v=>v.x),ys=geom.verts.map(v=>v.y);
const pad=40;
const minx=Math.min(...xs)-pad,maxx=Math.max(...xs)+pad;
const miny=Math.min(...ys)-pad,maxy=Math.max(...ys)+pad;
svg.setAttribute("viewBox",`${minx} ${miny} ${maxx-minx} ${maxy-miny}`);
let desertDone=false;
for(const h of geom.hexes){
const r=resArr[h.id];
el("polygon",{points:h.corners.map(c=>c.join(",")).join(" "),
fill:RES[r],stroke:r==="sea"?"rgba(30,25,15,.16)":"rgba(30,25,15,.35)",
"stroke-width":2.2,"stroke-linejoin":"round"});
if(r==="gold"){ // sparkle so gold never reads as wheat
const s1=el("text",{x:h.x-20,y:h.y-16,"text-anchor":"middle","font-size":13,
fill:"rgba(120,90,10,.9)"});s1.textContent="✦";
const s2=el("text",{x:h.x+20,y:h.y+22,"text-anchor":"middle","font-size":9,
fill:"rgba(120,90,10,.75)"});s2.textContent="✦";
}
if(num[h.id]!=null){
const n=num[h.id],red=n===6||n===8;
el("circle",{cx:h.x,cy:h.y,r:15.5,fill:"var(--token)",
stroke:"rgba(30,25,15,.3)","stroke-width":1});
const t=el("text",{x:h.x,y:h.y+1,"text-anchor":"middle",
"dominant-baseline":"middle","font-size":15,"font-weight":700,
fill:red?"#c0392b":"var(--token-ink)"});
t.textContent=n; t.style.fontFamily='"Iowan Old Style",Palatino,Georgia,serif';
const pips=PIPS[n];
for(let p=0;p<pips;p++)
el("circle",{cx:h.x+(p-(pips-1)/2)*3.6,cy:h.y+9.5,r:1.15,
fill:red?"#c0392b":"var(--token-ink)"});
} else if(r==="desert"&&!desertDone){ desertDone=true;
const g=el("g",{transform:`translate(${h.x},${h.y})`});
el("circle",{cx:0,cy:0,r:9,fill:"rgba(40,35,28,.75)"},g);
el("circle",{cx:0,cy:-9,r:4.5,fill:"rgba(40,35,28,.75)"},g);
const t=el("text",{x:0,y:24,"text-anchor":"middle","font-size":8,
fill:"rgba(40,35,28,.8)","font-weight":600},g);
t.textContent="ROBBER";
}
}
// pirate start hex (Seafarers scenario diagram position)
if(setup&&setup.pirate&&geom.cellIndex){
const hid=geom.cellIndex.get(setup.pirate[0]+","+setup.pirate[1]);
if(hid!=null){const h=geom.hexes[hid];
const g=el("g",{transform:`translate(${h.x},${h.y})`});
el("path",{d:"M -11 2 L 11 2 L 6 9 L -6 9 Z",fill:"rgba(25,22,18,.85)"},g);
el("path",{d:"M 0 2 L 0 -12 L 8 -4 L 1 -4",fill:"rgba(25,22,18,.85)"},g);
const t=el("text",{x:0,y:22,"text-anchor":"middle","font-size":8,
fill:"var(--muted)","font-weight":600},g);
t.textContent="PIRATE";
}
}
// ports on the coast
for(const pt of ports){
const va=geom.verts[pt.a], vb=geom.verts[pt.b], h=geom.hexes[pt.hex];
let dx=pt.mx-h.x, dy=pt.my-h.y;
const L=Math.hypot(dx,dy)||1; dx/=L; dy/=L;
const px=pt.mx+dx*17, py=pt.my+dy*17;
for(const v of [va,vb])
el("line",{x1:v.x,y1:v.y,x2:px,y2:py,stroke:"rgba(60,45,25,.5)",
"stroke-width":3,"stroke-linecap":"round"});
el("circle",{cx:px,cy:py,r:11,fill:"var(--token)",
stroke:pt.type==="any"?"rgba(90,80,60,.85)":RES[pt.type],"stroke-width":3});
const t=el("text",{x:px,y:py+1,"text-anchor":"middle",
"dominant-baseline":"middle","font-size":8.5,"font-weight":700,
fill:"var(--token-ink)"});
t.textContent=pt.type==="any"?"3:1":"2:1";
}
if(!placement)return; // board-only mode: no settlements/roads
// starting roads (under the houses)
placement.pairs.forEach((pair,pi)=>{
const[,color]=PLAYERCOLORS[pi];
for(const spot of pair){
const r=spot.road; if(!r)continue;
const a=geom.verts[spot.vid], b=geom.verts[r.to];
const x1=a.x+(b.x-a.x)*0.2, y1=a.y+(b.y-a.y)*0.2;
const x2=a.x+(b.x-a.x)*0.88, y2=a.y+(b.y-a.y)*0.88;
el("line",{x1,y1,x2,y2,stroke:"rgba(20,15,10,.6)","stroke-width":7.5,"stroke-linecap":"round"});
el("line",{x1,y1,x2,y2,stroke:color,"stroke-width":4.5,"stroke-linecap":"round"});
}
});
// settlements
placement.pairs.forEach((pair,pi)=>{
const[,color]=PLAYERCOLORS[pi];
for(const spot of pair){
const v=geom.verts[spot.vid];
const g=el("g",{transform:`translate(${v.x},${v.y})`});
el("path",{d:"M -8 8 L -8 -2 L 0 -9 L 8 -2 L 8 8 Z",fill:color,
stroke:"rgba(20,15,10,.55)","stroke-width":1.6,"stroke-linejoin":"round"},g);
const t=el("text",{x:0,y:3.5,"text-anchor":"middle","font-size":9,
"font-weight":800,fill:pi===2?"#333":"#fff"},g);
t.textContent=pi+1;
}
});
}
function renderPanel(geom,resArr,num,portMap,placement){
const cards=document.getElementById("playerCards");cards.innerHTML="";
const sums=placement.pairs.map(p=>p[0].pips+p[1].pips);
const effs=placement.pairs.map(pairEff);
const maxEff=Math.max(...effs);
const order=placement.pairs.map((p,i)=>i).sort((a,b)=>effs[a]-effs[b]);
placement.pairs.forEach((pair,pi)=>{
const[name,color]=PLAYERCOLORS[pi];
const covered=new Set([...pair[0].res,...pair[1].res]);
const missing=BASE_RES.filter(r=>!covered.has(r));
const card=document.createElement("div");card.className="card player";
const chipsOf=list=>list.map(([r,n])=>
`<span class="chip"><span class="dot" style="background:${RES[r]}"></span>${n}</span>`).join("");
const spotHTML=spot=>{
const inf=vertexInfo(geom,resArr,num,spot.vid);
const port=portMap.get(spot.vid);
const portChip=port?`<span class="chip pt">⚓ ${port==="any"
?"3:1":`2:1 <span class="dot" style="background:${RES[port]}"></span>`}</span>`:"";
const tgt=spot.road&&spot.road.target!=null
?`<span class="hexes tgt">${chipsOf(spot.road.chips)}</span>`
:`<span class="coast">open coast</span>`;
return `<div class="spot">⌂<span class="hexes">${chipsOf(inf.chips)}${portChip}</span>`
+`<span class="arrow">road →</span>${tgt}</div>`;};
const turn=order.indexOf(pi)+1;
const portBonus=effs[pi]-sums[pi];
card.innerHTML=`
<div class="head"><span class="swatch" style="background:${color}"></span>
<b>Player ${pi+1} · ${name}</b>
<span class="pips">${sums[pi]} <small>pips</small>${
portBonus>0?` <small>+${portBonus.toFixed(1)} port</small>`:""}</span></div>
<div class="bar"><i style="width:${effs[pi]/maxEff*100}%;background:${color}"></i></div>
<div class="spots">${spotHTML(pair[0])}${spotHTML(pair[1])}</div>
<div class="covers">Covers <b>${covered.size}/5</b> resources${
missing.length?` · missing ${missing.map(m=>RESNAME[m]).join(", ")}`:""}
· takes turn <b>${turn}</b>${turn===1?" — starts first":""}</div>`;
cards.appendChild(card);
});
const fc=document.getElementById("fairCard");
const spread=Math.round(placement.spread*10)/10;
const ok=spread<=2;
const starter=PLAYERCOLORS[order[0]][0];
fc.innerHTML=`<span class="big">±${spread}</span>
<div><span class="pill ${ok?"good":"warn"}">${ok?"Balanced start":"Uneven — re-draw"}</span>
<small>start-value gap (pips + port worth), best vs worst · avg ${
(sums.reduce((a,b)=>a+b,0)/sums.length).toFixed(1)} pips each ·
<b>${starter} starts first</b>, then weakest to strongest</small></div>`;
}
function renderBoardPanel(isSea,draftSpread){
document.getElementById("fairCard").innerHTML=
`<span class="big">⚓</span><div><span class="pill good">Balanced board</span>
<small>Fair board and ports. Everyone drafts their own settlements, so no corner is a
runaway pick and the placement duel is still yours to play.${
draftSpread!=null?` A solid snake draft on this board lands within
<b>±${Math.round(draftSpread*10)/10} pips</b>.`:""}</small></div>`;
document.getElementById("playerCards").innerHTML=
`<div class="card"><b>Place your own settlements</b>
<div class="covers" style="margin-top:.4rem">The board is generated to be fair, then it's
yours to draft. What's guaranteed:</div>
<ul style="margin:.45rem 0 0;padding-left:1.1rem;display:flex;flex-direction:column;
gap:.3rem;font-size:.85rem;color:var(--muted)">
<li>No 6/8 touching, no twin numbers touching, no 2 beside 12</li>
<li>No same-resource clumps, even pip share across all five resources</li>
${isSea
?`<li>Harbors on the official scenario edges, types shuffled, 2:1s kept off their own resource</li>
<li>Main island and small islands each use their official tile and number sets</li>`
:`<li>Ports fixed to the real frame, 2:1s kept off their own resource</li>`}
</ul></div>`;
}
/* ---------- board-only helper: what a competent snake draft lands at ---------- */
function snakeSpread(geom,resArr,num,nPlayers){
const legal=i=>!geom.mainVertIds||geom.mainVertIds.has(i);
const bl=new Set(); const own=Array.from({length:nPlayers},()=>[]);
const order=[...Array(nPlayers).keys()];
for(const pl of order.concat(order.slice().reverse())){
let best=null;
for(let i=0;i<geom.verts.length;i++){
if(bl.has(i)||!legal(i))continue;
const inf=vertexInfo(geom,resArr,num,i);
const nd=new Set([...own[pl].flatMap(s=>[...s.res]),...inf.res]).size;
const sc=inf.pips+0.7*nd;
if(!best||sc>best.sc)best={i,inf,sc};
}
if(!best)break;
own[pl].push(best.inf); bl.add(best.i);
for(const nb of geom.verts[best.i].adj)bl.add(nb);
}
const sums=own.map(ss=>ss.reduce((t,s)=>t+s.pips,0));
return Math.max(...sums)-Math.min(...sums);
}
/* ---------- orchestration ---------- */
let state={players:4,mode:"fair",map:"classic",noPorts:false,seed:null,board:null,placement:null};
function newSeed(){return Math.random().toString(36).slice(2,8)}
function generate(fullBoard){
if(fullBoard||!state.board){
// classic seeds keep their pre-Seafarers namespace so old shared links reproduce
rnd=mulberry32(xmur3(state.seed+"|"+state.players+(state.map==="sea"?"|sea":""))());
const setup=state.map==="sea"
?(state.players>=5?SETUPS.sea56:state.players===4?SETUPS.sea4:SETUPS.sea3)
:(state.players>=5?SETUPS.ext:SETUPS.base);
const geom=buildGeom(setup);
const ports=placePorts(geom,setup);
const resArr=placeResources(geom,setup,ports);
const num=placeNumbers(geom,setup,resArr);
const portMap=new Map();
for(const p of ports){portMap.set(p.a,p.type);portMap.set(p.b,p.type);}
state.board={setup,geom,resArr,num,ports,portMap};
}
const {setup,geom,resArr,num,ports,portMap}=state.board;
const fair=state.mode!=="board";
document.body.dataset.map=state.map;
document.getElementById("reroll").style.display=fair?"":"none";
document.getElementById("noPorts").style.display=fair?"":"none";
document.getElementById("methodCard").style.display=fair?"":"none";
if(fair){
state.placement=drawSettlements(geom,resArr,num,state.players,portMap,state.noPorts);
planRoads(geom,resArr,num,state.placement.pairs,portMap);
render(geom,resArr,num,ports,state.placement,setup);
renderPanel(geom,resArr,num,portMap,state.placement);
}else{
state.placement=null;
render(geom,resArr,num,ports,null,setup);
renderBoardPanel(state.map==="sea",snakeSpread(geom,resArr,num,state.players));
}
document.getElementById("seedLabel").textContent=state.seed;
const mp=(state.mode==="board"?"&m=board":"")+(state.map==="sea"?"&map=sea":"")
+(state.noPorts?"&np=1":"");
try{history.replaceState(null,"",`#s=${state.seed}&p=${state.players}${mp}`);}catch(_){}
}
function readHash(){
const m=Object.fromEntries(new URLSearchParams(location.hash.slice(1)));
if(m.s)state.seed=m.s;
if(m.p&&+m.p>=3&&+m.p<=6)state.players=+m.p;
if(m.m==="board")state.mode="board";
if(m.map==="sea")state.map="sea";
if(m.np==="1")state.noPorts=true;
}
document.getElementById("players").addEventListener("click",e=>{
const b=e.target.closest("button");if(!b)return;
document.querySelectorAll("#players button").forEach(x=>x.setAttribute("aria-pressed",x===b));
state.players=+b.dataset.n; state.board=null; generate(true);
});
document.getElementById("map").addEventListener("click",e=>{
const b=e.target.closest("button");if(!b)return;
document.querySelectorAll("#map button").forEach(x=>x.setAttribute("aria-pressed",x===b));
state.map=b.dataset.map; state.board=null; generate(true);
});
document.getElementById("newBoard").onclick=()=>{state.seed=newSeed();state.board=null;generate(true)};
document.getElementById("reroll").onclick=()=>generate(false);
document.getElementById("noPorts").onclick=e=>{
state.noPorts=!state.noPorts;
e.target.setAttribute("aria-pressed",state.noPorts);
generate(false); // same board, re-deal the starting spots
};
document.getElementById("print").onclick=()=>window.print();
document.getElementById("mode").addEventListener("click",e=>{
const b=e.target.closest("button");if(!b)return;
document.querySelectorAll("#mode button").forEach(x=>x.setAttribute("aria-pressed",x===b));
state.mode=b.dataset.mode; generate(false);
});
document.getElementById("copy").onclick=async e=>{
const mp=(state.mode==="board"?"&m=board":"")+(state.map==="sea"?"&map=sea":"")
+(state.noPorts?"&np=1":"");
const link=location.href.split("#")[0]+`#s=${state.seed}&p=${state.players}${mp}`;
try{await navigator.clipboard.writeText(link);e.target.textContent="Copied ✓";}
catch(_){e.target.textContent=link;}
setTimeout(()=>e.target.textContent="Copy link",2500);
};
/* test hook: drives the exact production pipeline for a given seed/player count/map */
window.__hm={run(seed,players,map,noPorts){
state.seed=seed; state.players=players; state.mode="fair"; state.map=map==="sea"?"sea":"classic";
state.noPorts=!!noPorts; state.board=null;
generate(true);
const {geom,resArr,num,ports}=state.board;
return {
...(state.map==="sea"?{map:"sea"}:{}), // classic return shape unchanged (golden tests)
hexes:geom.hexes.map(h=>({id:h.id,adj:h.adj,res:resArr[h.id],num:num[h.id]??null,
...(state.map==="sea"?{region:h.region}:{})})),
verts:geom.verts.map(v=>({hexes:v.hexes,adj:[...v.adj]})),
ports:ports.map(p=>({a:p.a,b:p.b,type:p.type})),
pairs:state.placement.pairs.map(pr=>pr.map(s=>({vid:s.vid,pips:s.pips,port:s.port,
road:s.road?{to:s.road.to,target:s.road.target}:null}))),
spread:state.placement.spread
};
}};
readHash();