<commit_before>package sokoban.Tethik;

import java.io.IOException;
import java.util.HashSet;
import java.util.List;

import sokoban.BoardPosition;

public class IDAPlayer {
	
	private Analyser analyser; 
	private PathFinder pathfinder;
	private BoardState initialState;
	public volatile boolean shouldStop = false;
	public static boolean VERBOSE = true;
	
	public IDAPlayer(BoardState initialState) {
		this.initialState = initialState;
		analyser = new Analyser(initialState);
		pathfinder = new PathFinder();
	}
	
	private Move winMove = null;
	
	/**
	 * Simple manhattan-distance heuristic on the blocks vs goals.
	 * @param move
	 * @return
	 */
	public int heuristicValue(Move move) {		
		BoardState board = move.board;
		int val = 0;
		for(BoardPosition goal : board.getGoalNodes())
		{		
			int min = Integer.MAX_VALUE;
			for(BoardPosition block : board.getBlockNodes())
			{
				min = Math.min(min, goal.DistanceTo(block));
			}			
			val += min;
		}		
		return val;
	}
	
	public int heuristicValue2(Move move) {
		return move.getHeuristicValue() * -1;
	}
	
//	private HashSet<Integer> deadlockStates = new HashSet<Integer>();
	private HashSet<Move> visitedStates = new HashSet<Move>();
	
	public int search(Move node, int bound) {
		if(shouldStop)
			return Integer.MIN_VALUE;
		
		winMove=null;
		visitedStates.add(node);
//		if(deadlockStates.contains(node)) {
//			System.out.println("Old Deadlock found..");
//			return Integer.MIN_VALUE;
//		}
		
//		if(node.getHeuristicValue() == Integer.MIN_VALUE) {
////			if(!deadlockStates.contains(node.hashCode()))
////				deadlockStates.add(node.hashCode());
//			return Integer.MIN_VALUE;
//		} 
//		
		if(node.board.isWin()){
			winMove=node;
			return Integer.MAX_VALUE;
		}
		
		int h = node.getHeuristicValue();
		int lb = h * -1;
		
		if(lb > bound)	
			return lb;		
		
		if(h == Integer.MAX_VALUE || h == Integer.MIN_VALUE)
			return h;
		
		if(VERBOSE) {
			System.out.println("lb: "+lb+" bound: "+bound);
			System.out.println(node.board);
		}
				
		List<Move> moves = node.getNextMoves();		
		for(Move child : moves) {		
			if(visitedStates.contains(child))
				continue;<commit_msg>visited states?<commit_after>package sokoban.Tethik;

import java.io.IOException;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;


import sokoban.BoardPosition;

public class IDAPlayer {
	
	private Analyser analyser; 
	private PathFinder pathfinder;
	private BoardState initialState;
	public volatile boolean shouldStop = false;
	public static volatile boolean VERBOSE = true;
	
	public IDAPlayer(BoardState initialState) {
		this.initialState = initialState;
		analyser = new Analyser(initialState);
		pathfinder = new PathFinder();
	}
	
	private Move winMove = null;
	
	/**
	 * Simple manhattan-distance heuristic on the blocks vs goals.
	 * @param move
	 * @return
	 */
	public int heuristicValue(Move move) {		
		BoardState board = move.board;
		int val = 0;
		for(BoardPosition goal : board.getGoalNodes())
		{		
			int min = Integer.MAX_VALUE;
			for(BoardPosition block : board.getBlockNodes())
			{
				min = Math.min(min, goal.DistanceTo(block));
			}			
			val += min;
		}		
		return val;
	}
	
	public int heuristicValue2(Move move) {
		return move.getHeuristicValue() * -1;
	}
	
//	private HashSet<Integer> deadlockStates = new HashSet<Integer>();
	private HashSet<Move> visitedStates = new HashSet<Move>();
	
	public int search(Move node, int bound) {
		if(shouldStop)
			return Integer.MIN_VALUE;
		
		winMove=null;
		visitedStates.add(node);
		
//		if(deadlockStates.contains(node)) {
//			System.out.println("Old Deadlock found..");
//			return Integer.MIN_VALUE;
//		}
		
//		if(node.getHeuristicValue() == Integer.MIN_VALUE) {
////			if(!deadlockStates.contains(node.hashCode()))
////				deadlockStates.add(node.hashCode());
//			return Integer.MIN_VALUE;
//		} 
//		
		if(node.board.isWin()){
			winMove=node;
			return Integer.MAX_VALUE;
		}
		
		int h = node.getHeuristicValue();
		int lb = h * -1;
		
		if(lb > bound)	
			return lb;		
		
		if(h == Integer.MAX_VALUE || h == Integer.MIN_VALUE)
			return h;
		
		if(VERBOSE) {
			System.out.println("lb: "+lb+" bound: "+bound);
			System.out.println(node.board);
		}
				
		List<Move> moves = node.getNextMoves();		
		Collections.sort(moves);		
		for(Move child : moves) {		
			if(visitedStates.contains(child))
				continue;
{'fraction_non_alphanumeric': 0.13083690503045342, 'fraction_numerical': 0.0018046469659372885, 'mean_word_length': 3.4384384384384385, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3932117', 'n_tokens_mistral': 1725, 'n_tokens_neox': 1487, 'n_words': 326}