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
|
const crossroads = [1007,1012,1018,1022,1023,1100,1109,1111,1112,1117,1118,1121,1129,1130,1131,1134,1135,1201,1204,1207,1209,1215,1217,1218,1220,1221,1231,1301,1302,1304,1314,1316,1317,1318,1319,1327,1333,1340,1401,1405,1407,1408,1410,1416,1417,1419,1434,1440,1506,1511,1514,1516,1518,1520,1601,1607,1612,1618,1622,1623,1708,1709,1713,1716,1717,1720,1721,1725,1728,1737,1801,1802,1806,1812,1813,1820,1821,1830,1833,1836,1838,1903,1905,1906,1908,1909,1911,1914,1915,1917,1919,1922,1925,1927,1929,1931,1932,2001,2015,2018,2019,2026,2027,2030,2035,2117,2122,2129,2133,2203,2219,2222,2223,2225,2226,2228,2236,2307,2308,2317,2321,2322,2323,2324,2329,2336,2337,2339,2404,2405,2418,2421,2423,2425,2427,2430,2431,2436,2437,2438,2440,2500,2502,2503,2504,2509,2519,2522,2526,2529,2530,2534,2536,2601,2604,2605,2609,2610,2613,2618,2619,2626,2628,2635,2636,2640,2701,2702,2704,2710,2714,2715,2721,2723,2729,2730,2733,2802,2810,2818,2825,2827,2828,2829,2831,2836,2840,2902,2909,2911,2913,2928,2930,2932,2935,3001,3002,3003,3004,3007,3008,3012,3017,3018,3028,3030,3035,3036,3037,3038,3039,3103,3117,3120,3125,3127,3129,3135,3138,3140,3202,3203,3208,3216,3228,3231,3234,3301,3302,3303,3304,3311,3313,3316,3326,3327,3333,3337,3338,3339,3402,3404,3408,3411,3412,3413,3428,3436,3505,3509,3512,3515,3526,3532,3535,3539,3540,3603,3605,3608,3613,3614,3615,3616,3633,3635,3636,3705,3708,3711,3713,3715,3718,3722,3723,3728,3729,3731,3801,3802,3804,3808,3813,3814,3818,3819,3828,3829,3841,3900,3903,3905,3915,3917,3919,3925,3935,4005,4006]
const splits = [1120,1510,1604,2034,2629,2717,3029,3409,3826]
const road_segments = [[1117,1218],[1000,1100],[1006,1007],[1006,1105],[1007,1107],[1009,1109],[1011,1111],[1012,1112],[1012,1111],[1015,1115],[1017,1117],[1018,1019],[1018,1117],[1019,1020],[1022,1023],[1022,1121],[1023,1024],[1026,1027],[1026,1126],[1027,1127],[1029,1129],[1030,1130],[1031,1131],[1031,1130],[1032,1033],[1032,1131],[1033,1034],[1034,1134],[1035,1135],[1035,1134],[1036,1135],[1100,1201],[1104,1105],[1104,1204],[1107,1207],[1109,1110],[1109,1209],[1110,1111],[1111,1112],[1111,1211],[1112,1113],[1113,1214],[1115,1215],[1116,1117],[1116,1216],[1118,1119],[1118,1219],[1118,1218],[1119,1220],[1121,1221],[1126,1226],[1127,1128],[1128,1129],[1129,1130],[1130,1231],[1131,1232],[1131,1231],[1135,1235],[1200,1201],[1201,1202],[1201,1301],[1202,1302],[1203,1204],[1203,1302],[1204,1304],[1206,1207],[1206,1305],[1207,1208],[1208,1209],[1209,1309],[1211,1311],[1214,1314],[1215,1216],[1215,1314],[1217,1218],[1217,1317],[1217,1316],[1219,1318],[1220,1221],[1220,1319],[1221,1321],[1226,1227],[1227,1327],[1231,1330],[1232,1233],[1233,1332],[1235,1335],[1239,1339],[1301,1302],[1301,1402],[1301,1401],[1302,1303],[1303,1404],[1304,1305],[1304,1405],[1309,1410],[1311,1411],[1314,1315],[1314,1415],[1314,1414],[1315,1316],[1316,1416],[1317,1318],[1317,1417],[1318,1319],[1318,1419],[1319,1419],[1321,1422],[1327,1428],[1327,1427],[1330,1430],[1332,1333],[1333,1434],[1333,1433],[1335,1435],[1339,1340],[1340,1341],[1340,1440],[1341,1441],[1400,1401],[1401,1500],[1402,1403],[1403,1503],[1404,1405],[1405,1406],[1405,1505],[1406,1407],[1407,1408],[1407,1506],[1408,1409],[1408,1508],[1409,1410],[1411,1511],[1414,1514],[1415,1416],[1416,1417],[1416,1516],[1417,1418],[1417,1516],[1418,1419],[1419,1420],[1419,1518],[1420,1520],[1422,1423],[1423,1522],[1427,1526],[1428,1528],[1430,1529],[1434,1435],[1434,1534],[1440,1441],[1440,1539],[1500,1601],[1505,1506],[1506,1607],[1508,1609],[1511,1612],[1512,1513],[1512,1612],[1513,1514],[1514,1515],[1514,1614],[1515,1516],[1516,1517],[1516,1617],[1517,1518],[1518,1618],[1520,1521],[1520,1621],[1521,1622],[1522,1622],[1528,1529],[1534,1635],[1539,1639],[1601,1602],[1601,1701],[1602,1603],[1605,1705],[1607,1608],[1607,1707],[1608,1708],[1609,1708],[1610,1709],[1612,1613],[1612,1711],[1613,1713],[1614,1713],[1617,1716],[1618,1619],[1618,1717],[1619,1719],[1621,1721],[1622,1623],[1622,1721],[1623,1723],[1623,1722],[1631,1731],[1631,1730],[1635,1636],[1636,1736],[1639,1738],[1701,1802],[1704,1805],[1705,1806],[1707,1807],[1708,1709],[1708,1809],[1709,1710],[1709,1810],[1710,1811],[1711,1812],[1713,1714],[1713,1813],[1714,1815],[1716,1717],[1716,1817],[1717,1718],[1718,1819],[1719,1720],[1720,1721],[1720,1821],[1720,1820],[1721,1822],[1722,1823],[1723,1724],[1724,1725],[1725,1726],[1725,1825],[1726,1727],[1727,1728],[1728,1729],[1728,1828],[1729,1830],[1730,1830],[1731,1732],[1732,1833],[1736,1737],[1737,1738],[1737,1838],[1737,1837],[1800,1801],[1801,1802],[1801,1901],[1802,1803],[1803,1903],[1805,1905],[1806,1906],[1806,1905],[1807,1906],[1809,1908],[1810,1909],[1811,1812],[1812,1813],[1812,1911],[1813,1913],[1813,1912],[1815,1915],[1817,1917],[1819,1820],[1820,1821],[1820,1919],[1821,1921],[1822,1922],[1823,1922],[1825,1925],[1828,1927],[1830,1831],[1830,1929],[1831,1931],[1833,1834],[1833,1932],[1834,1835],[1835,1836],[1836,1837],[1836,1935],[1838,1938],[1838,1937],[1901,2001],[1903,1904],[1903,2003],[1904,1905],[1905,1906],[1906,1907],[1906,2007],[1907,1908],[1908,1909],[1908,2009],[1909,1910],[1910,1911],[1911,1912],[1913,1914],[1914,1915],[1914,2015],[1915,1916],[1915,2015],[1916,1917],[1917,1918],[1917,2018],[1918,1919],[1919,1920],[1919,2019],[1920,2021],[1921,1922],[1922,1923],[1922,2023],[1923,1924],[1924,1925],[1925,1926],[1925,2026],[1926,1927],[1927,1928],[1927,2027],[1928,1929],[1929,2030],[1931,1932],[1931,2031],[1932,2033],[1935,2035],[1937,2037],[1938,1939],[1939,2039],[2000,2001],[2001,2101],[2001,2100],[2003,2103],[2007,2107],[2009,2109],[2015,2016],[2015,2114],[2016,2017],[2017,2117],[2018,2019],[2018,2117],[2019,2119],[2021,2121],[2023,2122],[2026,2027],[2026,2125],[2027,2127],[2030,2031],[2030,2129],[2035,2135],[2037,2136],[2039,2139],[2100,2200],[2101,2202],[2103,2203],[2107,2208],[2109,2210],[2114,2215],[2117,2118],[2117,2218],[2118,2219],[2119,2219],[2121,2222],[2122,2123],[2122,2222],[2123,2224],[2125,2225],[2127,2228],[2128,2129],[2128,2228],[2129,2230],[2133,2234],[2133,2233],[2135,2236],[2136,2236],[2139,2240],[2200,2300],[2202,2203],[2203,2303],[2203,2302],[2208,2308],[2210,2309],[2215,2314],[2218,2317],[2219,2220],[2219,2319],[2220,2320],[2222,2223],[2222,2322],[2222,2321],[2223,2323],[2223,2322],[2224,2225],[2225,2226],[2225,2324],[2226,2227],[2226,2326],[2227,2228],[2230,2329],[2233,2332],[2234,2333],[2236,2237],[2236,2336],[2237,2337],[2240,2339],[2300,2400],[2302,2403],[2303,2404],[2307,2308],[2307,2407],[2308,2409],[2309,2410],[2314,2414],[2315,2316],[2315,2415],[2316,2317],[2317,2418],[2319,2420],[2320,2321],[2321,2322],[2321,2421],[2322,2323],[2322,2423],[2322,2422],[2323,2324],[2324,2325],[2325,2425],[2326,2427],[2327,2328],[2327,2427],[2328,2329],[2329,2430],[2332,2432],[2333,2434],[2336,2337],[2336,2436],[2337,2438],[2339,2340],[2339,2440],[2340,2441],[2400,2500],[2403,2502],[2404,2405],[2404,2504],[2405,2406],[2405,2504],[2406,2407],[2409,2509],[2410,2509],[2414,2513],[2415,2514],[2418,2518],[2418,2517],[2420,2519],[2421,2422],[2421,2521],[2421,2520],[2423,2424],[2423,2522],[2424,2425],[2425,2525],[2427,2527],[2430,2431],[2430,2530],[2430,2529],[2431,2432],[2431,2530],[2434,2534],[2436,2536],[2436,2535],[2437,2438],[2437,2537],[2437,2536],[2438,2439],[2439,2440],[2440,2539],[2441,2541],[2500,2501],[2500,2601],[2501,2502],[2502,2503],[2502,2603],[2503,2504],[2503,2604],[2509,2610],[2513,2613],[2514,2615],[2517,2618],[2518,2619],[2519,2520],[2519,2620],[2519,2619],[2521,2522],[2522,2623],[2525,2526],[2526,2627],[2526,2626],[2527,2628],[2529,2530],[2529,2630],[2530,2531],[2531,2632],[2534,2535],[2534,2635],[2534,2634],[2536,2636],[2537,2638],[2539,2640],[2601,2701],[2601,2700],[2603,2702],[2604,2605],[2604,2704],[2605,2606],[2605,2705],[2605,2704],[2606,2607],[2607,2608],[2608,2609],[2609,2610],[2609,2708],[2610,2710],[2613,2713],[2613,2712],[2615,2714],[2618,2619],[2619,2719],[2620,2621],[2621,2721],[2623,2723],[2626,2726],[2626,2725],[2627,2628],[2628,2728],[2630,2730],[2632,2633],[2633,2733],[2634,2733],[2635,2636],[2635,2735],[2636,2736],[2638,2639],[2639,2739],[2640,2740],[2701,2702],[2701,2802],[2702,2703],[2702,2803],[2702,2802],[2703,2704],[2705,2805],[2708,2809],[2710,2811],[2710,2810],[2712,2812],[2713,2714],[2714,2715],[2715,2716],[2715,2815],[2719,2720],[2720,2721],[2721,2722],[2722,2823],[2723,2724],[2723,2823],[2724,2825],[2725,2825],[2726,2827],[2728,2729],[2729,2830],[2729,2829],[2730,2731],[2730,2831],[2731,2732],[2732,2733],[2733,2834],[2733,2833],[2735,2836],[2736,2836],[2739,2840],[2740,2840],[2800,2801],[2801,2901],[2802,2902],[2803,2903],[2805,2806],[2806,2906],[2809,2810],[2810,2909],[2811,2911],[2812,2911],[2814,2815],[2814,2913],[2818,2819],[2818,2917],[2819,2919],[2825,2826],[2825,2925],[2826,2827],[2827,2828],[2828,2829],[2829,2928],[2830,2930],[2831,2832],[2831,2930],[2832,2932],[2833,2932],[2834,2835],[2835,2935],[2836,2935],[2840,2940],[2840,2939],[2901,2902],[2902,3002],[2903,3004],[2906,3007],[2909,2910],[2909,3009],[2910,2911],[2911,2912],[2911,3012],[2911,3011],[2912,2913],[2913,2914],[2914,2915],[2915,2916],[2916,3017],[2917,3018],[2919,3020],[2925,3026],[2928,3028],[2930,2931],[2930,3030],[2931,2932],[2932,2933],[2932,3033],[2933,2934],[2934,3035],[2935,2936],[2935,3036],[2936,2937],[2937,3038],[2939,3039],[2940,3040],[3000,3001],[3001,3002],[3001,3101],[3001,3100],[3002,3003],[3002,3102],[3003,3004],[3003,3103],[3004,3005],[3005,3006],[3006,3007],[3007,3008],[3007,3106],[3008,3009],[3008,3108],[3011,3111],[3012,3013],[3012,3112],[3013,3113],[3017,3018],[3017,3117],[3018,3019],[3018,3117],[3019,3119],[3020,3120],[3022,3122],[3022,3121],[3024,3124],[3024,3123],[3026,3125],[3028,3127],[3030,3031],[3030,3129],[3031,3130],[3033,3133],[3035,3036],[3035,3135],[3036,3037],[3037,3038],[3037,3137],[3037,3136],[3038,3039],[3039,3138],[3040,3140],[3100,3200],[3101,3202],[3102,3203],[3103,3204],[3103,3203],[3106,3107],[3107,3208],[3108,3208],[3111,3211],[3112,3213],[3113,3114],[3114,3215],[3116,3117],[3116,3216],[3119,3120],[3120,3121],[3122,3123],[3124,3125],[3125,3126],[3125,3226],[3126,3127],[3127,3227],[3129,3230],[3129,3229],[3130,3231],[3133,3234],[3134,3135],[3134,3234],[3135,3136],[3135,3236],[3137,3138],[3138,3139],[3138,3238],[3139,3140],[3140,3241],[3140,3240],[3202,3203],[3202,3302],[3202,3301],[3203,3303],[3204,3304],[3206,3306],[3206,3305],[3208,3308],[3211,3311],[3213,3313],[3215,3216],[3216,3316],[3226,3326],[3227,3326],[3228,3229],[3228,3328],[3228,3327],[3230,3231],[3231,3232],[3231,3331],[3232,3233],[3233,3333],[3234,3334],[3234,3333],[3236,3237],[3237,3337],[3238,3337],[3240,3339],[3300,3301],[3301,3302],[3301,3402],[3302,3303],[3302,3402],[3303,3304],[3303,3404],[3304,3305],[3304,3405],[3306,3407],[3308,3408],[3311,3412],[3311,3411],[3313,3414],[3313,3413],[3316,3417],[3316,3416],[3319,3320],[3319,3419],[3320,3321],[3321,3422],[3326,3327],[3326,3426],[3327,3428],[3328,3428],[3331,3432],[3333,3434],[3334,3435],[3336,3337],[3336,3436],[3337,3338],[3338,3339],[3338,3438],[3339,3440],[3339,3439],[3402,3502],[3402,3501],[3404,3504],[3404,3503],[3405,3505],[3407,3408],[3408,3507],[3410,3411],[3411,3511],[3411,3510],[3412,3413],[3412,3512],[3413,3513],[3414,3514],[3416,3515],[3417,3418],[3418,3419],[3422,3423],[3423,3523],[3426,3526],[3428,3528],[3432,3532],[3433,3434],[3433,3532],[3435,3436],[3436,3535],[3439,3539],[3440,3540],[3441,3540],[3501,3602],[3502,3603],[3503,3603],[3504,3605],[3505,3606],[3505,3605],[3507,3608],[3509,3510],[3509,3609],[3511,3512],[3512,3613],[3513,3614],[3514,3615],[3515,3516],[3515,3616],[3516,3617],[3523,3524],[3524,3525],[3525,3526],[3526,3626],[3528,3628],[3531,3532],[3531,3631],[3532,3633],[3535,3636],[3535,3635],[3539,3540],[3539,3640],[3540,3541],[3602,3701],[3603,3703],[3605,3705],[3606,3607],[3607,3608],[3608,3708],[3609,3708],[3613,3614],[3613,3713],[3614,3615],[3614,3713],[3615,3616],[3615,3715],[3616,3715],[3617,3717],[3626,3725],[3628,3728],[3630,3631],[3630,3729],[3633,3634],[3633,3732],[3634,3635],[3635,3636],[3635,3734],[3636,3736],[3640,3740],[3700,3801],[3701,3801],[3703,3804],[3704,3705],[3704,3804],[3705,3805],[3708,3709],[3708,3808],[3709,3710],[3710,3711],[3711,3812],[3711,3811],[3712,3713],[3712,3813],[3713,3814],[3714,3715],[3714,3814],[3715,3816],[3715,3815],[3717,3718],[3718,3819],[3718,3818],[3719,3720],[3719,3819],[3720,3721],[3721,3722],[3722,3723],[3722,3822],[3723,3724],[3723,3824],[3724,3825],[3728,3729],[3728,3828],[3729,3730],[3729,3829],[3730,3731],[3731,3732],[3731,3832],[3734,3834],[3736,3836],[3740,3841],[3801,3802],[3802,3803],[3802,3901],[3803,3903],[3804,3903],[3805,3905],[3808,3908],[3808,3907],[3811,3911],[3812,3813],[3813,3814],[3814,3914],[3814,3913],[3815,3915],[3816,3817],[3817,3917],[3818,3917],[3819,3919],[3822,3921],[3824,3924],[3825,3925],[3827,3828],[3828,3829],[3828,3927],[3829,3929],[3832,3932],[3834,3933],[3836,3935],[3840,3841],[3840,3939],[3841,3940],[3900,3901],[3900,4001],[3900,4000],[3903,3904],[3903,4003],[3904,4005],[3905,4006],[3905,4005],[3906,3907],[3906,4006],[3908,4008],[3911,4012],[3913,4014],[3914,3915],[3915,4015],[3917,4018],[3917,4017],[3919,4020],[3919,4019],[3921,4022],[3924,3925],[3925,4026],[3925,4025],[3927,4028],[3929,4029],[3932,4032],[3933,4034],[3934,3935],[3934,4034],[3935,3936],[3935,4036],[3936,4037],[3938,3939],[3938,4038],[3940,4041],[4002,4003],[4005,4006],[4016,4017],[4018,4019],[4037,4038]]
const rivers = [[1012,1013],[1013,1113],[1013,1112],[1014,1113],[1018,1118],[1019,1119],[1019,1118],[1020,1119],[1038,1039],[1039,1138],[1113,1114],[1114,1214],[1116,1217],[1117,1118],[1117,1218],[1117,1217],[1119,1120],[1120,1221],[1120,1220],[1121,1221],[1138,1139],[1138,1239],[1214,1215],[1215,1315],[1215,1314],[1216,1217],[1216,1316],[1216,1315],[1221,1222],[1222,1322],[1222,1321],[1223,1323],[1223,1322],[1238,1239],[1238,1338],[1323,1324],[1323,1424],[1324,1425],[1325,1425],[1337,1338],[1337,1438],[1423,1424],[1423,1523],[1424,1425],[1424,1524],[1425,1426],[1426,1525],[1427,1527],[1428,1527],[1430,1530],[1431,1530],[1432,1532],[1433,1532],[1437,1438],[1437,1537],[1522,1523],[1523,1524],[1523,1624],[1523,1623],[1525,1526],[1525,1626],[1526,1527],[1526,1627],[1527,1528],[1528,1629],[1528,1628],[1529,1530],[1529,1629],[1530,1531],[1530,1630],[1531,1532],[1531,1632],[1531,1631],[1532,1533],[1533,1634],[1533,1633],[1534,1634],[1536,1537],[1537,1637],[1625,1626],[1626,1627],[1626,1726],[1626,1725],[1628,1629],[1629,1630],[1630,1631],[1630,1730],[1630,1729],[1634,1635],[1635,1735],[1635,1734],[1636,1735],[1637,1638],[1637,1737],[1638,1737],[1735,1736],[1736,1737],[1736,1837],[1736,1836],[1737,1738],[1738,1839],[1738,1838],[1739,1840],[1739,1839],[1740,1840],[1840,1841],[1841,1941],[1841,1940],
[1224,1323],
]
const split_roads = [
[ 1603, 1604, 1704 ], [ 1503, 1604, 1605 ],
[ 1221, 1120, 1020 ], [ 1121, 1120, 1021 ],
[ 1410, 1510, 1610 ], [ 1410, 1510, 1511 ],
[ 2035, 2034, 2033 ], [ 2035, 2034, 2133 ],
[ 2529, 2629, 2628 ], [ 2529, 2629, 2729 ],
[ 2618, 2717, 2818 ], [ 2618, 2717, 2716 ],
[ 3129, 3029, 2928 ], [ 3129, 3029, 3028 ],
[ 3408, 3409, 3410 ], [ 3408, 3409, 3509 ],
[ 3925, 3826, 3827 ], [ 3925, 3826, 3725 ],
]
let open_roads = []
let count = new Array(4042).fill(0)
let ends = crossroads.slice()
const bridges = []
for (let [a,b] of road_segments) {
for (let [c,d] of rivers)
if (a === c && b === d)
bridges.push([a,b])
}
for (let road of split_roads) {
for (let i = 1; i < road.length; ++i) {
let a = road[i-1]
let b = road[i]
for (let [c,d] of rivers)
if ((a === c && b === d) || (a===d && b===c))
bridges.push([a,b])
}
}
// remove trouble
// road_segments = road_segments.filter(([from,to]) => !splits.includes(from) && !splits.includes(to))
for (let [from,to] of road_segments) {
count[from]++
count[to]++
}
for (let i = 0 ; i < 4042; ++i) {
if (count[i] > 2) {
if (!crossroads.includes(i) && !splits.includes(i))
console.log("UNMARKED XROAD", i)
}
if (count[i] === 1)
ends.push(i)
}
let segments = road_segments.slice()
function has_road(x) {
for (let [a,b] of segments)
if (x === a || x === b)
return true
return false
}
for (let x of ends) {
while (has_road(x))
open_roads.push(create_road(x))
}
function create_road(a) {
let road = [ a ]
grow_road(road)
return road
}
function grow_road(road) {
let tail = road[road.length-1]
let head = road[0]
if (road.length > 1 && ends.includes(tail))
tail = -1
if (road.length > 1 && ends.includes(head))
head = -1
for (let i = 0; i < segments.length; ++i) {
let [a, b] = segments[i]
if (tail === a) {
segments.splice(i, 1)
road.push(b)
if (!ends.includes(b)) grow_road(road)
return
}
if (tail === b) {
segments.splice(i, 1)
road.push(a)
if (!ends.includes(a)) grow_road(road)
return
}
if (head === a) {
segments.splice(i, 1)
road.unshift(b)
if (!ends.includes(b)) grow_road(road)
return
}
if (head === b) {
segments.splice(i, 1)
road.unshift(a)
if (!ends.includes(a)) grow_road(road)
return
}
}
}
console.log("roads: " + JSON.stringify(open_roads.concat(split_roads)) + ",")
console.log("bridges: " + JSON.stringify(bridges) + ",")
console.log(segments)
|