XMLWrite

Number Place Generator Version 2.0 -- Sample Programs

How to call Java API of Number Place Generator Version 2.0.

Write XML File

Let's try to write a XML problem file.

  • standard board : size is 9.
  • hint is given by an array.
  • calculate the difficulty point.

XMLWrite.java

package jp.gr.puzzle.npv2.sample;

import java.io.File;
import java.util.ArrayList;
import jp.gr.puzzle.npv2.core.*;

public class XMLWrite {
        final static int numSize = 9;
        static boolean isDiagonal = false;
        static int[] hint = {
                        0,0,0,0,0,0,0,0,0,
                        0,1,1,0,0,0,1,1,0,
                        1,0,0,1,0,1,0,0,1,
                        1,0,0,0,1,0,0,0,1,
                        1,0,0,0,0,0,0,0,1,
                        0,1,0,0,0,0,0,1,0,
                        0,0,1,0,0,0,1,0,0,
                        0,0,0,1,0,1,0,0,0,
                        0,0,0,0,1,0,0,0,0               };
        
        static int[] hidden = new int[numSize*numSize];
        static SolverMethod method = new SolverMethod();
        
        public static void main(String[] args) {
                System.out.println("XMLWrite");
                
                int[] problem = null;
                ArrayList<Integer[]> blockarraylist = Utility.makeNormalBlock(numSize, 3, 3 );
                BlockConstraint block = new BlockConstraint( blockarraylist, numSize);  
                Generator generator = new Generator(numSize , hint , hidden, block);
                generator.setMethod(method);

                while( (problem = generator.generate()) == null )
                        ;
                Status state = new Status(numSize,block);
                Solver.addNumbers( state, problem);
                Status result = Solver.answer(state , method);
                int[] answer = result.getCell();
                int[] blockarray = Utility.integer2int(block.getBlockArray());
                int point = (int)Evaluator.evaluate(numSize,block,problem);     
                
                System.out.println( "point "+point );           
                Utility.printGrid( problem, numSize );
                File file = new File( "xmlwrite.xml");
                
                NumberPlaceFile npFile = new NumberPlaceFile();
                npFile.setNumSize(numSize);
                npFile.setHint(Utility.int2boolean(hint));
                npFile.setHidden(hidden);
                npFile.setAnswer(answer);
                npFile.setDifficult(point);
                npFile.setIsDiagonal(isDiagonal);
                npFile.setBlockArray(blockarray);
                npFile.setProblem(problem);
                npFile.Save(file);              
        }
}

Verification

You can check the XML file by loading the file to Number Place Generator V2 (vesion beta6 or later).

output file "xmlwrite.xml"

New lines are added for readability.

<?xml version="1.0" encoding="UTF-8" ?>
<problem size="9" name="Number Place" author="Number Place Generator">
<question difficult="5070">
0 0 0 0 0 0 0 0 0 
0 1 8 0 0 0 6 7 0 
4 0 0 5 0 3 0 0 2 
5 0 0 0 1 0 0 0 7 
1 0 0 0 0 0 0 0 3 
0 3 0 0 0 0 0 4 0 
0 0 5 0 0 0 8 0 0 
0 0 0 7 0 1 0 0 0 
0 0 0 0 6 0 0 0 0
</question>
<constraint diagonal="off">
<group block="on">
1 1 1 4 4 4 7 7 7 
1 1 1 4 4 4 7 7 7 
1 1 1 4 4 4 7 7 7 
2 2 2 5 5 5 8 8 8 
2 2 2 5 5 5 8 8 8 
2 2 2 5 5 5 8 8 8 
3 3 3 6 6 6 9 9 9 
3 3 3 6 6 6 9 9 9 
3 3 3 6 6 6 9 9 9
</group>
</constraint>
<answer>
9 5 2 1 7 6 3 8 4 
3 1 8 4 9 2 6 7 5 
4 7 6 5 8 3 9 1 2 
5 8 4 3 1 9 2 6 7 
1 2 7 6 4 8 5 9 3 
6 3 9 2 5 7 1 4 8 
7 6 5 9 3 4 8 2 1 
8 9 3 7 2 1 4 5 6 
2 4 1 8 6 5 7 3 9
</answer>
<hint>
0 0 0 0 0 0 0 0 0 
0 1 1 0 0 0 1 1 0 
1 0 0 1 0 1 0 0 1 
1 0 0 0 1 0 0 0 1 
1 0 0 0 0 0 0 0 1 
0 1 0 0 0 0 0 1 0 
0 0 1 0 0 0 1 0 0 
0 0 0 1 0 1 0 0 0 
0 0 0 0 1 0 0 0 0
</hint>
<hidden>
0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0
</hidden>
</problem>

}}}

PUZZLE GeneRator JaPan
Copyright(C) 2007 Time Intermedia Corporation. All Rights Reserved.