之前的关于华容道自动求解的代码,变量名的命名很不规范,结构也不太容易理解,过一段时间后,重新来看,又会不知道以前的代码的意思了,明明之前已经看懂,结果现在又不懂了,很浪费时间。所以,应该自己再来针对代码的可读写进行重构。 package game.hrd.game.hrd.refactor; import java.util.ArrayList; /** * Created by huangcongjie on 2017/12/20. */ public class Solver { HrdNode[] queue; int searchAmount = 0; int processingIndex = 0; int maxAmount = Integer.MAX_VALUE; private void addToQueue(HrdNode node) { if (searchAmount >= maxAmount) { System.out.println("对溢出"); return; } queue[searchAmount] = node; searchAmount++; } //--广度优先-- public int bfs(int[] layout, boolean useHash) { // System.out.println("use hash checker: " + useHash); long t1 = System.currentTimeMillis(); long cost = 0; IAnalyzer analyzer = useHash ? new HashLayoutAnalyzer() : new LayoutAnalyzer(); HrdNode root = new HrdNode(layout, analyzer, useHash); IChecker checker = useHash ? new LayoutToHash() : new LayoutToCode(root.layout); if (useHash) { maxAmount = 40 * 1024; } else { maxAmount = ((LayoutToCode) checker).codeTotalNum / 10; } queue = new