
com.almasb.fxgl.pathfinding.astar.TraversableGrid Maven / Gradle / Ivy
The newest version!
/*
* FXGL - JavaFX Game Library. The MIT License (MIT).
* Copyright (c) AlmasB ([email protected]).
* See LICENSE for details.
*/
package com.almasb.fxgl.pathfinding.astar;
import com.almasb.fxgl.core.collection.grid.CellGenerator;
import com.almasb.fxgl.core.collection.grid.Grid;
import java.util.List;
import java.util.stream.Collectors;
/**
* The supertype for any grid that can be traversed using A* pathfinding.
*
* @author Almas Baim (https://github.com/AlmasB)
*/
public abstract class TraversableGrid extends Grid {
public TraversableGrid(Class type, int width, int height) {
super(type, width, height);
}
public TraversableGrid(Class type, int width, int height, CellGenerator populateFunction) {
super(type, width, height, populateFunction);
}
public TraversableGrid(Class type, int width, int height, int cellWidth, int cellHeight, CellGenerator populateFunction) {
super(type, width, height, cellWidth, cellHeight, populateFunction);
}
/**
* @return all cells whose state is CellState.WALKABLE
*/
public List getWalkableCells() {
return getCells()
.stream()
.filter(c -> c.getState().isWalkable())
.collect(Collectors.toList());
}
/**
* @return given neighbors [source] and [target], true if we can move from [source] to [target] in a single action,
* i.e. there exists a path of size 1
*/
public boolean isTraversableInSingleMove(T source, T target) {
return target.isWalkable();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy