<commit_before>package fr.ritaly.dungeonmaster.ai.astar;

import java.util.LinkedList;
import java.util.List;

import fr.ritaly.dungeonmaster.map.Dungeon;
import fr.ritaly.dungeonmaster.map.Level;

public class LevelPathFinder extends AStar<LevelPathFinder.Node> {
	private final Level level;

	private final int targetX, targetY;

	public static class Node {
		public int x;
		public int y;

		public Node(int x, int y) {
			this.x = x;
			this.y = y;
		}

		public String toString() {
			return "(" + x + ", " + y + ") ";
		}
	}

	public LevelPathFinder(Level level, int x, int y) {
		this.level = level;
		this.targetX = x;
		this.targetY = y;
	}

	protected boolean isGoal(Node node) {
		return (node.x == targetX) && (node.y == targetY);
	}

	protected Double g(Node from, Node to) {
		if (from.x == to.x && from.y == to.y) {
			// But atteint
			return 0.0;
		}

		// FIXME Amliorer la prise en compte du ct traversable des lments
		if (!level.getElement(to.x, to.y).isConcrete()) {
			// Element franchissable
			return 1.0;
		}

		// Element non franchissable
		return Double.MAX_VALUE;
	}

	protected Double h(Node from, Node to) {
		/* Use the Manhattan distance heuristic. */
		return new Double(Math.abs(targetX - to.x) + Math.abs(targetY - to.y));
	}

	protected List<Node> generateSuccessors(Node node) {
		List<Node> ret = new LinkedList<Node>();
		int x = node.x;
		int y = node.y;

		// FIXME Amliorer la prise en compte du ct traversable des lments
		if (y < targetY && !level.getElement(x, y + 1).isConcrete()) {
			ret.add(new Node(x, y + 1));
		}

		// FIXME Amliorer la prise en compte du ct traversable des lments
		if (x < targetX && !level.getElement(x + 1, y).isConcrete()) {
			ret.add(new Node(x + 1, y));
		}

		return ret;
	}
<commit_msg>Fixed LevelPathFinder to consider the 4 possible move directions<commit_after>package fr.ritaly.dungeonmaster.ai.astar;

import java.util.LinkedList;
import java.util.List;

import fr.ritaly.dungeonmaster.map.Dungeon;
import fr.ritaly.dungeonmaster.map.Element;
import fr.ritaly.dungeonmaster.map.Level;

public class LevelPathFinder extends AStar<LevelPathFinder.Node> {
	private final Level level;

	private final int targetX, targetY;

	public static class Node {
		public int x;
		public int y;

		public Node(int x, int y) {
			this.x = x;
			this.y = y;
		}

		public String toString() {
			return "(" + x + ", " + y + ") ";
		}
	}

	public LevelPathFinder(Level level, int x, int y) {
		this.level = level;
		this.targetX = x;
		this.targetY = y;
	}

	protected boolean isGoal(Node node) {
		return (node.x == targetX) && (node.y == targetY);
	}

	protected Double g(Node from, Node to) {
		if (from.x == to.x && from.y == to.y) {
			// But atteint
			return 0.0;
		}

		// FIXME Amliorer la prise en compte du ct traversable des lments
		if (!level.getElement(to.x, to.y).isConcrete()) {
			// Element franchissable
			return 1.0;
		}

		// Element non franchissable
		return Double.MAX_VALUE;
	}

	protected Double h(Node from, Node to) {
		/* Use the Manhattan distance heuristic. */
		return new Double(Math.abs(targetX - to.x) + Math.abs(targetY - to.y));
	}

	protected List<Node> generateSuccessors(Node node) {
		// On recherche dans les 4 directions possibles de dplacement
		List<Node> ret = new LinkedList<Node>();
		int x = node.x;
		int y = node.y;

		// FIXME Amliorer la prise en compte du ct traversable des lments
		{
			final Element element = level.getElement(x, y + 1, false);
			
			if (!element.isConcrete()) {
				ret.add(new Node(x, y + 1));
			}
		}
		{
			final Element element = level.getElement(x, y - 1, false);
			
			if (!element.isConcrete()) {
				ret.add(new Node(x, y - 1));
			}
		}

		// FIXME Amliorer la prise en compte du ct traversable des lments
		{
			final Element element = level.getElement(x + 1, y, false);
			
			if (!element.isConcrete()) {
				ret.add(new Node(x + 1, y));
			}
		}
		{
			final Element element = level.getElement(x - 1, y, false);
			
			if (!element.isConcrete()) {
				ret.add(new Node(x - 1, y));
			}
		}

		return ret;
	}

{'fraction_non_alphanumeric': 0.13344802162693536, 'fraction_numerical': 0.005406733841238634, 'mean_word_length': 2.9941118743866535, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 11, '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': '6000609', 'n_tokens_mistral': 1641, 'n_tokens_neox': 1462, 'n_words': 419}