Chelover_C60
本帖最后由 Chelover_C60 于 2021-11-9 12:14 编辑

0 常见问题



Q:什么是四色定理?
A:引自百度百科,四色定理是
“任何一张地图只用四种颜色就能使具有共同边界的国家着上不同的颜色。”也就是说在不引起混淆的情况下一张地图只需四种颜色来标记就行。

Q:这个帖子和数据包是干啥的?
A:这个数据包的功能是,通过命令生成画板,经过玩家手动摆放黑色混凝土绘制出图形轮廓,然后系统自动分析轮廓并依据四色定理进行填充。该算法只会尝试寻找其中的一个解,而不会尝试寻找所有解。本帖讲述的就是这个数据包的工作原理。

Q:这个数据包可以做你画我猜,或者给图形上色吗?
A:不可以,这个数据包只具备填色功能,不具备绘图功能,而想要绘图则只能通过玩家手动放置。且填色功能只能依据一种特定算法填充,不能手动决定填充方式。算法的目的是进行四色填充,而不是绘制图形。

Q:这个数据包可以做色盲派对吗?
A:不可以,该数据包虽然能够进行填色,但只会尝试借助四色定理寻找其中的一个解。其只会尝试使用四种颜色进行填充,不会使用五种或更多的颜色填充,填充时的颜色分布不一定均匀,且进行填色时需要手动绘制轮廓。其目的是进行四色填充,而不是还原小游戏。

Q:我可以在这个帖子里回复“MCBBS有你更精彩”或者复制别人的回复吗?
A:不可以,依据版规,如果你进行此类回复,你会被版主警告并扣除10金粒、1人气。

Q:我都知道了,怎么才能看正文呢?
A:点击上方目录中的标题,即可切换到对应页面。

2021.12 数据,可能有更多内容
1 前言

   首先说一下为什么我会突然想到用命令来实现四色定理的自动填充。前一段时间我偶然看到一本书,里面讲到了四色定理,于是我偶然想到了是否可以用四色定理做一张小游戏地图。然后我把我的想法在某个群里说了下。现在到了假期,我又想到这个事,然后就突然想到有没有可能通过命令实现四色定理的自动填充,经过思考后,我大概想到了一种可能的填充算法,于是决定尝试实践一下。
   花了两天时间,我基本上完成了这个算法,并修复了已知的问题。以下是我的成果。
   可以看到,填充的结果还是比较理想的。虽然执行的命令数可能有点多。
   求解过程中,使用到了storage,使用了大量穷举和递归遍历,仅使用一个定位marker。穷举部分只穷举了64次,因此如果区域数量超过了64,可能就无法进行正常填充了。



2 数据包及其使用方法

   废话不多说,上数据包
   数据包于1.15.2编写,理论上支持1.15+
   使用方法:
   建立一个经典超平坦存档,开启作弊,并安装数据包。
   数据包的安装方法请参见https://www.mcbbs.net/thread-912853-1-1.html
   安装好后,进入世界或输入 /reload 以加载数据包。
   由于数据包的计算量比较大,因此请调大每刻可执行的命令数,建议至少为800000。使用命令 /gamerule maxCommandChainLength 800000 可修改每刻可执行的命令数。
   一切就绪后,输入 /function 4_color_theorem:init 进行初始化。这会建立必要记分板,并生成一个用于定位的药水云,同时生成用于绘图的画板。
   然后从背包中拿取黑色混凝土方块(注意必须使用该方块,因为边界判定依据的就是这个方块),在底板上摆放成任意的,可用于四色填充的图案。
   注意:由于数据包中部分分析为穷举分析,因此请确保分区不要超过64个!
   摆放完成后,执行 /function 4_color_theorem:main 即可进行自动填充。

其他的一些命令:
/function 4_color_theorem:clear_storage 可用于清除storage,一般不需要手动执行。
/function 4_color_theorem:clear_fill 可用于清除画板上的蓝、绿、黄、红色的填充而对边界没有影响。
/function 4_color_theorem:clear_board 可用于清除画板上的所有物品,包括各种颜色的填充和边界。



3 数据包工作流程

   数据包的整体工作流程大概如下图所示
   其中初始化信息,其实就是清理一下画板,再清理一下storage,没啥值得讲的,所以就不详细说明了。其他各个区域的工作原理会在对应章节叙述。
   本部分仅讲述实现思路与具体实现的相关函数,不会对具体命令进行讲解。有兴趣的可以自行下载数据包进行拆包研究。



3.1 区域识别

   要想知道一个区域的填充方式,首先要做的就是知道这个区域在哪,有多大的规模。同时为了便于计算,最好要有一个编号
   如果知道了一个区域的形状、大小和规模的话,那么进行逻辑分析时就好很多了。
   这里我使用了两个递归函数嵌套穷举x与z来进行逐个方块进行分析,判断这是否是一个新的区域。如果这是一个已经识别过的区域,那么就会跳过这个方块而去分析下一个方块。如果是一个没有识别的新区域,则会试图分析它的形状,以及它的边界。
   区域识别的过程大致如下图所示。其中白色表示未识别的区域,灰色表示已识别的区域,黑色为边界,红色为当前正在判定的区域。


相关函数:
4_color_theorem:reigon/detectx 沿x轴方向遍历的递归函数
scoreboard players set z 4_color_theorem 1
function 4_color_theorem:reigon/detectz
scoreboard players add x 4_color_theorem 1
execute if score x 4_color_theorem matches ..64 positioned ~1 ~ ~ run function 4_color_theorem:reigon/detectx

4_color_theorem:reigon/detectz 沿z轴方向遍历的递归函数
execute if block ~ ~ ~ air run function 4_color_theorem:reigon/number
scoreboard players add z 4_color_theorem 1
execute if score z 4_color_theorem matches ..64 positioned ~ ~ ~1 run function 4_color_theorem:reigon/detectz



3.1.1 区域填充

   由于区域是使用者任意搭建的,极有可能是边界不规则的图形,因此要对区域进行判定只能一个一个方块地进行判定。
   当上述两个递归函数发现了一个空气方块时,说明遇到了一个暂未分析过的新区域,于是开始对该区域进行识别。采用深度优先搜索(DFS)的方式,首先在该位置放置白色混凝土,并以该点为基点,向东、南、西、北四个方向分别检测。若检测结果为空气,则在该位置放置白色混凝土,并以该点为基点进行同样操作。如果检测结果为黑色混凝土,则说明碰到了边界,此时在边界上方也放置一个黑色混凝土(重要,后面要用到)。这样反复n次后,这个区域就会被填满白色混凝土,同时它的边界也会变高一格,效果如下图所示(可能不太明显)。

   填充过程的示意图大致可以用下图展示,其中白色块表示空气,黑色块表示黑色混凝土,蓝色块表示基准点(同时表示已填充的白色混凝土),灰色块表示已填充的白色混凝土(不再作为基准点)

相关函数:
4_color_theorem:fill 进行填充的函数
setblock ~ ~ ~ white_concrete
execute positioned ~1 ~ ~ if block ~ ~ ~ air run function 4_color_theorem:fill/xp
execute positioned ~-1 ~ ~ if block ~ ~ ~ air run function 4_color_theorem:fill/xd
execute positioned ~ ~ ~1 if block ~ ~ ~ air run function 4_color_theorem:fill/zp
execute positioned ~ ~ ~-1 if block ~ ~ ~ air run function 4_color_theorem:fill/zd
execute positioned ~1 ~ ~ if block ~ ~ ~ black_concrete run setblock ~ ~1 ~ black_concrete
execute positioned ~-1 ~ ~ if block ~ ~ ~ black_concrete run setblock ~ ~1 ~ black_concrete
execute positioned ~ ~ ~1 if block ~ ~ ~ black_concrete run setblock ~ ~1 ~ black_concrete
execute positioned ~ ~ ~-1 if block ~ ~ ~ black_concrete run setblock ~ ~1 ~ black_concrete

4_color_theorem:fill/xd 进行填充的函数,但不向x轴正方向检测
setblock ~ ~ ~ white_concrete
execute positioned ~-1 ~ ~ if block ~ ~ ~ air run function 4_color_theorem:fill/xd
execute positioned ~ ~ ~1 if block ~ ~ ~ air run function 4_color_theorem:fill/zp
execute positioned ~ ~ ~-1 if block ~ ~ ~ air run function 4_color_theorem:fill/zd
execute positioned ~-1 ~ ~ if block ~ ~ ~ black_concrete run setblock ~ ~1 ~ black_concrete
execute positioned ~ ~ ~1 if block ~ ~ ~ black_concrete run setblock ~ ~1 ~ black_concrete
execute positioned ~ ~ ~-1 if block ~ ~ ~ black_concrete run setblock ~ ~1 ~ black_concrete

4_color_theorem:fill/zd 进行填充的函数,但不向z轴正方向检测
setblock ~ ~ ~ white_concrete
execute positioned ~1 ~ ~ if block ~ ~ ~ air run function 4_color_theorem:fill/xp
execute positioned ~-1 ~ ~ if block ~ ~ ~ air run function 4_color_theorem:fill/xd
execute positioned ~ ~ ~-1 if block ~ ~ ~ air run function 4_color_theorem:fill/zd
execute positioned ~1 ~ ~ if block ~ ~ ~ black_concrete run setblock ~ ~1 ~ black_concrete
execute positioned ~-1 ~ ~ if block ~ ~ ~ black_concrete run setblock ~ ~1 ~ black_concrete
execute positioned ~ ~ ~-1 if block ~ ~ ~ black_concrete run setblock ~ ~1 ~ black_concrete

4_color_theorem:fill/xp 进行填充的函数,但不向x轴负方向检测
setblock ~ ~ ~ white_concrete
execute positioned ~1 ~ ~ if block ~ ~ ~ air run function 4_color_theorem:fill/xp
execute positioned ~ ~ ~1 if block ~ ~ ~ air run function 4_color_theorem:fill/zp
execute positioned ~ ~ ~-1 if block ~ ~ ~ air run function 4_color_theorem:fill/zd
execute positioned ~1 ~ ~ if block ~ ~ ~ black_concrete run setblock ~ ~1 ~ black_concrete
execute positioned ~ ~ ~1 if block ~ ~ ~ black_concrete run setblock ~ ~1 ~ black_concrete
execute positioned ~ ~ ~-1 if block ~ ~ ~ black_concrete run setblock ~ ~1 ~ black_concrete

4_color_theorem:fill/zp 进行填充的函数,但不向z轴负方向检测
setblock ~ ~ ~ white_concrete
execute positioned ~1 ~ ~ if block ~ ~ ~ air run function 4_color_theorem:fill/xp
execute positioned ~-1 ~ ~ if block ~ ~ ~ air run function 4_color_theorem:fill/xd
execute positioned ~ ~ ~1 if block ~ ~ ~ air run function 4_color_theorem:fill/zp
execute positioned ~1 ~ ~ if block ~ ~ ~ black_concrete run setblock ~ ~1 ~ black_concrete
execute positioned ~-1 ~ ~ if block ~ ~ ~ black_concrete run setblock ~ ~1 ~ black_concrete
execute positioned ~ ~ ~1 if block ~ ~ ~ black_concrete run setblock ~ ~1 ~ black_concrete





3.1.2 区域编号

   这里的编号方式,我采用的是使用y轴进行编号。
   在区域识别结束后,将填充的白色混凝土向上复制一层,并将原本填充的那一层替换为灰色混凝土。这样这个区域的形状、规模与边界信息就会被提取并分离出来,同时不会影响下一个区域的识别。但是为了做好区分,并且为了避免与下一次提取后的结果重叠在一起,因此还需要再向上移动一段距离,如下图所示
   对于第一个区域,提取好后,仅需要向上移动一格即可做到不影响第二次提取。而第二个区域,则需要向上移动两格。这里我采用了一个递归函数4_color_theorem:reigon/move,使用execute positioned来调整命令执行的y坐标基准点。若当前区域为第一个区域,则向上移动一格后执行clone操作;若是第二个区域,则两次向上移动一格后执行clone,以此类推。这样反复执行了几次后,整体的效果应该是这样的。
   至于编号嘛。。。我可以说y轴就是编号吗?

相关函数:
4_color_theorem:reigon/number 计算区域编号的函数
function 4_color_theorem:reigon/recog
scoreboard players add reigon_count 4_color_theorem 1
scoreboard players operation reigon_id 4_color_theorem = reigon_count 4_color_theorem
execute at @e[type=area_effect_cloud,tag=4_color_theorem positioned ~ ~1 ~ run function 4_color_theorem:reigon/move

4_color_theorem:reigon/recog 提取区域并将底部填充为灰色的函数
function 4_color_theorem:fill
execute at @e[type=area_effect_cloud,tag=4_color_theorem run clone ~1 ~ ~1 ~64 ~ ~64 ~1 ~1 ~1 filtered white_concrete
execute at @e[type=area_effect_cloud,tag=4_color_theorem run fill ~1 ~ ~1 ~64 ~ ~64 gray_concrete replace white_concrete

4_color_theorem:reigon/move 将区域向上移动的递归函数
scoreboard players remove reigon_id 4_color_theorem 1
execute if score reigon_id 4_color_theorem matches -1 run clone ~ 6 ~ ~65 6 ~65 ~ ~ ~ masked move
execute if score reigon_id 4_color_theorem matches 0.. positioned ~ ~1 ~ run function 4_color_theorem:reigon/move





3.2 相邻区域记录

   现在我们已经能够识别出来不同区域的形状、规模、边界了,甚至可以直接使用y轴作为其编号,那么接下来,就可以对相邻区域进行判定,便于后期的计算了。
   相邻区域记录的流程大致是这样的
   而要开始边界判定,依然要遍历画板上的方块。这里我又使用了两个递归函数进行遍历。与上一次不同的是,这一次遍历的目标是黑色混凝土。当遍历到黑色混凝土之后,说明检测到了边界,此时就可以进行边界判定了。

相关函数:
4_color_theorem:border_recog/detectx 沿x轴方向遍历的递归函数
scoreboard players set z 4_color_theorem 1
function 4_color_theorem:border_recog/detectz
scoreboard players add x 4_color_theorem 1
execute if score x 4_color_theorem matches ..64 positioned ~1 ~ ~ run function 4_color_theorem:border_recog/detectx

4_color_theorem:border_recog/detectz 沿z轴方向遍历的递归函数
execute if block ~ ~ ~ black_concrete run function 4_color_theorem:border_recog/detectborder
scoreboard players add z 4_color_theorem 1
execute if score z 4_color_theorem matches ..64 positioned ~ ~ ~1 run function 4_color_theorem:border_recog/detectz





3.2.1 边界判定

   由于之前将所有区域的边界均识别了出来,编好号并放置在不同的y坐标上,因此只需要识别y轴哪个地方有黑色混凝土,就说明哪几个区域在共用这个边界。于是在3.2中水平面上检测到黑色混凝土后,暂停水平方向上的遍历,改为竖直向上遍历,一旦碰到黑色混凝土,则可认定该层的区域使用这个边界。如此反复即可认定哪些区域在使用这个边界,即哪几个区域在此处相邻。
   识别过程可参考下图所示gif,其中红色为水平方向正在检测的方块,绿色表示竖直方向上的检测。当遇到黑色混凝土后即向上遍历,并记录y值,以此进行相邻区域识别。


相关函数:
4_color_theorem:border_recog/detectborder 检测到黑色混凝土后的初始化函数
scoreboard players set y 4_color_theorem 1
execute positioned ~ ~2 ~ run function 4_color_theorem:border_recog/detecty

4_color_theorem:border_recog/detecty 沿y轴方向遍历的递归函数
execute if block ~ ~ ~ black_concrete run function 4_color_theorem:border_recog/record
scoreboard players add y 4_color_theorem 1
execute if score y 4_color_theorem > reigon_count 4_color_theorem run function 4_color_theorem:border_recog/merge
execute if score y 4_color_theorem <= reigon_count 4_color_theorem positioned ~ ~1 ~ run function 4_color_theorem:border_recog/detecty



3.2.2 结果记录

   检测到了相邻区域后,接下来要做的就是把它们记录下来。
   这里我没有想到什么免穷举或者不使用nbt的方法,只好硬着头皮用了,不过性能似乎没我想象的那么差。
   当向上遍历到黑色混凝土时,检测当前的y值,并在nbt Temp里将该值记录为1b。比如,在y=1和y=2处检测到了黑色混凝土,说明区域1和区域2在此处相邻,Temp的值就是 {1:1b,2:1b} 。该功能由函数4_color_theorem:border_recog/record 穷举实现(穷举yyds!)。当遍历完一个边界后,检测Temp里的内容。在上面的例子中,Temp里有1和2,于是就使用Temp来覆盖Record.1个Record.2。该功能由函数 4_color_theorem:border_recog/merge 穷举实现。如此一来,就能够在Record里知道1和2是相邻的,2和1也是相邻的了。如此反复遍历后,会得到如下图所示的结果:
   解释一下,在Record中,11里包含了11,12,13,6,7,除去自身后有6,7,12,13四个区域,说明11和这4个区域是相邻的,后续计算中需要保证11的颜色和另外四个区域的颜色不一样。

相关函数:
4_color_theorem:border_recog/detecty 沿y轴方向遍历的递归函数
execute if block ~ ~ ~ black_concrete run function 4_color_theorem:border_recog/record
scoreboard players add y 4_color_theorem 1
execute if score y 4_color_theorem > reigon_count 4_color_theorem run function 4_color_theorem:border_recog/merge
execute if score y 4_color_theorem <= reigon_count 4_color_theorem positioned ~ ~1 ~ run function 4_color_theorem:border_recog/detecty

4_color_theorem:border_recog/record 用于向Temp里记录共用某边界的区域的穷举函数
execute if score y 4_color_theorem matches 1 run data merge storage 4_color_theorem {Temp:{1:1b}}
execute if score y 4_color_theorem matches 2 run data merge storage 4_color_theorem {Temp:{2:1b}}
execute if score y 4_color_theorem matches 3 run data merge storage 4_color_theorem {Temp:{3:1b}}
execute if score y 4_color_theorem matches 4 run data merge storage 4_color_theorem {Temp:{4:1b}}
execute if score y 4_color_theorem matches 5 run data merge storage 4_color_theorem {Temp:{5:1b}}
execute if score y 4_color_theorem matches 6 run data merge storage 4_color_theorem {Temp:{6:1b}}
execute if score y 4_color_theorem matches 7 run data merge storage 4_color_theorem {Temp:{7:1b}}
execute if score y 4_color_theorem matches 8 run data merge storage 4_color_theorem {Temp:{8:1b}}
execute if score y 4_color_theorem matches 9 run data merge storage 4_color_theorem {Temp:{9:1b}}
execute if score y 4_color_theorem matches 10 run data merge storage 4_color_theorem {Temp:{10:1b}}
execute if score y 4_color_theorem matches 11 run data merge storage 4_color_theorem {Temp:{11:1b}}
execute if score y 4_color_theorem matches 12 run data merge storage 4_color_theorem {Temp:{12:1b}}
execute if score y 4_color_theorem matches 13 run data merge storage 4_color_theorem {Temp:{13:1b}}
execute if score y 4_color_theorem matches 14 run data merge storage 4_color_theorem {Temp:{14:1b}}
execute if score y 4_color_theorem matches 15 run data merge storage 4_color_theorem {Temp:{15:1b}}
execute if score y 4_color_theorem matches 16 run data merge storage 4_color_theorem {Temp:{16:1b}}
execute if score y 4_color_theorem matches 17 run data merge storage 4_color_theorem {Temp:{17:1b}}
execute if score y 4_color_theorem matches 18 run data merge storage 4_color_theorem {Temp:{18:1b}}
execute if score y 4_color_theorem matches 19 run data merge storage 4_color_theorem {Temp:{19:1b}}
execute if score y 4_color_theorem matches 20 run data merge storage 4_color_theorem {Temp:{20:1b}}
execute if score y 4_color_theorem matches 21 run data merge storage 4_color_theorem {Temp:{21:1b}}
execute if score y 4_color_theorem matches 22 run data merge storage 4_color_theorem {Temp:{22:1b}}
execute if score y 4_color_theorem matches 23 run data merge storage 4_color_theorem {Temp:{23:1b}}
execute if score y 4_color_theorem matches 24 run data merge storage 4_color_theorem {Temp:{24:1b}}
execute if score y 4_color_theorem matches 25 run data merge storage 4_color_theorem {Temp:{25:1b}}
execute if score y 4_color_theorem matches 26 run data merge storage 4_color_theorem {Temp:{26:1b}}
execute if score y 4_color_theorem matches 27 run data merge storage 4_color_theorem {Temp:{27:1b}}
execute if score y 4_color_theorem matches 28 run data merge storage 4_color_theorem {Temp:{28:1b}}
execute if score y 4_color_theorem matches 29 run data merge storage 4_color_theorem {Temp:{29:1b}}
execute if score y 4_color_theorem matches 30 run data merge storage 4_color_theorem {Temp:{30:1b}}
execute if score y 4_color_theorem matches 31 run data merge storage 4_color_theorem {Temp:{31:1b}}
execute if score y 4_color_theorem matches 32 run data merge storage 4_color_theorem {Temp:{32:1b}}
execute if score y 4_color_theorem matches 33 run data merge storage 4_color_theorem {Temp:{33:1b}}
execute if score y 4_color_theorem matches 34 run data merge storage 4_color_theorem {Temp:{34:1b}}
execute if score y 4_color_theorem matches 35 run data merge storage 4_color_theorem {Temp:{35:1b}}
execute if score y 4_color_theorem matches 36 run data merge storage 4_color_theorem {Temp:{36:1b}}
execute if score y 4_color_theorem matches 37 run data merge storage 4_color_theorem {Temp:{37:1b}}
execute if score y 4_color_theorem matches 38 run data merge storage 4_color_theorem {Temp:{38:1b}}
execute if score y 4_color_theorem matches 39 run data merge storage 4_color_theorem {Temp:{39:1b}}
execute if score y 4_color_theorem matches 40 run data merge storage 4_color_theorem {Temp:{40:1b}}
execute if score y 4_color_theorem matches 41 run data merge storage 4_color_theorem {Temp:{41:1b}}
execute if score y 4_color_theorem matches 42 run data merge storage 4_color_theorem {Temp:{42:1b}}
execute if score y 4_color_theorem matches 43 run data merge storage 4_color_theorem {Temp:{43:1b}}
execute if score y 4_color_theorem matches 44 run data merge storage 4_color_theorem {Temp:{44:1b}}
execute if score y 4_color_theorem matches 45 run data merge storage 4_color_theorem {Temp:{45:1b}}
execute if score y 4_color_theorem matches 46 run data merge storage 4_color_theorem {Temp:{46:1b}}
execute if score y 4_color_theorem matches 47 run data merge storage 4_color_theorem {Temp:{47:1b}}
execute if score y 4_color_theorem matches 48 run data merge storage 4_color_theorem {Temp:{48:1b}}
execute if score y 4_color_theorem matches 49 run data merge storage 4_color_theorem {Temp:{49:1b}}
execute if score y 4_color_theorem matches 50 run data merge storage 4_color_theorem {Temp:{50:1b}}
execute if score y 4_color_theorem matches 51 run data merge storage 4_color_theorem {Temp:{51:1b}}
execute if score y 4_color_theorem matches 52 run data merge storage 4_color_theorem {Temp:{52:1b}}
execute if score y 4_color_theorem matches 53 run data merge storage 4_color_theorem {Temp:{53:1b}}
execute if score y 4_color_theorem matches 54 run data merge storage 4_color_theorem {Temp:{54:1b}}
execute if score y 4_color_theorem matches 55 run data merge storage 4_color_theorem {Temp:{55:1b}}
execute if score y 4_color_theorem matches 56 run data merge storage 4_color_theorem {Temp:{56:1b}}
execute if score y 4_color_theorem matches 57 run data merge storage 4_color_theorem {Temp:{57:1b}}
execute if score y 4_color_theorem matches 58 run data merge storage 4_color_theorem {Temp:{58:1b}}
execute if score y 4_color_theorem matches 59 run data merge storage 4_color_theorem {Temp:{59:1b}}
execute if score y 4_color_theorem matches 60 run data merge storage 4_color_theorem {Temp:{60:1b}}
execute if score y 4_color_theorem matches 61 run data merge storage 4_color_theorem {Temp:{61:1b}}
execute if score y 4_color_theorem matches 62 run data merge storage 4_color_theorem {Temp:{62:1b}}
execute if score y 4_color_theorem matches 63 run data merge storage 4_color_theorem {Temp:{63:1b}}
execute if score y 4_color_theorem matches 64 run data merge storage 4_color_theorem {Temp:{64:1b}}

4_color_theorem:border_recog/merge 用于向Record中覆盖相邻信息的穷举函数
execute if data storage 4_color_theorem Temp.1 run data modify storage 4_color_theorem Record.1 merge from storage 4_color_theorem Temp
execute if data storage 4_color_theorem Temp.2 run data modify storage 4_color_theorem Record.2 merge from storage 4_color_theorem Temp
execute if data storage 4_color_theorem Temp.3 run data modify storage 4_color_theorem Record.3 merge from storage 4_color_theorem Temp
execute if data storage 4_color_theorem Temp.4 run data modify storage 4_color_theorem Record.4 merge from storage 4_color_theorem Temp
execute if data storage 4_color_theorem Temp.5 run data modify storage 4_color_theorem Record.5 merge from storage 4_color_theorem Temp
execute if data storage 4_color_theorem Temp.6 run data modify storage 4_color_theorem Record.6 merge from storage 4_color_theorem Temp
execute if data storage 4_color_theorem Temp.7 run data modify storage 4_color_theorem Record.7 merge from storage 4_color_theorem Temp
execute if data storage 4_color_theorem Temp.8 run data modify storage 4_color_theorem Record.8 merge from storage 4_color_theorem Temp
execute if data storage 4_color_theorem Temp.9 run data modify storage 4_color_theorem Record.9 merge from storage 4_color_theorem Temp
execute if data storage 4_color_theorem Temp.10 run data modify storage 4_color_theorem Record.10 merge from storage 4_color_theorem Temp
execute if data storage 4_color_theorem Temp.11 run data modify storage 4_color_theorem Record.11 merge from storage 4_color_theorem Temp
execute if data storage 4_color_theorem Temp.12 run data modify storage 4_color_theorem Record.12 merge from storage 4_color_theorem Temp
execute if data storage 4_color_theorem Temp.13 run data modify storage 4_color_theorem Record.13 merge from storage 4_color_theorem Temp
execute if data storage 4_color_theorem Temp.14 run data modify storage 4_color_theorem Record.14 merge from storage 4_color_theorem Temp
execute if data storage 4_color_theorem Temp.15 run data modify storage 4_color_theorem Record.15 merge from storage 4_color_theorem Temp
execute if data storage 4_color_theorem Temp.16 run data modify storage 4_color_theorem Record.16 merge from storage 4_color_theorem Temp
execute if data storage 4_color_theorem Temp.17 run data modify storage 4_color_theorem Record.17 merge from storage 4_color_theorem Temp
execute if data storage 4_color_theorem Temp.18 run data modify storage 4_color_theorem Record.18 merge from storage 4_color_theorem Temp
execute if data storage 4_color_theorem Temp.19 run data modify storage 4_color_theorem Record.19 merge from storage 4_color_theorem Temp
execute if data storage 4_color_theorem Temp.20 run data modify storage 4_color_theorem Record.20 merge from storage 4_color_theorem Temp
execute if data storage 4_color_theorem Temp.21 run data modify storage 4_color_theorem Record.21 merge from storage 4_color_theorem Temp
execute if data storage 4_color_theorem Temp.22 run data modify storage 4_color_theorem Record.22 merge from storage 4_color_theorem Temp
execute if data storage 4_color_theorem Temp.23 run data modify storage 4_color_theorem Record.23 merge from storage 4_color_theorem Temp
execute if data storage 4_color_theorem Temp.24 run data modify storage 4_color_theorem Record.24 merge from storage 4_color_theorem Temp
execute if data storage 4_color_theorem Temp.25 run data modify storage 4_color_theorem Record.25 merge from storage 4_color_theorem Temp
execute if data storage 4_color_theorem Temp.26 run data modify storage 4_color_theorem Record.26 merge from storage 4_color_theorem Temp
execute if data storage 4_color_theorem Temp.27 run data modify storage 4_color_theorem Record.27 merge from storage 4_color_theorem Temp
execute if data storage 4_color_theorem Temp.28 run data modify storage 4_color_theorem Record.28 merge from storage 4_color_theorem Temp
execute if data storage 4_color_theorem Temp.29 run data modify storage 4_color_theorem Record.29 merge from storage 4_color_theorem Temp
execute if data storage 4_color_theorem Temp.30 run data modify storage 4_color_theorem Record.30 merge from storage 4_color_theorem Temp
execute if data storage 4_color_theorem Temp.31 run data modify storage 4_color_theorem Record.31 merge from storage 4_color_theorem Temp
execute if data storage 4_color_theorem Temp.32 run data modify storage 4_color_theorem Record.32 merge from storage 4_color_theorem Temp
execute if data storage 4_color_theorem Temp.33 run data modify storage 4_color_theorem Record.33 merge from storage 4_color_theorem Temp
execute if data storage 4_color_theorem Temp.34 run data modify storage 4_color_theorem Record.34 merge from storage 4_color_theorem Temp
execute if data storage 4_color_theorem Temp.35 run data modify storage 4_color_theorem Record.35 merge from storage 4_color_theorem Temp
execute if data storage 4_color_theorem Temp.36 run data modify storage 4_color_theorem Record.36 merge from storage 4_color_theorem Temp
execute if data storage 4_color_theorem Temp.37 run data modify storage 4_color_theorem Record.37 merge from storage 4_color_theorem Temp
execute if data storage 4_color_theorem Temp.38 run data modify storage 4_color_theorem Record.38 merge from storage 4_color_theorem Temp
execute if data storage 4_color_theorem Temp.39 run data modify storage 4_color_theorem Record.39 merge from storage 4_color_theorem Temp
execute if data storage 4_color_theorem Temp.40 run data modify storage 4_color_theorem Record.40 merge from storage 4_color_theorem Temp
execute if data storage 4_color_theorem Temp.41 run data modify storage 4_color_theorem Record.41 merge from storage 4_color_theorem Temp
execute if data storage 4_color_theorem Temp.42 run data modify storage 4_color_theorem Record.42 merge from storage 4_color_theorem Temp
execute if data storage 4_color_theorem Temp.43 run data modify storage 4_color_theorem Record.43 merge from storage 4_color_theorem Temp
execute if data storage 4_color_theorem Temp.44 run data modify storage 4_color_theorem Record.44 merge from storage 4_color_theorem Temp
execute if data storage 4_color_theorem Temp.45 run data modify storage 4_color_theorem Record.45 merge from storage 4_color_theorem Temp
execute if data storage 4_color_theorem Temp.46 run data modify storage 4_color_theorem Record.46 merge from storage 4_color_theorem Temp
execute if data storage 4_color_theorem Temp.47 run data modify storage 4_color_theorem Record.47 merge from storage 4_color_theorem Temp
execute if data storage 4_color_theorem Temp.48 run data modify storage 4_color_theorem Record.48 merge from storage 4_color_theorem Temp
execute if data storage 4_color_theorem Temp.49 run data modify storage 4_color_theorem Record.49 merge from storage 4_color_theorem Temp
execute if data storage 4_color_theorem Temp.50 run data modify storage 4_color_theorem Record.50 merge from storage 4_color_theorem Temp
execute if data storage 4_color_theorem Temp.51 run data modify storage 4_color_theorem Record.51 merge from storage 4_color_theorem Temp
execute if data storage 4_color_theorem Temp.52 run data modify storage 4_color_theorem Record.52 merge from storage 4_color_theorem Temp
execute if data storage 4_color_theorem Temp.53 run data modify storage 4_color_theorem Record.53 merge from storage 4_color_theorem Temp
execute if data storage 4_color_theorem Temp.54 run data modify storage 4_color_theorem Record.54 merge from storage 4_color_theorem Temp
execute if data storage 4_color_theorem Temp.55 run data modify storage 4_color_theorem Record.55 merge from storage 4_color_theorem Temp
execute if data storage 4_color_theorem Temp.56 run data modify storage 4_color_theorem Record.56 merge from storage 4_color_theorem Temp
execute if data storage 4_color_theorem Temp.57 run data modify storage 4_color_theorem Record.57 merge from storage 4_color_theorem Temp
execute if data storage 4_color_theorem Temp.58 run data modify storage 4_color_theorem Record.58 merge from storage 4_color_theorem Temp
execute if data storage 4_color_theorem Temp.59 run data modify storage 4_color_theorem Record.59 merge from storage 4_color_theorem Temp
execute if data storage 4_color_theorem Temp.60 run data modify storage 4_color_theorem Record.60 merge from storage 4_color_theorem Temp
execute if data storage 4_color_theorem Temp.61 run data modify storage 4_color_theorem Record.61 merge from storage 4_color_theorem Temp
execute if data storage 4_color_theorem Temp.62 run data modify storage 4_color_theorem Record.62 merge from storage 4_color_theorem Temp
execute if data storage 4_color_theorem Temp.63 run data modify storage 4_color_theorem Record.63 merge from storage 4_color_theorem Temp
execute if data storage 4_color_theorem Temp.64 run data modify storage 4_color_theorem Record.64 merge from storage 4_color_theorem Temp
data remove storage 4_color_theorem Temp





3.2.3 剔除自身

   虽然我们现在得到了区域相邻的结果,但这个结果并不好看,因为可以看到,每个区域都在和自身相邻,这会一定程度地影响后续计算。因此需要从这些记录中剔除自身。这个功能还是由一个函数穷举实现。
   剔除自身后的效果:

相关函数:
4_color_theorem:border_recog/selfdelete 用于从记录当中剔除自身的穷举函数
data remove storage 4_color_theorem Record.1.1
data remove storage 4_color_theorem Record.2.2
data remove storage 4_color_theorem Record.3.3
data remove storage 4_color_theorem Record.4.4
data remove storage 4_color_theorem Record.5.5
data remove storage 4_color_theorem Record.6.6
data remove storage 4_color_theorem Record.7.7
data remove storage 4_color_theorem Record.8.8
data remove storage 4_color_theorem Record.9.9
data remove storage 4_color_theorem Record.10.10
data remove storage 4_color_theorem Record.11.11
data remove storage 4_color_theorem Record.12.12
data remove storage 4_color_theorem Record.13.13
data remove storage 4_color_theorem Record.14.14
data remove storage 4_color_theorem Record.15.15
data remove storage 4_color_theorem Record.16.16
data remove storage 4_color_theorem Record.17.17
data remove storage 4_color_theorem Record.18.18
data remove storage 4_color_theorem Record.19.19
data remove storage 4_color_theorem Record.20.20
data remove storage 4_color_theorem Record.21.21
data remove storage 4_color_theorem Record.22.22
data remove storage 4_color_theorem Record.23.23
data remove storage 4_color_theorem Record.24.24
data remove storage 4_color_theorem Record.25.25
data remove storage 4_color_theorem Record.26.26
data remove storage 4_color_theorem Record.27.27
data remove storage 4_color_theorem Record.28.28
data remove storage 4_color_theorem Record.29.29
data remove storage 4_color_theorem Record.30.30
data remove storage 4_color_theorem Record.31.31
data remove storage 4_color_theorem Record.32.32
data remove storage 4_color_theorem Record.33.33
data remove storage 4_color_theorem Record.34.34
data remove storage 4_color_theorem Record.35.35
data remove storage 4_color_theorem Record.36.36
data remove storage 4_color_theorem Record.37.37
data remove storage 4_color_theorem Record.38.38
data remove storage 4_color_theorem Record.39.39
data remove storage 4_color_theorem Record.40.40
data remove storage 4_color_theorem Record.41.41
data remove storage 4_color_theorem Record.42.42
data remove storage 4_color_theorem Record.43.43
data remove storage 4_color_theorem Record.44.44
data remove storage 4_color_theorem Record.45.45
data remove storage 4_color_theorem Record.46.46
data remove storage 4_color_theorem Record.47.47
data remove storage 4_color_theorem Record.48.48
data remove storage 4_color_theorem Record.49.49
data remove storage 4_color_theorem Record.50.50
data remove storage 4_color_theorem Record.51.51
data remove storage 4_color_theorem Record.52.52
data remove storage 4_color_theorem Record.53.53
data remove storage 4_color_theorem Record.54.54
data remove storage 4_color_theorem Record.55.55
data remove storage 4_color_theorem Record.56.56
data remove storage 4_color_theorem Record.57.57
data remove storage 4_color_theorem Record.58.58
data remove storage 4_color_theorem Record.59.59
data remove storage 4_color_theorem Record.60.60
data remove storage 4_color_theorem Record.61.61
data remove storage 4_color_theorem Record.62.62
data remove storage 4_color_theorem Record.63.63
data remove storage 4_color_theorem Record.64.64





3.3 穷举求解

   相信我,你不会想看这一部分的。
   这个流程图,我至少设计了十几分钟,然后从开始着手写算法到最终debug完成,花了大概有前两部分几倍的时间。
   不过咱还是得讲啊,先把流程图放上来吧。

相关函数:
4_color_theorem:solve/get_sol 用于主体结构的主要递归函数(这个函数确实是递归的)
#Temp 用于储存该区域的相邻区域
#Temp2 用于储存一个相邻区域的填色


#获取相邻区域id并复制至Temp中,格式为Compound
data remove storage 4_color_theorem Temp
function 4_color_theorem:solve/copy_to_temp
#获取相邻区域已有的填色并复制至NearbyFill中,格式为List
data remove storage 4_color_theorem NearbyFill
function 4_color_theorem:solve/get_nearby_fill
#分析相邻区域的已有填充,获取可用填充
data modify storage 4_color_theorem PossibleSolutionThis set value {1:1b,2:1b,3:1b,4:1b}
function 4_color_theorem:solve/get_possible_sol
#分析是否有可用填充,若有则使用第一种可用填充,若无则否定相邻已有填色的id最大的区域
function 4_color_theorem:solve/get_final_sol_this





3.3.1 获取相邻填色信息

   要想确定一个区域需要填什么色,首先要做的就是知道它周围的区域填色有哪些。
   通过穷举获取区域周围的填色,并进行一定的加工处理即可得到结果。
   不过需要特别提出的是,在假定区域1,3都与区域2相邻的前提下,如果我正在对区域2进行填充,那么即使区域3和区域2相邻,也不考虑区域3的填色,而仅考虑区域1的填色。因为在对区域2进行填色时,区域3并没有填色,因此考虑区域3以及编号更大的区域的填色没有意义。(这里需要指出,即便因为某些原因填了区域3的颜色后需要返回来修改区域2的颜色,此时也不考虑区域3的颜色。具体原因后面会讨论。)
   我的处理方式是,首先通过函数穷举将该区域的相邻区域复制入Temp,然后使用另一个函数对Temp进行穷举,获取需要的区域的颜色填充并转移至NearbyFill这个nbt中(这个nbt会以Byte List的格式储存附近区域的填色,蓝色为1b,绿色为2b,黄色为3b,红色为4b。一个例子是 NearbyFill:[1b,2b,1b],说明这个区域与两个蓝色填色的区域和一个绿色填色的区域相邻)。
   当然,对于第一个区域来说,这个nbt获取不到任何东西,因为没有任何区域的编号比它更小。
   通过对NearbyFill的解析处理,即可得到一个区域的(可能)可用填色。

相关函数:
4_color_theorem:solve/get_sol 用于主体结构的主要递归函数,涉及到一些nbt的初始化
#Temp 用于储存该区域的相邻区域
#Temp2 用于储存一个相邻区域的填色


#获取相邻区域id并复制至Temp中,格式为Compound
data remove storage 4_color_theorem Temp
function 4_color_theorem:solve/copy_to_temp
#获取相邻区域已有的填色并复制至NearbyFill中,格式为List
data remove storage 4_color_theorem NearbyFill
function 4_color_theorem:solve/get_nearby_fill
#分析相邻区域的已有填充,获取可用填充
data modify storage 4_color_theorem PossibleSolutionThis set value {1:1b,2:1b,3:1b,4:1b}
function 4_color_theorem:solve/get_possible_sol
#分析是否有可用填充,若有则使用第一种可用填充,若无则否定相邻已有填色的id最大的区域
function 4_color_theorem:solve/get_final_sol_this

4_color_theorem:solve/copy_to_temp 用于将附近区域编号复制入Temp中的穷举函数
execute if score reigon_id 4_color_theorem matches 1 run data modify storage 4_color_theorem Temp set from storage 4_color_theorem Record.1
execute if score reigon_id 4_color_theorem matches 2 run data modify storage 4_color_theorem Temp set from storage 4_color_theorem Record.2
execute if score reigon_id 4_color_theorem matches 3 run data modify storage 4_color_theorem Temp set from storage 4_color_theorem Record.3
execute if score reigon_id 4_color_theorem matches 4 run data modify storage 4_color_theorem Temp set from storage 4_color_theorem Record.4
execute if score reigon_id 4_color_theorem matches 5 run data modify storage 4_color_theorem Temp set from storage 4_color_theorem Record.5
execute if score reigon_id 4_color_theorem matches 6 run data modify storage 4_color_theorem Temp set from storage 4_color_theorem Record.6
execute if score reigon_id 4_color_theorem matches 7 run data modify storage 4_color_theorem Temp set from storage 4_color_theorem Record.7
execute if score reigon_id 4_color_theorem matches 8 run data modify storage 4_color_theorem Temp set from storage 4_color_theorem Record.8
execute if score reigon_id 4_color_theorem matches 9 run data modify storage 4_color_theorem Temp set from storage 4_color_theorem Record.9
execute if score reigon_id 4_color_theorem matches 10 run data modify storage 4_color_theorem Temp set from storage 4_color_theorem Record.10
execute if score reigon_id 4_color_theorem matches 11 run data modify storage 4_color_theorem Temp set from storage 4_color_theorem Record.11
execute if score reigon_id 4_color_theorem matches 12 run data modify storage 4_color_theorem Temp set from storage 4_color_theorem Record.12
execute if score reigon_id 4_color_theorem matches 13 run data modify storage 4_color_theorem Temp set from storage 4_color_theorem Record.13
execute if score reigon_id 4_color_theorem matches 14 run data modify storage 4_color_theorem Temp set from storage 4_color_theorem Record.14
execute if score reigon_id 4_color_theorem matches 15 run data modify storage 4_color_theorem Temp set from storage 4_color_theorem Record.15
execute if score reigon_id 4_color_theorem matches 16 run data modify storage 4_color_theorem Temp set from storage 4_color_theorem Record.16
execute if score reigon_id 4_color_theorem matches 17 run data modify storage 4_color_theorem Temp set from storage 4_color_theorem Record.17
execute if score reigon_id 4_color_theorem matches 18 run data modify storage 4_color_theorem Temp set from storage 4_color_theorem Record.18
execute if score reigon_id 4_color_theorem matches 19 run data modify storage 4_color_theorem Temp set from storage 4_color_theorem Record.19
execute if score reigon_id 4_color_theorem matches 20 run data modify storage 4_color_theorem Temp set from storage 4_color_theorem Record.20
execute if score reigon_id 4_color_theorem matches 21 run data modify storage 4_color_theorem Temp set from storage 4_color_theorem Record.21
execute if score reigon_id 4_color_theorem matches 22 run data modify storage 4_color_theorem Temp set from storage 4_color_theorem Record.22
execute if score reigon_id 4_color_theorem matches 23 run data modify storage 4_color_theorem Temp set from storage 4_color_theorem Record.23
execute if score reigon_id 4_color_theorem matches 24 run data modify storage 4_color_theorem Temp set from storage 4_color_theorem Record.24
execute if score reigon_id 4_color_theorem matches 25 run data modify storage 4_color_theorem Temp set from storage 4_color_theorem Record.25
execute if score reigon_id 4_color_theorem matches 26 run data modify storage 4_color_theorem Temp set from storage 4_color_theorem Record.26
execute if score reigon_id 4_color_theorem matches 27 run data modify storage 4_color_theorem Temp set from storage 4_color_theorem Record.27
execute if score reigon_id 4_color_theorem matches 28 run data modify storage 4_color_theorem Temp set from storage 4_color_theorem Record.28
execute if score reigon_id 4_color_theorem matches 29 run data modify storage 4_color_theorem Temp set from storage 4_color_theorem Record.29
execute if score reigon_id 4_color_theorem matches 30 run data modify storage 4_color_theorem Temp set from storage 4_color_theorem Record.30
execute if score reigon_id 4_color_theorem matches 31 run data modify storage 4_color_theorem Temp set from storage 4_color_theorem Record.31
execute if score reigon_id 4_color_theorem matches 32 run data modify storage 4_color_theorem Temp set from storage 4_color_theorem Record.32
execute if score reigon_id 4_color_theorem matches 33 run data modify storage 4_color_theorem Temp set from storage 4_color_theorem Record.33
execute if score reigon_id 4_color_theorem matches 34 run data modify storage 4_color_theorem Temp set from storage 4_color_theorem Record.34
execute if score reigon_id 4_color_theorem matches 35 run data modify storage 4_color_theorem Temp set from storage 4_color_theorem Record.35
execute if score reigon_id 4_color_theorem matches 36 run data modify storage 4_color_theorem Temp set from storage 4_color_theorem Record.36
execute if score reigon_id 4_color_theorem matches 37 run data modify storage 4_color_theorem Temp set from storage 4_color_theorem Record.37
execute if score reigon_id 4_color_theorem matches 38 run data modify storage 4_color_theorem Temp set from storage 4_color_theorem Record.38
execute if score reigon_id 4_color_theorem matches 39 run data modify storage 4_color_theorem Temp set from storage 4_color_theorem Record.39
execute if score reigon_id 4_color_theorem matches 40 run data modify storage 4_color_theorem Temp set from storage 4_color_theorem Record.40
execute if score reigon_id 4_color_theorem matches 41 run data modify storage 4_color_theorem Temp set from storage 4_color_theorem Record.41
execute if score reigon_id 4_color_theorem matches 42 run data modify storage 4_color_theorem Temp set from storage 4_color_theorem Record.42
execute if score reigon_id 4_color_theorem matches 43 run data modify storage 4_color_theorem Temp set from storage 4_color_theorem Record.43
execute if score reigon_id 4_color_theorem matches 44 run data modify storage 4_color_theorem Temp set from storage 4_color_theorem Record.44
execute if score reigon_id 4_color_theorem matches 45 run data modify storage 4_color_theorem Temp set from storage 4_color_theorem Record.45
execute if score reigon_id 4_color_theorem matches 46 run data modify storage 4_color_theorem Temp set from storage 4_color_theorem Record.46
execute if score reigon_id 4_color_theorem matches 47 run data modify storage 4_color_theorem Temp set from storage 4_color_theorem Record.47
execute if score reigon_id 4_color_theorem matches 48 run data modify storage 4_color_theorem Temp set from storage 4_color_theorem Record.48
execute if score reigon_id 4_color_theorem matches 49 run data modify storage 4_color_theorem Temp set from storage 4_color_theorem Record.49
execute if score reigon_id 4_color_theorem matches 50 run data modify storage 4_color_theorem Temp set from storage 4_color_theorem Record.50
execute if score reigon_id 4_color_theorem matches 51 run data modify storage 4_color_theorem Temp set from storage 4_color_theorem Record.51
execute if score reigon_id 4_color_theorem matches 52 run data modify storage 4_color_theorem Temp set from storage 4_color_theorem Record.52
execute if score reigon_id 4_color_theorem matches 53 run data modify storage 4_color_theorem Temp set from storage 4_color_theorem Record.53
execute if score reigon_id 4_color_theorem matches 54 run data modify storage 4_color_theorem Temp set from storage 4_color_theorem Record.54
execute if score reigon_id 4_color_theorem matches 55 run data modify storage 4_color_theorem Temp set from storage 4_color_theorem Record.55
execute if score reigon_id 4_color_theorem matches 56 run data modify storage 4_color_theorem Temp set from storage 4_color_theorem Record.56
execute if score reigon_id 4_color_theorem matches 57 run data modify storage 4_color_theorem Temp set from storage 4_color_theorem Record.57
execute if score reigon_id 4_color_theorem matches 58 run data modify storage 4_color_theorem Temp set from storage 4_color_theorem Record.58
execute if score reigon_id 4_color_theorem matches 59 run data modify storage 4_color_theorem Temp set from storage 4_color_theorem Record.59
execute if score reigon_id 4_color_theorem matches 60 run data modify storage 4_color_theorem Temp set from storage 4_color_theorem Record.60
execute if score reigon_id 4_color_theorem matches 61 run data modify storage 4_color_theorem Temp set from storage 4_color_theorem Record.61
execute if score reigon_id 4_color_theorem matches 62 run data modify storage 4_color_theorem Temp set from storage 4_color_theorem Record.62
execute if score reigon_id 4_color_theorem matches 63 run data modify storage 4_color_theorem Temp set from storage 4_color_theorem Record.63
execute if score reigon_id 4_color_theorem matches 64 run data modify storage 4_color_theorem Temp set from storage 4_color_theorem Record.64

4_color_theorem:solve/get_nearby_fill 用于分析Temp并获取所需附近区域填色的穷举函数
execute if score reigon_id 4_color_theorem matches 1.. if data storage 4_color_theorem Temp.1 run data modify storage 4_color_theorem NearbyFill append from storage 4_color_theorem FinalSolution.1
execute if score reigon_id 4_color_theorem matches 2.. if data storage 4_color_theorem Temp.2 run data modify storage 4_color_theorem NearbyFill append from storage 4_color_theorem FinalSolution.2
execute if score reigon_id 4_color_theorem matches 3.. if data storage 4_color_theorem Temp.3 run data modify storage 4_color_theorem NearbyFill append from storage 4_color_theorem FinalSolution.3
execute if score reigon_id 4_color_theorem matches 4.. if data storage 4_color_theorem Temp.4 run data modify storage 4_color_theorem NearbyFill append from storage 4_color_theorem FinalSolution.4
execute if score reigon_id 4_color_theorem matches 5.. if data storage 4_color_theorem Temp.5 run data modify storage 4_color_theorem NearbyFill append from storage 4_color_theorem FinalSolution.5
execute if score reigon_id 4_color_theorem matches 6.. if data storage 4_color_theorem Temp.6 run data modify storage 4_color_theorem NearbyFill append from storage 4_color_theorem FinalSolution.6
execute if score reigon_id 4_color_theorem matches 7.. if data storage 4_color_theorem Temp.7 run data modify storage 4_color_theorem NearbyFill append from storage 4_color_theorem FinalSolution.7
execute if score reigon_id 4_color_theorem matches 8.. if data storage 4_color_theorem Temp.8 run data modify storage 4_color_theorem NearbyFill append from storage 4_color_theorem FinalSolution.8
execute if score reigon_id 4_color_theorem matches 9.. if data storage 4_color_theorem Temp.9 run data modify storage 4_color_theorem NearbyFill append from storage 4_color_theorem FinalSolution.9
execute if score reigon_id 4_color_theorem matches 10.. if data storage 4_color_theorem Temp.10 run data modify storage 4_color_theorem NearbyFill append from storage 4_color_theorem FinalSolution.10
execute if score reigon_id 4_color_theorem matches 11.. if data storage 4_color_theorem Temp.11 run data modify storage 4_color_theorem NearbyFill append from storage 4_color_theorem FinalSolution.11
execute if score reigon_id 4_color_theorem matches 12.. if data storage 4_color_theorem Temp.12 run data modify storage 4_color_theorem NearbyFill append from storage 4_color_theorem FinalSolution.12
execute if score reigon_id 4_color_theorem matches 13.. if data storage 4_color_theorem Temp.13 run data modify storage 4_color_theorem NearbyFill append from storage 4_color_theorem FinalSolution.13
execute if score reigon_id 4_color_theorem matches 14.. if data storage 4_color_theorem Temp.14 run data modify storage 4_color_theorem NearbyFill append from storage 4_color_theorem FinalSolution.14
execute if score reigon_id 4_color_theorem matches 15.. if data storage 4_color_theorem Temp.15 run data modify storage 4_color_theorem NearbyFill append from storage 4_color_theorem FinalSolution.15
execute if score reigon_id 4_color_theorem matches 16.. if data storage 4_color_theorem Temp.16 run data modify storage 4_color_theorem NearbyFill append from storage 4_color_theorem FinalSolution.16
execute if score reigon_id 4_color_theorem matches 17.. if data storage 4_color_theorem Temp.17 run data modify storage 4_color_theorem NearbyFill append from storage 4_color_theorem FinalSolution.17
execute if score reigon_id 4_color_theorem matches 18.. if data storage 4_color_theorem Temp.18 run data modify storage 4_color_theorem NearbyFill append from storage 4_color_theorem FinalSolution.18
execute if score reigon_id 4_color_theorem matches 19.. if data storage 4_color_theorem Temp.19 run data modify storage 4_color_theorem NearbyFill append from storage 4_color_theorem FinalSolution.19
execute if score reigon_id 4_color_theorem matches 20.. if data storage 4_color_theorem Temp.20 run data modify storage 4_color_theorem NearbyFill append from storage 4_color_theorem FinalSolution.20
execute if score reigon_id 4_color_theorem matches 21.. if data storage 4_color_theorem Temp.21 run data modify storage 4_color_theorem NearbyFill append from storage 4_color_theorem FinalSolution.21
execute if score reigon_id 4_color_theorem matches 22.. if data storage 4_color_theorem Temp.22 run data modify storage 4_color_theorem NearbyFill append from storage 4_color_theorem FinalSolution.22
execute if score reigon_id 4_color_theorem matches 23.. if data storage 4_color_theorem Temp.23 run data modify storage 4_color_theorem NearbyFill append from storage 4_color_theorem FinalSolution.23
execute if score reigon_id 4_color_theorem matches 24.. if data storage 4_color_theorem Temp.24 run data modify storage 4_color_theorem NearbyFill append from storage 4_color_theorem FinalSolution.24
execute if score reigon_id 4_color_theorem matches 25.. if data storage 4_color_theorem Temp.25 run data modify storage 4_color_theorem NearbyFill append from storage 4_color_theorem FinalSolution.25
execute if score reigon_id 4_color_theorem matches 26.. if data storage 4_color_theorem Temp.26 run data modify storage 4_color_theorem NearbyFill append from storage 4_color_theorem FinalSolution.26
execute if score reigon_id 4_color_theorem matches 27.. if data storage 4_color_theorem Temp.27 run data modify storage 4_color_theorem NearbyFill append from storage 4_color_theorem FinalSolution.27
execute if score reigon_id 4_color_theorem matches 28.. if data storage 4_color_theorem Temp.28 run data modify storage 4_color_theorem NearbyFill append from storage 4_color_theorem FinalSolution.28
execute if score reigon_id 4_color_theorem matches 29.. if data storage 4_color_theorem Temp.29 run data modify storage 4_color_theorem NearbyFill append from storage 4_color_theorem FinalSolution.29
execute if score reigon_id 4_color_theorem matches 30.. if data storage 4_color_theorem Temp.30 run data modify storage 4_color_theorem NearbyFill append from storage 4_color_theorem FinalSolution.30
execute if score reigon_id 4_color_theorem matches 31.. if data storage 4_color_theorem Temp.31 run data modify storage 4_color_theorem NearbyFill append from storage 4_color_theorem FinalSolution.31
execute if score reigon_id 4_color_theorem matches 32.. if data storage 4_color_theorem Temp.32 run data modify storage 4_color_theorem NearbyFill append from storage 4_color_theorem FinalSolution.32
execute if score reigon_id 4_color_theorem matches 33.. if data storage 4_color_theorem Temp.33 run data modify storage 4_color_theorem NearbyFill append from storage 4_color_theorem FinalSolution.33
execute if score reigon_id 4_color_theorem matches 34.. if data storage 4_color_theorem Temp.34 run data modify storage 4_color_theorem NearbyFill append from storage 4_color_theorem FinalSolution.34
execute if score reigon_id 4_color_theorem matches 35.. if data storage 4_color_theorem Temp.35 run data modify storage 4_color_theorem NearbyFill append from storage 4_color_theorem FinalSolution.35
execute if score reigon_id 4_color_theorem matches 36.. if data storage 4_color_theorem Temp.36 run data modify storage 4_color_theorem NearbyFill append from storage 4_color_theorem FinalSolution.36
execute if score reigon_id 4_color_theorem matches 37.. if data storage 4_color_theorem Temp.37 run data modify storage 4_color_theorem NearbyFill append from storage 4_color_theorem FinalSolution.37
execute if score reigon_id 4_color_theorem matches 38.. if data storage 4_color_theorem Temp.38 run data modify storage 4_color_theorem NearbyFill append from storage 4_color_theorem FinalSolution.38
execute if score reigon_id 4_color_theorem matches 39.. if data storage 4_color_theorem Temp.39 run data modify storage 4_color_theorem NearbyFill append from storage 4_color_theorem FinalSolution.39
execute if score reigon_id 4_color_theorem matches 40.. if data storage 4_color_theorem Temp.40 run data modify storage 4_color_theorem NearbyFill append from storage 4_color_theorem FinalSolution.40
execute if score reigon_id 4_color_theorem matches 41.. if data storage 4_color_theorem Temp.41 run data modify storage 4_color_theorem NearbyFill append from storage 4_color_theorem FinalSolution.41
execute if score reigon_id 4_color_theorem matches 42.. if data storage 4_color_theorem Temp.42 run data modify storage 4_color_theorem NearbyFill append from storage 4_color_theorem FinalSolution.42
execute if score reigon_id 4_color_theorem matches 43.. if data storage 4_color_theorem Temp.43 run data modify storage 4_color_theorem NearbyFill append from storage 4_color_theorem FinalSolution.43
execute if score reigon_id 4_color_theorem matches 44.. if data storage 4_color_theorem Temp.44 run data modify storage 4_color_theorem NearbyFill append from storage 4_color_theorem FinalSolution.44
execute if score reigon_id 4_color_theorem matches 45.. if data storage 4_color_theorem Temp.45 run data modify storage 4_color_theorem NearbyFill append from storage 4_color_theorem FinalSolution.45
execute if score reigon_id 4_color_theorem matches 46.. if data storage 4_color_theorem Temp.46 run data modify storage 4_color_theorem NearbyFill append from storage 4_color_theorem FinalSolution.46
execute if score reigon_id 4_color_theorem matches 47.. if data storage 4_color_theorem Temp.47 run data modify storage 4_color_theorem NearbyFill append from storage 4_color_theorem FinalSolution.47
execute if score reigon_id 4_color_theorem matches 48.. if data storage 4_color_theorem Temp.48 run data modify storage 4_color_theorem NearbyFill append from storage 4_color_theorem FinalSolution.48
execute if score reigon_id 4_color_theorem matches 49.. if data storage 4_color_theorem Temp.49 run data modify storage 4_color_theorem NearbyFill append from storage 4_color_theorem FinalSolution.49
execute if score reigon_id 4_color_theorem matches 50.. if data storage 4_color_theorem Temp.50 run data modify storage 4_color_theorem NearbyFill append from storage 4_color_theorem FinalSolution.50
execute if score reigon_id 4_color_theorem matches 51.. if data storage 4_color_theorem Temp.51 run data modify storage 4_color_theorem NearbyFill append from storage 4_color_theorem FinalSolution.51
execute if score reigon_id 4_color_theorem matches 52.. if data storage 4_color_theorem Temp.52 run data modify storage 4_color_theorem NearbyFill append from storage 4_color_theorem FinalSolution.52
execute if score reigon_id 4_color_theorem matches 53.. if data storage 4_color_theorem Temp.53 run data modify storage 4_color_theorem NearbyFill append from storage 4_color_theorem FinalSolution.53
execute if score reigon_id 4_color_theorem matches 54.. if data storage 4_color_theorem Temp.54 run data modify storage 4_color_theorem NearbyFill append from storage 4_color_theorem FinalSolution.54
execute if score reigon_id 4_color_theorem matches 55.. if data storage 4_color_theorem Temp.55 run data modify storage 4_color_theorem NearbyFill append from storage 4_color_theorem FinalSolution.55
execute if score reigon_id 4_color_theorem matches 56.. if data storage 4_color_theorem Temp.56 run data modify storage 4_color_theorem NearbyFill append from storage 4_color_theorem FinalSolution.56
execute if score reigon_id 4_color_theorem matches 57.. if data storage 4_color_theorem Temp.57 run data modify storage 4_color_theorem NearbyFill append from storage 4_color_theorem FinalSolution.57
execute if score reigon_id 4_color_theorem matches 58.. if data storage 4_color_theorem Temp.58 run data modify storage 4_color_theorem NearbyFill append from storage 4_color_theorem FinalSolution.58
execute if score reigon_id 4_color_theorem matches 59.. if data storage 4_color_theorem Temp.59 run data modify storage 4_color_theorem NearbyFill append from storage 4_color_theorem FinalSolution.59
execute if score reigon_id 4_color_theorem matches 60.. if data storage 4_color_theorem Temp.60 run data modify storage 4_color_theorem NearbyFill append from storage 4_color_theorem FinalSolution.60
execute if score reigon_id 4_color_theorem matches 61.. if data storage 4_color_theorem Temp.61 run data modify storage 4_color_theorem NearbyFill append from storage 4_color_theorem FinalSolution.61
execute if score reigon_id 4_color_theorem matches 62.. if data storage 4_color_theorem Temp.62 run data modify storage 4_color_theorem NearbyFill append from storage 4_color_theorem FinalSolution.62
execute if score reigon_id 4_color_theorem matches 63.. if data storage 4_color_theorem Temp.63 run data modify storage 4_color_theorem NearbyFill append from storage 4_color_theorem FinalSolution.63
execute if score reigon_id 4_color_theorem matches 64.. if data storage 4_color_theorem Temp.64 run data modify storage 4_color_theorem NearbyFill append from storage 4_color_theorem FinalSolution.64





3.3.2 分析填色可能

   获取了所需的周围环境填色后,可以分析当前区域的可用填色了。
   这里我建立了一个PossibleSolutionThis的nbt。这个nbt用于记录当前区域的所有填色的可行性。
   首先要对这个nbt进行初始化,设置所有颜色均存在填色可能(PossibleSolutionThis:{1:1b,2:1b,3:1b,4:1b},四种填色方式均使用1b标记)。
   随后调用一个递归函数,检测NearbyFill中的nbt,判断哪种颜色已经被使用,并将对应的颜色设置为0b。这样递归后,PossibleSolutionThis中就会有一部分颜色可用(标记为1b),而另一部分颜色不可用(标记为0b)的结果出现了(一个示例 PossibleSolutionThis:{1:1b,2:0b,3:0b,4:1b},说明蓝色和红色可用,而绿色和黄色不可用)(对区域1来说,所有四种颜色都会是1b。而后续的填色过程中,可能会出现所有颜色都不可用的现象,此时认定结果“出错”,需要通过改变之前区域的填充来解决,会在后面详细说明)。

相关函数:
4_color_theorem:solve/get_sol 用于主体结构的主要递归函数,用于PossibleSolutionThis的初始化
#Temp 用于储存该区域的相邻区域
#Temp2 用于储存一个相邻区域的填色


#获取相邻区域id并复制至Temp中,格式为Compound
data remove storage 4_color_theorem Temp
function 4_color_theorem:solve/copy_to_temp
#获取相邻区域已有的填色并复制至NearbyFill中,格式为List
data remove storage 4_color_theorem NearbyFill
function 4_color_theorem:solve/get_nearby_fill
#分析相邻区域的已有填充,获取可用填充
data modify storage 4_color_theorem PossibleSolutionThis set value {1:1b,2:1b,3:1b,4:1b}
function 4_color_theorem:solve/get_possible_sol
#分析是否有可用填充,若有则使用第一种可用填充,若无则否定相邻已有填色的id最大的区域
function 4_color_theorem:solve/get_final_sol_this

4_color_theorem:solve/get_possible_sol 用于通过NearbyFill处理PossibleSolutionThis的穷举递归函数
data modify storage 4_color_theorem Temp2 set from storage 4_color_theorem NearbyFill[0]
execute if data storage 4_color_theorem {Temp2:1b} run data merge storage 4_color_theorem {PossibleSolutionThis:{1:0b}}
execute if data storage 4_color_theorem {Temp2:2b} run data merge storage 4_color_theorem {PossibleSolutionThis:{2:0b}}
execute if data storage 4_color_theorem {Temp2:3b} run data merge storage 4_color_theorem {PossibleSolutionThis:{3:0b}}
execute if data storage 4_color_theorem {Temp2:4b} run data merge storage 4_color_theorem {PossibleSolutionThis:{4:0b}}
data remove storage 4_color_theorem
NearbyFill[0]
execute if data storage 4_color_theorem NearbyFill[] run function 4_color_theorem:solve/get_possible_sol





3.3.3 填色选取与记录

   现在我们获得了一个区域的可能填充,那么得到答案的最简单的方法就是一个个试。我的策略是先从1(蓝色)开始,1不行就用2(绿色),再不行就3(黄色)或4(红色)。
   通过函数穷举判断PossibleSolutionThis的第一个可用颜色,并保存到FinalSolutionThis这个nbt中。这个nbt即表示当前这个区域正在使用的填色。同时,使用穷举函数将PossibleSolutionThis和FinalSolutionThis保存到PossibleSolution和FinalSolution下对应编号的nbt内。这样FinalSolution里就保存了所有区域正在使用的填色,而PossibleSolution里保存了所有区域的可用填色。结果如下图所示:
   注意,这两个记录都有用。PossibleSolution用于出错时能够方便地进行修正,而FinalSolution则用于生成最终解。

备忘录:
PossibleSolution 用于保存所有区域的填色可能
PossibleSolutionThis 用于保存当前正在分析的区域的填色可能
FinalSolution 用于保存所有区域的正在使用的填色
FinalSolutionThis 用于保存当前正在分析的区域正在使用的填色

相关函数:
4_color_theorem:solve/get_final_sol_this 用于选定FinalSolutionThis,或执行错误修正
data modify storage 4_color_theorem FinalSolutionThis set value 0b
execute if data storage 4_color_theorem PossibleSolutionThis{1:1b} run data modify storage 4_color_theorem FinalSolutionThis set value 1b
execute if data storage 4_color_theorem {FinalSolutionThis:0b} if data storage 4_color_theorem PossibleSolutionThis{2:1b} run data modify storage 4_color_theorem FinalSolutionThis set value 2b
execute if data storage 4_color_theorem {FinalSolutionThis:0b} if data storage 4_color_theorem PossibleSolutionThis{3:1b} run data modify storage 4_color_theorem FinalSolutionThis set value 3b
execute if data storage 4_color_theorem {FinalSolutionThis:0b} if data storage 4_color_theorem PossibleSolutionThis{4:1b} run data modify storage 4_color_theorem FinalSolutionThis set value 4b


#有可用填色
execute unless data storage 4_color_theorem {FinalSolutionThis:0b} run function 4_color_theorem:solve/record_sol


#无可用填色
execute if data storage 4_color_theorem {FinalSolutionThis:0b} run function 4_color_theorem:solve/back_to_nearest_area

4_color_theorem:solve/record_sol 用于执行记录函数,并参与主要函数的递归
function 4_color_theorem:solve/record_final_sol
function 4_color_theorem:solve/record_possible_sol
execute if score reigon_id 4_color_theorem < reigon_count 4_color_theorem run function 4_color_theorem:solve/next_area

4_color_theorem:solve/record_final_sol 用于记录FinalSolution的穷举函数
execute if score reigon_id 4_color_theorem matches 1 run data modify storage 4_color_theorem FinalSolution.1 set from storage 4_color_theorem FinalSolutionThis
execute if score reigon_id 4_color_theorem matches 2 run data modify storage 4_color_theorem FinalSolution.2 set from storage 4_color_theorem FinalSolutionThis
execute if score reigon_id 4_color_theorem matches 3 run data modify storage 4_color_theorem FinalSolution.3 set from storage 4_color_theorem FinalSolutionThis
execute if score reigon_id 4_color_theorem matches 4 run data modify storage 4_color_theorem FinalSolution.4 set from storage 4_color_theorem FinalSolutionThis
execute if score reigon_id 4_color_theorem matches 5 run data modify storage 4_color_theorem FinalSolution.5 set from storage 4_color_theorem FinalSolutionThis
execute if score reigon_id 4_color_theorem matches 6 run data modify storage 4_color_theorem FinalSolution.6 set from storage 4_color_theorem FinalSolutionThis
execute if score reigon_id 4_color_theorem matches 7 run data modify storage 4_color_theorem FinalSolution.7 set from storage 4_color_theorem FinalSolutionThis
execute if score reigon_id 4_color_theorem matches 8 run data modify storage 4_color_theorem FinalSolution.8 set from storage 4_color_theorem FinalSolutionThis
execute if score reigon_id 4_color_theorem matches 9 run data modify storage 4_color_theorem FinalSolution.9 set from storage 4_color_theorem FinalSolutionThis
execute if score reigon_id 4_color_theorem matches 10 run data modify storage 4_color_theorem FinalSolution.10 set from storage 4_color_theorem FinalSolutionThis
execute if score reigon_id 4_color_theorem matches 11 run data modify storage 4_color_theorem FinalSolution.11 set from storage 4_color_theorem FinalSolutionThis
execute if score reigon_id 4_color_theorem matches 12 run data modify storage 4_color_theorem FinalSolution.12 set from storage 4_color_theorem FinalSolutionThis
execute if score reigon_id 4_color_theorem matches 13 run data modify storage 4_color_theorem FinalSolution.13 set from storage 4_color_theorem FinalSolutionThis
execute if score reigon_id 4_color_theorem matches 14 run data modify storage 4_color_theorem FinalSolution.14 set from storage 4_color_theorem FinalSolutionThis
execute if score reigon_id 4_color_theorem matches 15 run data modify storage 4_color_theorem FinalSolution.15 set from storage 4_color_theorem FinalSolutionThis
execute if score reigon_id 4_color_theorem matches 16 run data modify storage 4_color_theorem FinalSolution.16 set from storage 4_color_theorem FinalSolutionThis
execute if score reigon_id 4_color_theorem matches 17 run data modify storage 4_color_theorem FinalSolution.17 set from storage 4_color_theorem FinalSolutionThis
execute if score reigon_id 4_color_theorem matches 18 run data modify storage 4_color_theorem FinalSolution.18 set from storage 4_color_theorem FinalSolutionThis
execute if score reigon_id 4_color_theorem matches 19 run data modify storage 4_color_theorem FinalSolution.19 set from storage 4_color_theorem FinalSolutionThis
execute if score reigon_id 4_color_theorem matches 20 run data modify storage 4_color_theorem FinalSolution.20 set from storage 4_color_theorem FinalSolutionThis
execute if score reigon_id 4_color_theorem matches 21 run data modify storage 4_color_theorem FinalSolution.21 set from storage 4_color_theorem FinalSolutionThis
execute if score reigon_id 4_color_theorem matches 22 run data modify storage 4_color_theorem FinalSolution.22 set from storage 4_color_theorem FinalSolutionThis
execute if score reigon_id 4_color_theorem matches 23 run data modify storage 4_color_theorem FinalSolution.23 set from storage 4_color_theorem FinalSolutionThis
execute if score reigon_id 4_color_theorem matches 24 run data modify storage 4_color_theorem FinalSolution.24 set from storage 4_color_theorem FinalSolutionThis
execute if score reigon_id 4_color_theorem matches 25 run data modify storage 4_color_theorem FinalSolution.25 set from storage 4_color_theorem FinalSolutionThis
execute if score reigon_id 4_color_theorem matches 26 run data modify storage 4_color_theorem FinalSolution.26 set from storage 4_color_theorem FinalSolutionThis
execute if score reigon_id 4_color_theorem matches 27 run data modify storage 4_color_theorem FinalSolution.27 set from storage 4_color_theorem FinalSolutionThis
execute if score reigon_id 4_color_theorem matches 28 run data modify storage 4_color_theorem FinalSolution.28 set from storage 4_color_theorem FinalSolutionThis
execute if score reigon_id 4_color_theorem matches 29 run data modify storage 4_color_theorem FinalSolution.29 set from storage 4_color_theorem FinalSolutionThis
execute if score reigon_id 4_color_theorem matches 30 run data modify storage 4_color_theorem FinalSolution.30 set from storage 4_color_theorem FinalSolutionThis
execute if score reigon_id 4_color_theorem matches 31 run data modify storage 4_color_theorem FinalSolution.31 set from storage 4_color_theorem FinalSolutionThis
execute if score reigon_id 4_color_theorem matches 32 run data modify storage 4_color_theorem FinalSolution.32 set from storage 4_color_theorem FinalSolutionThis
execute if score reigon_id 4_color_theorem matches 33 run data modify storage 4_color_theorem FinalSolution.33 set from storage 4_color_theorem FinalSolutionThis
execute if score reigon_id 4_color_theorem matches 34 run data modify storage 4_color_theorem FinalSolution.34 set from storage 4_color_theorem FinalSolutionThis
execute if score reigon_id 4_color_theorem matches 35 run data modify storage 4_color_theorem FinalSolution.35 set from storage 4_color_theorem FinalSolutionThis
execute if score reigon_id 4_color_theorem matches 36 run data modify storage 4_color_theorem FinalSolution.36 set from storage 4_color_theorem FinalSolutionThis
execute if score reigon_id 4_color_theorem matches 37 run data modify storage 4_color_theorem FinalSolution.37 set from storage 4_color_theorem FinalSolutionThis
execute if score reigon_id 4_color_theorem matches 38 run data modify storage 4_color_theorem FinalSolution.38 set from storage 4_color_theorem FinalSolutionThis
execute if score reigon_id 4_color_theorem matches 39 run data modify storage 4_color_theorem FinalSolution.39 set from storage 4_color_theorem FinalSolutionThis
execute if score reigon_id 4_color_theorem matches 40 run data modify storage 4_color_theorem FinalSolution.40 set from storage 4_color_theorem FinalSolutionThis
execute if score reigon_id 4_color_theorem matches 41 run data modify storage 4_color_theorem FinalSolution.41 set from storage 4_color_theorem FinalSolutionThis
execute if score reigon_id 4_color_theorem matches 42 run data modify storage 4_color_theorem FinalSolution.42 set from storage 4_color_theorem FinalSolutionThis
execute if score reigon_id 4_color_theorem matches 43 run data modify storage 4_color_theorem FinalSolution.43 set from storage 4_color_theorem FinalSolutionThis
execute if score reigon_id 4_color_theorem matches 44 run data modify storage 4_color_theorem FinalSolution.44 set from storage 4_color_theorem FinalSolutionThis
execute if score reigon_id 4_color_theorem matches 45 run data modify storage 4_color_theorem FinalSolution.45 set from storage 4_color_theorem FinalSolutionThis
execute if score reigon_id 4_color_theorem matches 46 run data modify storage 4_color_theorem FinalSolution.46 set from storage 4_color_theorem FinalSolutionThis
execute if score reigon_id 4_color_theorem matches 47 run data modify storage 4_color_theorem FinalSolution.47 set from storage 4_color_theorem FinalSolutionThis
execute if score reigon_id 4_color_theorem matches 48 run data modify storage 4_color_theorem FinalSolution.48 set from storage 4_color_theorem FinalSolutionThis
execute if score reigon_id 4_color_theorem matches 49 run data modify storage 4_color_theorem FinalSolution.49 set from storage 4_color_theorem FinalSolutionThis
execute if score reigon_id 4_color_theorem matches 50 run data modify storage 4_color_theorem FinalSolution.50 set from storage 4_color_theorem FinalSolutionThis
execute if score reigon_id 4_color_theorem matches 51 run data modify storage 4_color_theorem FinalSolution.51 set from storage 4_color_theorem FinalSolutionThis
execute if score reigon_id 4_color_theorem matches 52 run data modify storage 4_color_theorem FinalSolution.52 set from storage 4_color_theorem FinalSolutionThis
execute if score reigon_id 4_color_theorem matches 53 run data modify storage 4_color_theorem FinalSolution.53 set from storage 4_color_theorem FinalSolutionThis
execute if score reigon_id 4_color_theorem matches 54 run data modify storage 4_color_theorem FinalSolution.54 set from storage 4_color_theorem FinalSolutionThis
execute if score reigon_id 4_color_theorem matches 55 run data modify storage 4_color_theorem FinalSolution.55 set from storage 4_color_theorem FinalSolutionThis
execute if score reigon_id 4_color_theorem matches 56 run data modify storage 4_color_theorem FinalSolution.56 set from storage 4_color_theorem FinalSolutionThis
execute if score reigon_id 4_color_theorem matches 57 run data modify storage 4_color_theorem FinalSolution.57 set from storage 4_color_theorem FinalSolutionThis
execute if score reigon_id 4_color_theorem matches 58 run data modify storage 4_color_theorem FinalSolution.58 set from storage 4_color_theorem FinalSolutionThis
execute if score reigon_id 4_color_theorem matches 59 run data modify storage 4_color_theorem FinalSolution.59 set from storage 4_color_theorem FinalSolutionThis
execute if score reigon_id 4_color_theorem matches 60 run data modify storage 4_color_theorem FinalSolution.60 set from storage 4_color_theorem FinalSolutionThis
execute if score reigon_id 4_color_theorem matches 61 run data modify storage 4_color_theorem FinalSolution.61 set from storage 4_color_theorem FinalSolutionThis
execute if score reigon_id 4_color_theorem matches 62 run data modify storage 4_color_theorem FinalSolution.62 set from storage 4_color_theorem FinalSolutionThis
execute if score reigon_id 4_color_theorem matches 63 run data modify storage 4_color_theorem FinalSolution.63 set from storage 4_color_theorem FinalSolutionThis
execute if score reigon_id 4_color_theorem matches 64 run data modify storage 4_color_theorem FinalSolution.64 set from storage 4_color_theorem FinalSolutionThis

4_color_theorem:solve/record_possible_sol 用于记录PossibleSolution的穷举函数
execute if score reigon_id 4_color_theorem matches 1 run data modify storage 4_color_theorem PossibleSolution.1 set from storage 4_color_theorem PossibleSolutionThis
execute if score reigon_id 4_color_theorem matches 2 run data modify storage 4_color_theorem PossibleSolution.2 set from storage 4_color_theorem PossibleSolutionThis
execute if score reigon_id 4_color_theorem matches 3 run data modify storage 4_color_theorem PossibleSolution.3 set from storage 4_color_theorem PossibleSolutionThis
execute if score reigon_id 4_color_theorem matches 4 run data modify storage 4_color_theorem PossibleSolution.4 set from storage 4_color_theorem PossibleSolutionThis
execute if score reigon_id 4_color_theorem matches 5 run data modify storage 4_color_theorem PossibleSolution.5 set from storage 4_color_theorem PossibleSolutionThis
execute if score reigon_id 4_color_theorem matches 6 run data modify storage 4_color_theorem PossibleSolution.6 set from storage 4_color_theorem PossibleSolutionThis
execute if score reigon_id 4_color_theorem matches 7 run data modify storage 4_color_theorem PossibleSolution.7 set from storage 4_color_theorem PossibleSolutionThis
execute if score reigon_id 4_color_theorem matches 8 run data modify storage 4_color_theorem PossibleSolution.8 set from storage 4_color_theorem PossibleSolutionThis
execute if score reigon_id 4_color_theorem matches 9 run data modify storage 4_color_theorem PossibleSolution.9 set from storage 4_color_theorem PossibleSolutionThis
execute if score reigon_id 4_color_theorem matches 10 run data modify storage 4_color_theorem PossibleSolution.10 set from storage 4_color_theorem PossibleSolutionThis
execute if score reigon_id 4_color_theorem matches 11 run data modify storage 4_color_theorem PossibleSolution.11 set from storage 4_color_theorem PossibleSolutionThis
execute if score reigon_id 4_color_theorem matches 12 run data modify storage 4_color_theorem PossibleSolution.12 set from storage 4_color_theorem PossibleSolutionThis
execute if score reigon_id 4_color_theorem matches 13 run data modify storage 4_color_theorem PossibleSolution.13 set from storage 4_color_theorem PossibleSolutionThis
execute if score reigon_id 4_color_theorem matches 14 run data modify storage 4_color_theorem PossibleSolution.14 set from storage 4_color_theorem PossibleSolutionThis
execute if score reigon_id 4_color_theorem matches 15 run data modify storage 4_color_theorem PossibleSolution.15 set from storage 4_color_theorem PossibleSolutionThis
execute if score reigon_id 4_color_theorem matches 16 run data modify storage 4_color_theorem PossibleSolution.16 set from storage 4_color_theorem PossibleSolutionThis
execute if score reigon_id 4_color_theorem matches 17 run data modify storage 4_color_theorem PossibleSolution.17 set from storage 4_color_theorem PossibleSolutionThis
execute if score reigon_id 4_color_theorem matches 18 run data modify storage 4_color_theorem PossibleSolution.18 set from storage 4_color_theorem PossibleSolutionThis
execute if score reigon_id 4_color_theorem matches 19 run data modify storage 4_color_theorem PossibleSolution.19 set from storage 4_color_theorem PossibleSolutionThis
execute if score reigon_id 4_color_theorem matches 20 run data modify storage 4_color_theorem PossibleSolution.20 set from storage 4_color_theorem PossibleSolutionThis
execute if score reigon_id 4_color_theorem matches 21 run data modify storage 4_color_theorem PossibleSolution.21 set from storage 4_color_theorem PossibleSolutionThis
execute if score reigon_id 4_color_theorem matches 22 run data modify storage 4_color_theorem PossibleSolution.22 set from storage 4_color_theorem PossibleSolutionThis
execute if score reigon_id 4_color_theorem matches 23 run data modify storage 4_color_theorem PossibleSolution.23 set from storage 4_color_theorem PossibleSolutionThis
execute if score reigon_id 4_color_theorem matches 24 run data modify storage 4_color_theorem PossibleSolution.24 set from storage 4_color_theorem PossibleSolutionThis
execute if score reigon_id 4_color_theorem matches 25 run data modify storage 4_color_theorem PossibleSolution.25 set from storage 4_color_theorem PossibleSolutionThis
execute if score reigon_id 4_color_theorem matches 26 run data modify storage 4_color_theorem PossibleSolution.26 set from storage 4_color_theorem PossibleSolutionThis
execute if score reigon_id 4_color_theorem matches 27 run data modify storage 4_color_theorem PossibleSolution.27 set from storage 4_color_theorem PossibleSolutionThis
execute if score reigon_id 4_color_theorem matches 28 run data modify storage 4_color_theorem PossibleSolution.28 set from storage 4_color_theorem PossibleSolutionThis
execute if score reigon_id 4_color_theorem matches 29 run data modify storage 4_color_theorem PossibleSolution.29 set from storage 4_color_theorem PossibleSolutionThis
execute if score reigon_id 4_color_theorem matches 30 run data modify storage 4_color_theorem PossibleSolution.30 set from storage 4_color_theorem PossibleSolutionThis
execute if score reigon_id 4_color_theorem matches 31 run data modify storage 4_color_theorem PossibleSolution.31 set from storage 4_color_theorem PossibleSolutionThis
execute if score reigon_id 4_color_theorem matches 32 run data modify storage 4_color_theorem PossibleSolution.32 set from storage 4_color_theorem PossibleSolutionThis
execute if score reigon_id 4_color_theorem matches 33 run data modify storage 4_color_theorem PossibleSolution.33 set from storage 4_color_theorem PossibleSolutionThis
execute if score reigon_id 4_color_theorem matches 34 run data modify storage 4_color_theorem PossibleSolution.34 set from storage 4_color_theorem PossibleSolutionThis
execute if score reigon_id 4_color_theorem matches 35 run data modify storage 4_color_theorem PossibleSolution.35 set from storage 4_color_theorem PossibleSolutionThis
execute if score reigon_id 4_color_theorem matches 36 run data modify storage 4_color_theorem PossibleSolution.36 set from storage 4_color_theorem PossibleSolutionThis
execute if score reigon_id 4_color_theorem matches 37 run data modify storage 4_color_theorem PossibleSolution.37 set from storage 4_color_theorem PossibleSolutionThis
execute if score reigon_id 4_color_theorem matches 38 run data modify storage 4_color_theorem PossibleSolution.38 set from storage 4_color_theorem PossibleSolutionThis
execute if score reigon_id 4_color_theorem matches 39 run data modify storage 4_color_theorem PossibleSolution.39 set from storage 4_color_theorem PossibleSolutionThis
execute if score reigon_id 4_color_theorem matches 40 run data modify storage 4_color_theorem PossibleSolution.40 set from storage 4_color_theorem PossibleSolutionThis
execute if score reigon_id 4_color_theorem matches 41 run data modify storage 4_color_theorem PossibleSolution.41 set from storage 4_color_theorem PossibleSolutionThis
execute if score reigon_id 4_color_theorem matches 42 run data modify storage 4_color_theorem PossibleSolution.42 set from storage 4_color_theorem PossibleSolutionThis
execute if score reigon_id 4_color_theorem matches 43 run data modify storage 4_color_theorem PossibleSolution.43 set from storage 4_color_theorem PossibleSolutionThis
execute if score reigon_id 4_color_theorem matches 44 run data modify storage 4_color_theorem PossibleSolution.44 set from storage 4_color_theorem PossibleSolutionThis
execute if score reigon_id 4_color_theorem matches 45 run data modify storage 4_color_theorem PossibleSolution.45 set from storage 4_color_theorem PossibleSolutionThis
execute if score reigon_id 4_color_theorem matches 46 run data modify storage 4_color_theorem PossibleSolution.46 set from storage 4_color_theorem PossibleSolutionThis
execute if score reigon_id 4_color_theorem matches 47 run data modify storage 4_color_theorem PossibleSolution.47 set from storage 4_color_theorem PossibleSolutionThis
execute if score reigon_id 4_color_theorem matches 48 run data modify storage 4_color_theorem PossibleSolution.48 set from storage 4_color_theorem PossibleSolutionThis
execute if score reigon_id 4_color_theorem matches 49 run data modify storage 4_color_theorem PossibleSolution.49 set from storage 4_color_theorem PossibleSolutionThis
execute if score reigon_id 4_color_theorem matches 50 run data modify storage 4_color_theorem PossibleSolution.50 set from storage 4_color_theorem PossibleSolutionThis
execute if score reigon_id 4_color_theorem matches 51 run data modify storage 4_color_theorem PossibleSolution.51 set from storage 4_color_theorem PossibleSolutionThis
execute if score reigon_id 4_color_theorem matches 52 run data modify storage 4_color_theorem PossibleSolution.52 set from storage 4_color_theorem PossibleSolutionThis
execute if score reigon_id 4_color_theorem matches 53 run data modify storage 4_color_theorem PossibleSolution.53 set from storage 4_color_theorem PossibleSolutionThis
execute if score reigon_id 4_color_theorem matches 54 run data modify storage 4_color_theorem PossibleSolution.54 set from storage 4_color_theorem PossibleSolutionThis
execute if score reigon_id 4_color_theorem matches 55 run data modify storage 4_color_theorem PossibleSolution.55 set from storage 4_color_theorem PossibleSolutionThis
execute if score reigon_id 4_color_theorem matches 56 run data modify storage 4_color_theorem PossibleSolution.56 set from storage 4_color_theorem PossibleSolutionThis
execute if score reigon_id 4_color_theorem matches 57 run data modify storage 4_color_theorem PossibleSolution.57 set from storage 4_color_theorem PossibleSolutionThis
execute if score reigon_id 4_color_theorem matches 58 run data modify storage 4_color_theorem PossibleSolution.58 set from storage 4_color_theorem PossibleSolutionThis
execute if score reigon_id 4_color_theorem matches 59 run data modify storage 4_color_theorem PossibleSolution.59 set from storage 4_color_theorem PossibleSolutionThis
execute if score reigon_id 4_color_theorem matches 60 run data modify storage 4_color_theorem PossibleSolution.60 set from storage 4_color_theorem PossibleSolutionThis
execute if score reigon_id 4_color_theorem matches 61 run data modify storage 4_color_theorem PossibleSolution.61 set from storage 4_color_theorem PossibleSolutionThis
execute if score reigon_id 4_color_theorem matches 62 run data modify storage 4_color_theorem PossibleSolution.62 set from storage 4_color_theorem PossibleSolutionThis
execute if score reigon_id 4_color_theorem matches 63 run data modify storage 4_color_theorem PossibleSolution.63 set from storage 4_color_theorem PossibleSolutionThis
execute if score reigon_id 4_color_theorem matches 64 run data modify storage 4_color_theorem PossibleSolution.64 set from storage 4_color_theorem PossibleSolutionThis





3.3.4 错解的标记与绕过

   如果在分析可用填色时发现无可用填色,说明附近的一个已有填色的区域的填色出错了。由于不知道具体是哪个区域出错,还是只能一个个试。我的选择是为附近的编号比当前编号小的编号最大的区域重新填色。
   首先通过穷举函数获取附近的编号最大但又比当前区域编号小的区域,保存至NearestId中,并转移至记分板。通过穷举函数获取该编号的区域记录下的PossibleSolution和FinalSolution,分别保存至PossibleSolutionThis和FinalSolutionThis中。再通过穷举在PossibleSolutionThis中将FinalSolutionThis的解标记为不可用(0b)。随后复制好其他信息,重新分析PossibleSolutionThis中是否有可用解。
   重新分析的过程中,PossibleSolutionThis是直接从之前的记录中获取的,因此不再需要初始化(甚至因为做过标记,而不能进行初始化)。
   这里讨论一下之前留下的一个问题。如果区域x填充后,区域y被认定无解,而区域x又恰好是编号比y小的区域中编号最大的一个,那么重新填充的x是否要依据其他有填充而编号又比x大的区域进行填充?(比如,区域4和区域5,6相邻,区域5,6互相不相邻,而区域6被认定无解,此时区域4的填充是否需要考虑区域5的填充)
   我的观点是,此处区域4的填充不应参考区域5的填充。因为首先区域5的填充是参考了区域4的,如果区域4有变,那么区域5的填充也会有变化。那么,在之前情形下得到的结论在这种情形下不再适用,所以不应直接使用。因此,区域4的可用填充可以直接从记录中获取,而区域5的填充则需要重新初始化,并重新讨论分析。

相关函数:
4_color_theorem:solve/back_to_nearest_area 用于错解绕过的主要函数,同时穷举对错误的PossibleSolution进行标记
#获取id最大且比当前id小的相邻区域id
data remove storage 4_color_theorem NearestId
function 4_color_theorem:solve/copy_to_temp
function 4_color_theorem:solve/get_nearest_id
execute store result score reigon_id 4_color_theorem run data get storage 4_color_theorem NearestId
#获取记录的可用填充,移动至PossibleSolutionThis
function 4_color_theorem:solve/copy_possible_sol
#获取记录的当前正在使用的填充,标记为不可用
function 4_color_theorem:solve/copy_final_sol
execute if data storage 4_color_theorem {FinalSolutionThis:1b} run data modify storage 4_color_theorem PossibleSolutionThis.1 set value 0b
execute if data storage 4_color_theorem {FinalSolutionThis:2b} run data modify storage 4_color_theorem PossibleSolutionThis.2 set value 0b
execute if data storage 4_color_theorem {FinalSolutionThis:3b} run data modify storage 4_color_theorem PossibleSolutionThis.3 set value 0b
execute if data storage 4_color_theorem {FinalSolutionThis:4b} run data modify storage 4_color_theorem PossibleSolutionThis.4 set value 0b
#继续分析是否有可用填充
function 4_color_theorem:solve/get_final_sol_this

4_color_theorem:solve/get_nearest_id 用于获取附近编号最大而又比当前区域小的穷举函数
execute if score reigon_id 4_color_theorem matches 1.. if data storage 4_color_theorem Temp.1 run data merge storage 4_color_theorem {NearestId:1b}
execute if score reigon_id 4_color_theorem matches 2.. if data storage 4_color_theorem Temp.2 run data merge storage 4_color_theorem {NearestId:2b}
execute if score reigon_id 4_color_theorem matches 3.. if data storage 4_color_theorem Temp.3 run data merge storage 4_color_theorem {NearestId:3b}
execute if score reigon_id 4_color_theorem matches 4.. if data storage 4_color_theorem Temp.4 run data merge storage 4_color_theorem {NearestId:4b}
execute if score reigon_id 4_color_theorem matches 5.. if data storage 4_color_theorem Temp.5 run data merge storage 4_color_theorem {NearestId:5b}
execute if score reigon_id 4_color_theorem matches 6.. if data storage 4_color_theorem Temp.6 run data merge storage 4_color_theorem {NearestId:6b}
execute if score reigon_id 4_color_theorem matches 7.. if data storage 4_color_theorem Temp.7 run data merge storage 4_color_theorem {NearestId:7b}
execute if score reigon_id 4_color_theorem matches 8.. if data storage 4_color_theorem Temp.8 run data merge storage 4_color_theorem {NearestId:8b}
execute if score reigon_id 4_color_theorem matches 9.. if data storage 4_color_theorem Temp.9 run data merge storage 4_color_theorem {NearestId:9b}
execute if score reigon_id 4_color_theorem matches 10.. if data storage 4_color_theorem Temp.10 run data merge storage 4_color_theorem {NearestId:10b}
execute if score reigon_id 4_color_theorem matches 11.. if data storage 4_color_theorem Temp.11 run data merge storage 4_color_theorem {NearestId:11b}
execute if score reigon_id 4_color_theorem matches 12.. if data storage 4_color_theorem Temp.12 run data merge storage 4_color_theorem {NearestId:12b}
execute if score reigon_id 4_color_theorem matches 13.. if data storage 4_color_theorem Temp.13 run data merge storage 4_color_theorem {NearestId:13b}
execute if score reigon_id 4_color_theorem matches 14.. if data storage 4_color_theorem Temp.14 run data merge storage 4_color_theorem {NearestId:14b}
execute if score reigon_id 4_color_theorem matches 15.. if data storage 4_color_theorem Temp.15 run data merge storage 4_color_theorem {NearestId:15b}
execute if score reigon_id 4_color_theorem matches 16.. if data storage 4_color_theorem Temp.16 run data merge storage 4_color_theorem {NearestId:16b}
execute if score reigon_id 4_color_theorem matches 17.. if data storage 4_color_theorem Temp.17 run data merge storage 4_color_theorem {NearestId:17b}
execute if score reigon_id 4_color_theorem matches 18.. if data storage 4_color_theorem Temp.18 run data merge storage 4_color_theorem {NearestId:18b}
execute if score reigon_id 4_color_theorem matches 19.. if data storage 4_color_theorem Temp.19 run data merge storage 4_color_theorem {NearestId:19b}
execute if score reigon_id 4_color_theorem matches 20.. if data storage 4_color_theorem Temp.20 run data merge storage 4_color_theorem {NearestId:20b}
execute if score reigon_id 4_color_theorem matches 21.. if data storage 4_color_theorem Temp.21 run data merge storage 4_color_theorem {NearestId:21b}
execute if score reigon_id 4_color_theorem matches 22.. if data storage 4_color_theorem Temp.22 run data merge storage 4_color_theorem {NearestId:22b}
execute if score reigon_id 4_color_theorem matches 23.. if data storage 4_color_theorem Temp.23 run data merge storage 4_color_theorem {NearestId:23b}
execute if score reigon_id 4_color_theorem matches 24.. if data storage 4_color_theorem Temp.24 run data merge storage 4_color_theorem {NearestId:24b}
execute if score reigon_id 4_color_theorem matches 25.. if data storage 4_color_theorem Temp.25 run data merge storage 4_color_theorem {NearestId:25b}
execute if score reigon_id 4_color_theorem matches 26.. if data storage 4_color_theorem Temp.26 run data merge storage 4_color_theorem {NearestId:26b}
execute if score reigon_id 4_color_theorem matches 27.. if data storage 4_color_theorem Temp.27 run data merge storage 4_color_theorem {NearestId:27b}
execute if score reigon_id 4_color_theorem matches 28.. if data storage 4_color_theorem Temp.28 run data merge storage 4_color_theorem {NearestId:28b}
execute if score reigon_id 4_color_theorem matches 29.. if data storage 4_color_theorem Temp.29 run data merge storage 4_color_theorem {NearestId:29b}
execute if score reigon_id 4_color_theorem matches 30.. if data storage 4_color_theorem Temp.30 run data merge storage 4_color_theorem {NearestId:30b}
execute if score reigon_id 4_color_theorem matches 31.. if data storage 4_color_theorem Temp.31 run data merge storage 4_color_theorem {NearestId:31b}
execute if score reigon_id 4_color_theorem matches 32.. if data storage 4_color_theorem Temp.32 run data merge storage 4_color_theorem {NearestId:32b}
execute if score reigon_id 4_color_theorem matches 33.. if data storage 4_color_theorem Temp.33 run data merge storage 4_color_theorem {NearestId:33b}
execute if score reigon_id 4_color_theorem matches 34.. if data storage 4_color_theorem Temp.34 run data merge storage 4_color_theorem {NearestId:34b}
execute if score reigon_id 4_color_theorem matches 35.. if data storage 4_color_theorem Temp.35 run data merge storage 4_color_theorem {NearestId:35b}
execute if score reigon_id 4_color_theorem matches 36.. if data storage 4_color_theorem Temp.36 run data merge storage 4_color_theorem {NearestId:36b}
execute if score reigon_id 4_color_theorem matches 37.. if data storage 4_color_theorem Temp.37 run data merge storage 4_color_theorem {NearestId:37b}
execute if score reigon_id 4_color_theorem matches 38.. if data storage 4_color_theorem Temp.38 run data merge storage 4_color_theorem {NearestId:38b}
execute if score reigon_id 4_color_theorem matches 39.. if data storage 4_color_theorem Temp.39 run data merge storage 4_color_theorem {NearestId:39b}
execute if score reigon_id 4_color_theorem matches 40.. if data storage 4_color_theorem Temp.40 run data merge storage 4_color_theorem {NearestId:40b}
execute if score reigon_id 4_color_theorem matches 41.. if data storage 4_color_theorem Temp.41 run data merge storage 4_color_theorem {NearestId:41b}
execute if score reigon_id 4_color_theorem matches 42.. if data storage 4_color_theorem Temp.42 run data merge storage 4_color_theorem {NearestId:42b}
execute if score reigon_id 4_color_theorem matches 43.. if data storage 4_color_theorem Temp.43 run data merge storage 4_color_theorem {NearestId:43b}
execute if score reigon_id 4_color_theorem matches 44.. if data storage 4_color_theorem Temp.44 run data merge storage 4_color_theorem {NearestId:44b}
execute if score reigon_id 4_color_theorem matches 45.. if data storage 4_color_theorem Temp.45 run data merge storage 4_color_theorem {NearestId:45b}
execute if score reigon_id 4_color_theorem matches 46.. if data storage 4_color_theorem Temp.46 run data merge storage 4_color_theorem {NearestId:46b}
execute if score reigon_id 4_color_theorem matches 47.. if data storage 4_color_theorem Temp.47 run data merge storage 4_color_theorem {NearestId:47b}
execute if score reigon_id 4_color_theorem matches 48.. if data storage 4_color_theorem Temp.48 run data merge storage 4_color_theorem {NearestId:48b}
execute if score reigon_id 4_color_theorem matches 49.. if data storage 4_color_theorem Temp.49 run data merge storage 4_color_theorem {NearestId:49b}
execute if score reigon_id 4_color_theorem matches 50.. if data storage 4_color_theorem Temp.50 run data merge storage 4_color_theorem {NearestId:50b}
execute if score reigon_id 4_color_theorem matches 51.. if data storage 4_color_theorem Temp.51 run data merge storage 4_color_theorem {NearestId:51b}
execute if score reigon_id 4_color_theorem matches 52.. if data storage 4_color_theorem Temp.52 run data merge storage 4_color_theorem {NearestId:52b}
execute if score reigon_id 4_color_theorem matches 53.. if data storage 4_color_theorem Temp.53 run data merge storage 4_color_theorem {NearestId:53b}
execute if score reigon_id 4_color_theorem matches 54.. if data storage 4_color_theorem Temp.54 run data merge storage 4_color_theorem {NearestId:54b}
execute if score reigon_id 4_color_theorem matches 55.. if data storage 4_color_theorem Temp.55 run data merge storage 4_color_theorem {NearestId:55b}
execute if score reigon_id 4_color_theorem matches 56.. if data storage 4_color_theorem Temp.56 run data merge storage 4_color_theorem {NearestId:56b}
execute if score reigon_id 4_color_theorem matches 57.. if data storage 4_color_theorem Temp.57 run data merge storage 4_color_theorem {NearestId:57b}
execute if score reigon_id 4_color_theorem matches 58.. if data storage 4_color_theorem Temp.58 run data merge storage 4_color_theorem {NearestId:58b}
execute if score reigon_id 4_color_theorem matches 59.. if data storage 4_color_theorem Temp.59 run data merge storage 4_color_theorem {NearestId:59b}
execute if score reigon_id 4_color_theorem matches 60.. if data storage 4_color_theorem Temp.60 run data merge storage 4_color_theorem {NearestId:60b}
execute if score reigon_id 4_color_theorem matches 61.. if data storage 4_color_theorem Temp.61 run data merge storage 4_color_theorem {NearestId:61b}
execute if score reigon_id 4_color_theorem matches 62.. if data storage 4_color_theorem Temp.62 run data merge storage 4_color_theorem {NearestId:62b}
execute if score reigon_id 4_color_theorem matches 63.. if data storage 4_color_theorem Temp.63 run data merge storage 4_color_theorem {NearestId:63b}
execute if score reigon_id 4_color_theorem matches 64.. if data storage 4_color_theorem Temp.64 run data merge storage 4_color_theorem {NearestId:64b}

4_color_theorem:solve/copy_possible_sol 用于获取目标编号的PossibleSolution的穷举函数
execute if score reigon_id 4_color_theorem matches 1 run data modify storage 4_color_theorem PossibleSolutionThis set from storage 4_color_theorem PossibleSolution.1
execute if score reigon_id 4_color_theorem matches 2 run data modify storage 4_color_theorem PossibleSolutionThis set from storage 4_color_theorem PossibleSolution.2
execute if score reigon_id 4_color_theorem matches 3 run data modify storage 4_color_theorem PossibleSolutionThis set from storage 4_color_theorem PossibleSolution.3
execute if score reigon_id 4_color_theorem matches 4 run data modify storage 4_color_theorem PossibleSolutionThis set from storage 4_color_theorem PossibleSolution.4
execute if score reigon_id 4_color_theorem matches 5 run data modify storage 4_color_theorem PossibleSolutionThis set from storage 4_color_theorem PossibleSolution.5
execute if score reigon_id 4_color_theorem matches 6 run data modify storage 4_color_theorem PossibleSolutionThis set from storage 4_color_theorem PossibleSolution.6
execute if score reigon_id 4_color_theorem matches 7 run data modify storage 4_color_theorem PossibleSolutionThis set from storage 4_color_theorem PossibleSolution.7
execute if score reigon_id 4_color_theorem matches 8 run data modify storage 4_color_theorem PossibleSolutionThis set from storage 4_color_theorem PossibleSolution.8
execute if score reigon_id 4_color_theorem matches 9 run data modify storage 4_color_theorem PossibleSolutionThis set from storage 4_color_theorem PossibleSolution.9
execute if score reigon_id 4_color_theorem matches 10 run data modify storage 4_color_theorem PossibleSolutionThis set from storage 4_color_theorem PossibleSolution.10
execute if score reigon_id 4_color_theorem matches 11 run data modify storage 4_color_theorem PossibleSolutionThis set from storage 4_color_theorem PossibleSolution.11
execute if score reigon_id 4_color_theorem matches 12 run data modify storage 4_color_theorem PossibleSolutionThis set from storage 4_color_theorem PossibleSolution.12
execute if score reigon_id 4_color_theorem matches 13 run data modify storage 4_color_theorem PossibleSolutionThis set from storage 4_color_theorem PossibleSolution.13
execute if score reigon_id 4_color_theorem matches 14 run data modify storage 4_color_theorem PossibleSolutionThis set from storage 4_color_theorem PossibleSolution.14
execute if score reigon_id 4_color_theorem matches 15 run data modify storage 4_color_theorem PossibleSolutionThis set from storage 4_color_theorem PossibleSolution.15
execute if score reigon_id 4_color_theorem matches 16 run data modify storage 4_color_theorem PossibleSolutionThis set from storage 4_color_theorem PossibleSolution.16
execute if score reigon_id 4_color_theorem matches 17 run data modify storage 4_color_theorem PossibleSolutionThis set from storage 4_color_theorem PossibleSolution.17
execute if score reigon_id 4_color_theorem matches 18 run data modify storage 4_color_theorem PossibleSolutionThis set from storage 4_color_theorem PossibleSolution.18
execute if score reigon_id 4_color_theorem matches 19 run data modify storage 4_color_theorem PossibleSolutionThis set from storage 4_color_theorem PossibleSolution.19
execute if score reigon_id 4_color_theorem matches 20 run data modify storage 4_color_theorem PossibleSolutionThis set from storage 4_color_theorem PossibleSolution.20
execute if score reigon_id 4_color_theorem matches 21 run data modify storage 4_color_theorem PossibleSolutionThis set from storage 4_color_theorem PossibleSolution.21
execute if score reigon_id 4_color_theorem matches 22 run data modify storage 4_color_theorem PossibleSolutionThis set from storage 4_color_theorem PossibleSolution.22
execute if score reigon_id 4_color_theorem matches 23 run data modify storage 4_color_theorem PossibleSolutionThis set from storage 4_color_theorem PossibleSolution.23
execute if score reigon_id 4_color_theorem matches 24 run data modify storage 4_color_theorem PossibleSolutionThis set from storage 4_color_theorem PossibleSolution.24
execute if score reigon_id 4_color_theorem matches 25 run data modify storage 4_color_theorem PossibleSolutionThis set from storage 4_color_theorem PossibleSolution.25
execute if score reigon_id 4_color_theorem matches 26 run data modify storage 4_color_theorem PossibleSolutionThis set from storage 4_color_theorem PossibleSolution.26
execute if score reigon_id 4_color_theorem matches 27 run data modify storage 4_color_theorem PossibleSolutionThis set from storage 4_color_theorem PossibleSolution.27
execute if score reigon_id 4_color_theorem matches 28 run data modify storage 4_color_theorem PossibleSolutionThis set from storage 4_color_theorem PossibleSolution.28
execute if score reigon_id 4_color_theorem matches 29 run data modify storage 4_color_theorem PossibleSolutionThis set from storage 4_color_theorem PossibleSolution.29
execute if score reigon_id 4_color_theorem matches 30 run data modify storage 4_color_theorem PossibleSolutionThis set from storage 4_color_theorem PossibleSolution.30
execute if score reigon_id 4_color_theorem matches 31 run data modify storage 4_color_theorem PossibleSolutionThis set from storage 4_color_theorem PossibleSolution.31
execute if score reigon_id 4_color_theorem matches 32 run data modify storage 4_color_theorem PossibleSolutionThis set from storage 4_color_theorem PossibleSolution.32
execute if score reigon_id 4_color_theorem matches 33 run data modify storage 4_color_theorem PossibleSolutionThis set from storage 4_color_theorem PossibleSolution.33
execute if score reigon_id 4_color_theorem matches 34 run data modify storage 4_color_theorem PossibleSolutionThis set from storage 4_color_theorem PossibleSolution.34
execute if score reigon_id 4_color_theorem matches 35 run data modify storage 4_color_theorem PossibleSolutionThis set from storage 4_color_theorem PossibleSolution.35
execute if score reigon_id 4_color_theorem matches 36 run data modify storage 4_color_theorem PossibleSolutionThis set from storage 4_color_theorem PossibleSolution.36
execute if score reigon_id 4_color_theorem matches 37 run data modify storage 4_color_theorem PossibleSolutionThis set from storage 4_color_theorem PossibleSolution.37
execute if score reigon_id 4_color_theorem matches 38 run data modify storage 4_color_theorem PossibleSolutionThis set from storage 4_color_theorem PossibleSolution.38
execute if score reigon_id 4_color_theorem matches 39 run data modify storage 4_color_theorem PossibleSolutionThis set from storage 4_color_theorem PossibleSolution.39
execute if score reigon_id 4_color_theorem matches 40 run data modify storage 4_color_theorem PossibleSolutionThis set from storage 4_color_theorem PossibleSolution.40
execute if score reigon_id 4_color_theorem matches 41 run data modify storage 4_color_theorem PossibleSolutionThis set from storage 4_color_theorem PossibleSolution.41
execute if score reigon_id 4_color_theorem matches 42 run data modify storage 4_color_theorem PossibleSolutionThis set from storage 4_color_theorem PossibleSolution.42
execute if score reigon_id 4_color_theorem matches 43 run data modify storage 4_color_theorem PossibleSolutionThis set from storage 4_color_theorem PossibleSolution.43
execute if score reigon_id 4_color_theorem matches 44 run data modify storage 4_color_theorem PossibleSolutionThis set from storage 4_color_theorem PossibleSolution.44
execute if score reigon_id 4_color_theorem matches 45 run data modify storage 4_color_theorem PossibleSolutionThis set from storage 4_color_theorem PossibleSolution.45
execute if score reigon_id 4_color_theorem matches 46 run data modify storage 4_color_theorem PossibleSolutionThis set from storage 4_color_theorem PossibleSolution.46
execute if score reigon_id 4_color_theorem matches 47 run data modify storage 4_color_theorem PossibleSolutionThis set from storage 4_color_theorem PossibleSolution.47
execute if score reigon_id 4_color_theorem matches 48 run data modify storage 4_color_theorem PossibleSolutionThis set from storage 4_color_theorem PossibleSolution.48
execute if score reigon_id 4_color_theorem matches 49 run data modify storage 4_color_theorem PossibleSolutionThis set from storage 4_color_theorem PossibleSolution.49
execute if score reigon_id 4_color_theorem matches 50 run data modify storage 4_color_theorem PossibleSolutionThis set from storage 4_color_theorem PossibleSolution.50
execute if score reigon_id 4_color_theorem matches 51 run data modify storage 4_color_theorem PossibleSolutionThis set from storage 4_color_theorem PossibleSolution.51
execute if score reigon_id 4_color_theorem matches 52 run data modify storage 4_color_theorem PossibleSolutionThis set from storage 4_color_theorem PossibleSolution.52
execute if score reigon_id 4_color_theorem matches 53 run data modify storage 4_color_theorem PossibleSolutionThis set from storage 4_color_theorem PossibleSolution.53
execute if score reigon_id 4_color_theorem matches 54 run data modify storage 4_color_theorem PossibleSolutionThis set from storage 4_color_theorem PossibleSolution.54
execute if score reigon_id 4_color_theorem matches 55 run data modify storage 4_color_theorem PossibleSolutionThis set from storage 4_color_theorem PossibleSolution.55
execute if score reigon_id 4_color_theorem matches 56 run data modify storage 4_color_theorem PossibleSolutionThis set from storage 4_color_theorem PossibleSolution.56
execute if score reigon_id 4_color_theorem matches 57 run data modify storage 4_color_theorem PossibleSolutionThis set from storage 4_color_theorem PossibleSolution.57
execute if score reigon_id 4_color_theorem matches 58 run data modify storage 4_color_theorem PossibleSolutionThis set from storage 4_color_theorem PossibleSolution.58
execute if score reigon_id 4_color_theorem matches 59 run data modify storage 4_color_theorem PossibleSolutionThis set from storage 4_color_theorem PossibleSolution.59
execute if score reigon_id 4_color_theorem matches 60 run data modify storage 4_color_theorem PossibleSolutionThis set from storage 4_color_theorem PossibleSolution.60
execute if score reigon_id 4_color_theorem matches 61 run data modify storage 4_color_theorem PossibleSolutionThis set from storage 4_color_theorem PossibleSolution.61
execute if score reigon_id 4_color_theorem matches 62 run data modify storage 4_color_theorem PossibleSolutionThis set from storage 4_color_theorem PossibleSolution.62
execute if score reigon_id 4_color_theorem matches 63 run data modify storage 4_color_theorem PossibleSolutionThis set from storage 4_color_theorem PossibleSolution.63
execute if score reigon_id 4_color_theorem matches 64 run data modify storage 4_color_theorem PossibleSolutionThis set from storage 4_color_theorem PossibleSolution.64

4_color_theorem:solve/copy_final_sol 用于获取目标编号的FinalSolution的穷举函数
execute if score reigon_id 4_color_theorem matches 1 run data modify storage 4_color_theorem FinalSolutionThis set from storage 4_color_theorem FinalSolution.1
execute if score reigon_id 4_color_theorem matches 2 run data modify storage 4_color_theorem FinalSolutionThis set from storage 4_color_theorem FinalSolution.2
execute if score reigon_id 4_color_theorem matches 3 run data modify storage 4_color_theorem FinalSolutionThis set from storage 4_color_theorem FinalSolution.3
execute if score reigon_id 4_color_theorem matches 4 run data modify storage 4_color_theorem FinalSolutionThis set from storage 4_color_theorem FinalSolution.4
execute if score reigon_id 4_color_theorem matches 5 run data modify storage 4_color_theorem FinalSolutionThis set from storage 4_color_theorem FinalSolution.5
execute if score reigon_id 4_color_theorem matches 6 run data modify storage 4_color_theorem FinalSolutionThis set from storage 4_color_theorem FinalSolution.6
execute if score reigon_id 4_color_theorem matches 7 run data modify storage 4_color_theorem FinalSolutionThis set from storage 4_color_theorem FinalSolution.7
execute if score reigon_id 4_color_theorem matches 8 run data modify storage 4_color_theorem FinalSolutionThis set from storage 4_color_theorem FinalSolution.8
execute if score reigon_id 4_color_theorem matches 9 run data modify storage 4_color_theorem FinalSolutionThis set from storage 4_color_theorem FinalSolution.9
execute if score reigon_id 4_color_theorem matches 10 run data modify storage 4_color_theorem FinalSolutionThis set from storage 4_color_theorem FinalSolution.10
execute if score reigon_id 4_color_theorem matches 11 run data modify storage 4_color_theorem FinalSolutionThis set from storage 4_color_theorem FinalSolution.11
execute if score reigon_id 4_color_theorem matches 12 run data modify storage 4_color_theorem FinalSolutionThis set from storage 4_color_theorem FinalSolution.12
execute if score reigon_id 4_color_theorem matches 13 run data modify storage 4_color_theorem FinalSolutionThis set from storage 4_color_theorem FinalSolution.13
execute if score reigon_id 4_color_theorem matches 14 run data modify storage 4_color_theorem FinalSolutionThis set from storage 4_color_theorem FinalSolution.14
execute if score reigon_id 4_color_theorem matches 15 run data modify storage 4_color_theorem FinalSolutionThis set from storage 4_color_theorem FinalSolution.15
execute if score reigon_id 4_color_theorem matches 16 run data modify storage 4_color_theorem FinalSolutionThis set from storage 4_color_theorem FinalSolution.16
execute if score reigon_id 4_color_theorem matches 17 run data modify storage 4_color_theorem FinalSolutionThis set from storage 4_color_theorem FinalSolution.17
execute if score reigon_id 4_color_theorem matches 18 run data modify storage 4_color_theorem FinalSolutionThis set from storage 4_color_theorem FinalSolution.18
execute if score reigon_id 4_color_theorem matches 19 run data modify storage 4_color_theorem FinalSolutionThis set from storage 4_color_theorem FinalSolution.19
execute if score reigon_id 4_color_theorem matches 20 run data modify storage 4_color_theorem FinalSolutionThis set from storage 4_color_theorem FinalSolution.20
execute if score reigon_id 4_color_theorem matches 21 run data modify storage 4_color_theorem FinalSolutionThis set from storage 4_color_theorem FinalSolution.21
execute if score reigon_id 4_color_theorem matches 22 run data modify storage 4_color_theorem FinalSolutionThis set from storage 4_color_theorem FinalSolution.22
execute if score reigon_id 4_color_theorem matches 23 run data modify storage 4_color_theorem FinalSolutionThis set from storage 4_color_theorem FinalSolution.23
execute if score reigon_id 4_color_theorem matches 24 run data modify storage 4_color_theorem FinalSolutionThis set from storage 4_color_theorem FinalSolution.24
execute if score reigon_id 4_color_theorem matches 25 run data modify storage 4_color_theorem FinalSolutionThis set from storage 4_color_theorem FinalSolution.25
execute if score reigon_id 4_color_theorem matches 26 run data modify storage 4_color_theorem FinalSolutionThis set from storage 4_color_theorem FinalSolution.26
execute if score reigon_id 4_color_theorem matches 27 run data modify storage 4_color_theorem FinalSolutionThis set from storage 4_color_theorem FinalSolution.27
execute if score reigon_id 4_color_theorem matches 28 run data modify storage 4_color_theorem FinalSolutionThis set from storage 4_color_theorem FinalSolution.28
execute if score reigon_id 4_color_theorem matches 29 run data modify storage 4_color_theorem FinalSolutionThis set from storage 4_color_theorem FinalSolution.29
execute if score reigon_id 4_color_theorem matches 30 run data modify storage 4_color_theorem FinalSolutionThis set from storage 4_color_theorem FinalSolution.30
execute if score reigon_id 4_color_theorem matches 31 run data modify storage 4_color_theorem FinalSolutionThis set from storage 4_color_theorem FinalSolution.31
execute if score reigon_id 4_color_theorem matches 32 run data modify storage 4_color_theorem FinalSolutionThis set from storage 4_color_theorem FinalSolution.32
execute if score reigon_id 4_color_theorem matches 33 run data modify storage 4_color_theorem FinalSolutionThis set from storage 4_color_theorem FinalSolution.33
execute if score reigon_id 4_color_theorem matches 34 run data modify storage 4_color_theorem FinalSolutionThis set from storage 4_color_theorem FinalSolution.34
execute if score reigon_id 4_color_theorem matches 35 run data modify storage 4_color_theorem FinalSolutionThis set from storage 4_color_theorem FinalSolution.35
execute if score reigon_id 4_color_theorem matches 36 run data modify storage 4_color_theorem FinalSolutionThis set from storage 4_color_theorem FinalSolution.36
execute if score reigon_id 4_color_theorem matches 37 run data modify storage 4_color_theorem FinalSolutionThis set from storage 4_color_theorem FinalSolution.37
execute if score reigon_id 4_color_theorem matches 38 run data modify storage 4_color_theorem FinalSolutionThis set from storage 4_color_theorem FinalSolution.38
execute if score reigon_id 4_color_theorem matches 39 run data modify storage 4_color_theorem FinalSolutionThis set from storage 4_color_theorem FinalSolution.39
execute if score reigon_id 4_color_theorem matches 40 run data modify storage 4_color_theorem FinalSolutionThis set from storage 4_color_theorem FinalSolution.40
execute if score reigon_id 4_color_theorem matches 41 run data modify storage 4_color_theorem FinalSolutionThis set from storage 4_color_theorem FinalSolution.41
execute if score reigon_id 4_color_theorem matches 42 run data modify storage 4_color_theorem FinalSolutionThis set from storage 4_color_theorem FinalSolution.42
execute if score reigon_id 4_color_theorem matches 43 run data modify storage 4_color_theorem FinalSolutionThis set from storage 4_color_theorem FinalSolution.43
execute if score reigon_id 4_color_theorem matches 44 run data modify storage 4_color_theorem FinalSolutionThis set from storage 4_color_theorem FinalSolution.44
execute if score reigon_id 4_color_theorem matches 45 run data modify storage 4_color_theorem FinalSolutionThis set from storage 4_color_theorem FinalSolution.45
execute if score reigon_id 4_color_theorem matches 46 run data modify storage 4_color_theorem FinalSolutionThis set from storage 4_color_theorem FinalSolution.46
execute if score reigon_id 4_color_theorem matches 47 run data modify storage 4_color_theorem FinalSolutionThis set from storage 4_color_theorem FinalSolution.47
execute if score reigon_id 4_color_theorem matches 48 run data modify storage 4_color_theorem FinalSolutionThis set from storage 4_color_theorem FinalSolution.48
execute if score reigon_id 4_color_theorem matches 49 run data modify storage 4_color_theorem FinalSolutionThis set from storage 4_color_theorem FinalSolution.49
execute if score reigon_id 4_color_theorem matches 50 run data modify storage 4_color_theorem FinalSolutionThis set from storage 4_color_theorem FinalSolution.50
execute if score reigon_id 4_color_theorem matches 51 run data modify storage 4_color_theorem FinalSolutionThis set from storage 4_color_theorem FinalSolution.51
execute if score reigon_id 4_color_theorem matches 52 run data modify storage 4_color_theorem FinalSolutionThis set from storage 4_color_theorem FinalSolution.52
execute if score reigon_id 4_color_theorem matches 53 run data modify storage 4_color_theorem FinalSolutionThis set from storage 4_color_theorem FinalSolution.53
execute if score reigon_id 4_color_theorem matches 54 run data modify storage 4_color_theorem FinalSolutionThis set from storage 4_color_theorem FinalSolution.54
execute if score reigon_id 4_color_theorem matches 55 run data modify storage 4_color_theorem FinalSolutionThis set from storage 4_color_theorem FinalSolution.55
execute if score reigon_id 4_color_theorem matches 56 run data modify storage 4_color_theorem FinalSolutionThis set from storage 4_color_theorem FinalSolution.56
execute if score reigon_id 4_color_theorem matches 57 run data modify storage 4_color_theorem FinalSolutionThis set from storage 4_color_theorem FinalSolution.57
execute if score reigon_id 4_color_theorem matches 58 run data modify storage 4_color_theorem FinalSolutionThis set from storage 4_color_theorem FinalSolution.58
execute if score reigon_id 4_color_theorem matches 59 run data modify storage 4_color_theorem FinalSolutionThis set from storage 4_color_theorem FinalSolution.59
execute if score reigon_id 4_color_theorem matches 60 run data modify storage 4_color_theorem FinalSolutionThis set from storage 4_color_theorem FinalSolution.60
execute if score reigon_id 4_color_theorem matches 61 run data modify storage 4_color_theorem FinalSolutionThis set from storage 4_color_theorem FinalSolution.61
execute if score reigon_id 4_color_theorem matches 62 run data modify storage 4_color_theorem FinalSolutionThis set from storage 4_color_theorem FinalSolution.62
execute if score reigon_id 4_color_theorem matches 63 run data modify storage 4_color_theorem FinalSolutionThis set from storage 4_color_theorem FinalSolution.63
execute if score reigon_id 4_color_theorem matches 64 run data modify storage 4_color_theorem FinalSolutionThis set from storage 4_color_theorem FinalSolution.64





3.4 结果填充

   如果你看到了这儿,那么祝贺你,你可以提前欢呼了,因为后面的东西会非常简单。
   现在我们已经得到了解,它就存在FinalSolution这个nbt中。我们现在需要做的就是把它实装下来。
   流程大概是这样




3.4.1 存储格式转变

   这里转格式嘛,纯属是个人喜好,现在想想,其实不转应该也无妨。
   由于FinalSolution是Compound类型,不便于递归,因此我首先通过穷举将其转化为List。通过识别FinalSolution并使用data modify append转化为List类型,保存至FinalSolutionList当中。结果如下:
   有了List,就能通过递归调用进行颜色填充了。

相关函数:
4_color_theorem:final_fill/compound_to_list 用于将FinalSolution由Compound转List的穷举函数
data modify storage 4_color_theorem FinalSolutionList append from storage 4_color_theorem FinalSolution.1
data modify storage 4_color_theorem FinalSolutionList append from storage 4_color_theorem FinalSolution.2
data modify storage 4_color_theorem FinalSolutionList append from storage 4_color_theorem FinalSolution.3
data modify storage 4_color_theorem FinalSolutionList append from storage 4_color_theorem FinalSolution.4
data modify storage 4_color_theorem FinalSolutionList append from storage 4_color_theorem FinalSolution.5
data modify storage 4_color_theorem FinalSolutionList append from storage 4_color_theorem FinalSolution.6
data modify storage 4_color_theorem FinalSolutionList append from storage 4_color_theorem FinalSolution.7
data modify storage 4_color_theorem FinalSolutionList append from storage 4_color_theorem FinalSolution.8
data modify storage 4_color_theorem FinalSolutionList append from storage 4_color_theorem FinalSolution.9
data modify storage 4_color_theorem FinalSolutionList append from storage 4_color_theorem FinalSolution.10
data modify storage 4_color_theorem FinalSolutionList append from storage 4_color_theorem FinalSolution.11
data modify storage 4_color_theorem FinalSolutionList append from storage 4_color_theorem FinalSolution.12
data modify storage 4_color_theorem FinalSolutionList append from storage 4_color_theorem FinalSolution.13
data modify storage 4_color_theorem FinalSolutionList append from storage 4_color_theorem FinalSolution.14
data modify storage 4_color_theorem FinalSolutionList append from storage 4_color_theorem FinalSolution.15
data modify storage 4_color_theorem FinalSolutionList append from storage 4_color_theorem FinalSolution.16
data modify storage 4_color_theorem FinalSolutionList append from storage 4_color_theorem FinalSolution.17
data modify storage 4_color_theorem FinalSolutionList append from storage 4_color_theorem FinalSolution.18
data modify storage 4_color_theorem FinalSolutionList append from storage 4_color_theorem FinalSolution.19
data modify storage 4_color_theorem FinalSolutionList append from storage 4_color_theorem FinalSolution.20
data modify storage 4_color_theorem FinalSolutionList append from storage 4_color_theorem FinalSolution.21
data modify storage 4_color_theorem FinalSolutionList append from storage 4_color_theorem FinalSolution.22
data modify storage 4_color_theorem FinalSolutionList append from storage 4_color_theorem FinalSolution.23
data modify storage 4_color_theorem FinalSolutionList append from storage 4_color_theorem FinalSolution.24
data modify storage 4_color_theorem FinalSolutionList append from storage 4_color_theorem FinalSolution.25
data modify storage 4_color_theorem FinalSolutionList append from storage 4_color_theorem FinalSolution.26
data modify storage 4_color_theorem FinalSolutionList append from storage 4_color_theorem FinalSolution.27
data modify storage 4_color_theorem FinalSolutionList append from storage 4_color_theorem FinalSolution.28
data modify storage 4_color_theorem FinalSolutionList append from storage 4_color_theorem FinalSolution.29
data modify storage 4_color_theorem FinalSolutionList append from storage 4_color_theorem FinalSolution.30
data modify storage 4_color_theorem FinalSolutionList append from storage 4_color_theorem FinalSolution.31
data modify storage 4_color_theorem FinalSolutionList append from storage 4_color_theorem FinalSolution.32
data modify storage 4_color_theorem FinalSolutionList append from storage 4_color_theorem FinalSolution.33
data modify storage 4_color_theorem FinalSolutionList append from storage 4_color_theorem FinalSolution.34
data modify storage 4_color_theorem FinalSolutionList append from storage 4_color_theorem FinalSolution.35
data modify storage 4_color_theorem FinalSolutionList append from storage 4_color_theorem FinalSolution.36
data modify storage 4_color_theorem FinalSolutionList append from storage 4_color_theorem FinalSolution.37
data modify storage 4_color_theorem FinalSolutionList append from storage 4_color_theorem FinalSolution.38
data modify storage 4_color_theorem FinalSolutionList append from storage 4_color_theorem FinalSolution.39
data modify storage 4_color_theorem FinalSolutionList append from storage 4_color_theorem FinalSolution.40
data modify storage 4_color_theorem FinalSolutionList append from storage 4_color_theorem FinalSolution.41
data modify storage 4_color_theorem FinalSolutionList append from storage 4_color_theorem FinalSolution.42
data modify storage 4_color_theorem FinalSolutionList append from storage 4_color_theorem FinalSolution.43
data modify storage 4_color_theorem FinalSolutionList append from storage 4_color_theorem FinalSolution.44
data modify storage 4_color_theorem FinalSolutionList append from storage 4_color_theorem FinalSolution.45
data modify storage 4_color_theorem FinalSolutionList append from storage 4_color_theorem FinalSolution.46
data modify storage 4_color_theorem FinalSolutionList append from storage 4_color_theorem FinalSolution.47
data modify storage 4_color_theorem FinalSolutionList append from storage 4_color_theorem FinalSolution.48
data modify storage 4_color_theorem FinalSolutionList append from storage 4_color_theorem FinalSolution.49
data modify storage 4_color_theorem FinalSolutionList append from storage 4_color_theorem FinalSolution.50
data modify storage 4_color_theorem FinalSolutionList append from storage 4_color_theorem FinalSolution.51
data modify storage 4_color_theorem FinalSolutionList append from storage 4_color_theorem FinalSolution.52
data modify storage 4_color_theorem FinalSolutionList append from storage 4_color_theorem FinalSolution.53
data modify storage 4_color_theorem FinalSolutionList append from storage 4_color_theorem FinalSolution.54
data modify storage 4_color_theorem FinalSolutionList append from storage 4_color_theorem FinalSolution.55
data modify storage 4_color_theorem FinalSolutionList append from storage 4_color_theorem FinalSolution.56
data modify storage 4_color_theorem FinalSolutionList append from storage 4_color_theorem FinalSolution.57
data modify storage 4_color_theorem FinalSolutionList append from storage 4_color_theorem FinalSolution.58
data modify storage 4_color_theorem FinalSolutionList append from storage 4_color_theorem FinalSolution.59
data modify storage 4_color_theorem FinalSolutionList append from storage 4_color_theorem FinalSolution.60
data modify storage 4_color_theorem FinalSolutionList append from storage 4_color_theorem FinalSolution.61
data modify storage 4_color_theorem FinalSolutionList append from storage 4_color_theorem FinalSolution.62
data modify storage 4_color_theorem FinalSolutionList append from storage 4_color_theorem FinalSolution.63
data modify storage 4_color_theorem FinalSolutionList append from storage 4_color_theorem FinalSolution.64





3.4.2 颜色填充

   有了FinalSolutionList,就可以轻松通过递归调用的方式对图形进行填充了。
   首先读取第一个元素,判断其代指的颜色,随后对第一层进行填充。然后删去第一个元素,并将命令基准点向上调整一格。这样反复读取,直到FinalSolutionList中不再存在任何元素。这样每一层就都能够填充完毕了。
   由于每一层有且仅有一个区域,因此可以直接使用fill命令进行填充。这也是分层标号的优势之一。
   填充好的效果如下:

相关函数:
4_color_theorem:final_fill/fill 用于递归填充颜色
data modify storage 4_color_theorem Temp2 set from storage 4_color_theorem FinalSolutionList[0]
execute if data storage 4_color_theorem {Temp2:1b} run fill ~1 ~ ~1 ~64 ~ ~64 blue_concrete replace white_concrete
execute if data storage 4_color_theorem {Temp2:2b} run fill ~1 ~ ~1 ~64 ~ ~64 green_concrete replace white_concrete
execute if data storage 4_color_theorem {Temp2:3b} run fill ~1 ~ ~1 ~64 ~ ~64 yellow_concrete replace white_concrete
execute if data storage 4_color_theorem {Temp2:4b} run fill ~1 ~ ~1 ~64 ~ ~64 red_concrete replace white_concrete
data remove storage 4_color_theorem FinalSolutionList[0]

execute if data storage 4_color_theorem FinalSolutionList
[0] positioned ~ ~1 ~ run function 4_color_theorem:final_fill/fill




3.4.3 图形复位

   图形已经填充好了,下一步就是要把它移动回去了。
   这里我还是调用了一个递归函数,逐层把区域复制回去。首先调整基准点为第一层,然后将区域移动回原处。然后将基准点向上移动一格,再将第二层移回原处,以此类推,直到将所有图形移动回原处。这样,我们就得到了一个完美的使用四色填充的图形!

相关函数:
4_color_theorem:final_fill/move 用于逐层将图形移回原处的递归函数
clone ~ ~ ~ ~65 ~ ~65 ~ 5 ~ masked move
scoreboard players add reigon_id 4_color_theorem 1
execute if score reigon_id 4_color_theorem <= reigon_count 4_color_theorem positioned ~ ~1 ~ run function 4_color_theorem:final_fill/move





4 结果分析与改进可能

   总体来说这个结果还是比较令人满意的,性能也比我预想中的要好很多。不过某些地方由于个人没时间比较懒就没做优化。比如,穷举如果能用二分的话,应该能省下相当量的命令数。同时最后一部分,我后来想了想,转格式是没有必要的。其实可以直接通过穷举套穷举的方法解决,不需要进行递归。同时,填色和复位也可以放到一步完成。不过最后一部分所占用的命令数微乎其微,对整体性能影响不会太大。
   以及,不知道有没有可能会有免穷举的方法(个人感觉应该没有,估计就算有也会相当复杂吧)。
   以上就是我对我写的这个算法的一些想法。好,我水完了,我先溜了

残梦溪边
检测完毕又是一个我看不懂的帖子唉

△@←
为什么不用实体marker呢
实体遍历多方便

Chelover_C60
△@← 发表于 2021-4-6 10:12
为什么不用实体marker呢
实体遍历多方便

如果是指用实体遍历填充的话
填充的目的不仅仅是区域识别,还要知道一个区域和哪些区域相邻。而且填色的时候要考虑到是否可能存在某种情况下某个区域四种颜色都无法使用的情况。
实际上我在前言里展示的第四章图中,如果按照正常逻辑(从左下开始,先往右填,再往上填),右下角的填色应该是蓝色,但实际上它是黄色,因为如果填蓝色的话,后面会出现所有颜色都不可用的情况,所以返回来改成了黄色(这一块我debug了好久)
如果仅仅是遍历填充的话,较难解决这种四色都不可用的情况,而且这样反复填不同颜色的话,命令的执行量可能会明显增多

斗_
神乎其神!6的飞起

2727069744
第一眼看成了七巧板

Masonic9
这个功能不知道能不能用来给画上色

Chelover_C60
Masonic9 发表于 2021-6-22 22:34
这个功能不知道能不能用来给画上色

做画可能需要的仅仅是填充功能吧,用这个东西给画上色我并不认为很可行
当然如果你想要一个四色定理填充的画的话当我没说()

如晴天似雨天
1.16.5版本可以吗?

夏言大人
这个或许可以做一些类似于贪吃蛇大作战或者占地盘的小游戏

清风诺帝
搞建筑真方便

fvjugnvgjgb456
感觉继续开发的潜力很大啊

遗忘的死神
这是要做画图工具?

1743983538
C语言学生表示毫无压力

何止
我靠这玩意不是证了几百年的吗。。。。

yingtao123
我把我的手机传送到mc了 hhh

我是cjky
这个要是能在服务器里实现,那你画我猜就简单了

哟西iiiiiiiiii
区域数量只能是64吗

深渊中的探寻者
Masonic9 发表于 2021-6-22 22:34
这个功能不知道能不能用来给画上色

自动填充颜色感觉不会很好,倒是可以用类似于教堂花窗的玻璃简单上色

1248391116
这让我想起了七桥问题
能不能找出一个算法完成联通若干给定点的图呢?
(这个算法是有的,但不知道能不能在MC中实现)

Chelover_C60
1248391116 发表于 2021-8-9 01:07
这让我想起了七桥问题
能不能找出一个算法完成联通若干给定点的图呢?
(这个算法是有的,但不知道能不能在 ...

那要看你的实现形式了
如果采用平面画的形式实现,基本是要看如何对各个点进行判定,对各个连线进行判定,判断出来哪些点通过哪条线与另外的点对应,最后想办法求解。
难点就是对点的编号,对连线的识别,以及求解算法的体现

222147
Moe-moo 发表于 2021-6-21 12:42
迟早有一天你们能在mc里面玩mc

快进到用mc模拟地球2333

xgnnnt
可以拿来做数学题...

mubaichen566
可以证明四色定理吗?【doge】

白云远上
颜色要是再多点我就可以在MC里画画了

xxcka123
这个感觉就很高级,每个颜色代表什么呢

千忆往昔思
这个变换的话可以缩小一点是不是就可以变成消失彩色方块那个小游戏了?
感觉应该可以实现,不知道服务器使用的命令方块还是插件
感谢大佬的分享!

Fen_Fei
小型像素画上色还是挺有用的 可以解放双手了

Spider.
功能不怎么实用 不过很新颖哎

我爱你宝贝~
我还以为是七巧板呢

mcacp
function 4_color_theorem:reigon/recog
scoreboard players add reigon_count 4_color_theorem 1
scoreboard players operation reigon_id 4_color_theorem = reigon_count 4_color_theorem
execute at @e[type=area_effect_cloud,tag=4_color_theorem positioned ~ ~1 ~ run function 4_color_theorem:reigon/move
应该是

GW-化十
这就是四色问题的答案吗哈哈

丨丶小爷
没有仔细验证过,第一个的想法是直接BFS或者DFS,不知道有没有其他优化的算法呢?

ku-bruce
woc这也太强了,快进到用mc表示图论

Man100521
这个玩意用来随机那种小游戏地图...

3345395370
牛啊牛啊牛啊

Nomanho
辛苦了辛苦了辛苦了..

Mr_Banxia
看会了,又好像没会0.0

QQQ66666
        MCBBS有你更精彩~

ddbwo
有低版本的吗,我和小伙伴的地图是1.12的

星晨月皓
mcbbs有你更精彩

Cx660
1.18.5版本可以吗?

天启kiss
这是要做画图工具????

Chelover_C60
丨丶小爷 发表于 2021-9-10 20:28
没有仔细验证过,第一个的想法是直接BFS或者DFS,不知道有没有其他优化的算法呢? ...

不知你说的是哪个部分
在区域填充识别时,dfs是最契合函数递归逻辑的算法,因此在填充时选择dfs算法

皮胖小子
那不是很方便?

zx7710079
可以在mc玩手机了!

浮生如此绵绵
看起来有点复杂啊 难定

0030
太牛了!辛苦大佬!!

荔枝Litch1
这个要是能在服务器里实现,那你画我猜就简单了

1207139923
MCBBS有你更精彩~

第一页 上一页 下一页 最后一页