⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hexpuzzle.java

📁 source codes to solve Hexpuzzle problem
💻 JAVA
字号:
import java.util.ArrayList;
import java.util.HashSet;
import java.util.PriorityQueue;

/**
 * 
 * @author Hui Bin Huang
 *
 */

public class Hexpuzzle {
	
	private PriorityQueue<Node> open;
	private HashSet<Node> close;
	
	Hexpuzzle(HexpuzzleItems puzzle)
	{
		if(puzzle != null)
		{
			Node initialState = new Node(puzzle);
			open = new PriorityQueue<Node>();
			open.add(initialState);
			close = new HashSet<Node>();
		}
	}

	public void playHexpuzzle()
	{	
		while(!open.isEmpty())
		{			
			Node currentState = (Node)open.poll();				
						
			//print the current sequence number
			System.out.println(currentState.toString());
			
			if(currentState.goalTest())
				return;
			
			if(close.contains(currentState))
				continue;
			
			close.add(currentState);
			
			ArrayList<Node> successorNodes = currentState.successor();
			for(int i = 0; i < successorNodes.size(); i++)
			{
				Node temp = successorNodes.get(i);
				open.add(temp);
			}
		}
	}
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		//String itemStr = args[0];
		//String itemStr = "A B C D E G H N I J K L M _ F O";
		String itemStr = "A B C D E H I J K L G M N _ F O";
		//String itemStr = " ";
		//int heuristic = Integer.parseInt(args[1]);
		int heuristic = 2;
		
		for(int i=0; i < args.length; i++)
		{
			if(i==0) itemStr = args[i];
			if(i==1) heuristic = Integer.parseInt(args[i]); 
		}
		
		HexpuzzleItems puzzleItems = new HexpuzzleItems(itemStr, heuristic);
		if(puzzleItems == null)
		{
			System.out.println("Failed to create the puzzle... ");
			System.exit(1);
		}
		
		Hexpuzzle puzzle = new Hexpuzzle(puzzleItems);
		if(puzzle != null)
			puzzle.playHexpuzzle();
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -