使用给定的Nonogram puzzle(Java)约束生成所有可能的组合

时间:2017-04-07 15:18:58

标签: java algorithm artificial-intelligence combinations constraint-programming

我的问题是,当我有一个约束时,我必须为行/列生成所有可能的组合。让我们说有一个非图形拼图,它的行大小为40.我有约束

B,11,G,5,B,9

我必须遵守约束条件:

  • 在两个填充相同颜色的方块之间始终至少有一个空框
  • 在填充不同颜色的框之间不必有空框
  • 图例中数字的顺序对应于方框的顺序(从左到右,从上到下)

其中字母代表颜色(即B =蓝色),以下是该块的长度。我有一个规则的课程。这些规则存储在ArrayList规则中。

public class Rule {

public int size;
public char color;

public Rule(int length, char color){
    this.size = length;
    this.color= color;
}

现在我想生成行/列的所有有效组合,以便我可以将它们添加到ArrayList rowCombinations

for (int i =0 ; i < rowSize ; i++){             
    rowCombinations.add(makeCombinations(some_input));
}

因此makeCombinations函数将返回我的自定义变量类CSPVariable

public class CSPVariable {

public ArrayList<char[]> storage;
public int position;
public boolean Row;

public CSPVariable(int index, boolean Row) {
    this.position = index;
    this.Row = Row;
    this.storage = new ArrayList<>();
}

所以要回顾一下......根据规则,我想生成所有可能的字母组合,并将它存储到char数组存储int CSPVariable类。

0 个答案:

没有答案