path finding – Java Game: A* Algorithm (searching only cells in front of character)

Game Type: grid tile map that is turned based

Directions allowed: Left, Forward, Right
(to reverse directions you must either use two lefts or two rights) – both left and right moves diagonal but change the face of the ship depending on original face)

Slots: Depending on ship size there are a certain number of slots for that particular ship for user to enter to allow the ship to move that many spots per turn (ie. 3 slots == 3 moves per turn)

Example:

Start Position: 2,2

Start face: North

Move Placed: Left

End Result: Position: 1,3 ; Face: West


Problem: algorithm uses all 8 tiles for path finding; but should only look for the tiles that are in front (depends on ship face)

Pathfinding calculation:

    private Comparator<Node> nodeSorter = new Comparator<Node>() {

        @Override
        public int compare(Node n0, Node n1) {
            if(n1.fCost < n0.fCost) return 1;
            if(n1.fCost > n0.fCost) return -1;
            return 0;
        }
        
    };

    public List<Node> findPath(Position start, Position goal){
        List<Node> openList = new ArrayList<Node>();
        List<Node> closedList = new ArrayList<Node>();
        Node current = new Node(start, null, 0, start.distance(goal));
        openList.add(current);
        while(openList.size() > 0) {
            Collections.sort(openList, nodeSorter);
            current = openList.get(0);
            if(current.position.equals(goal)) {
                List<Node> path = new ArrayList<Node>();
                while(current.parent != null) {
                    path.add(current);
                    current = current.parent;
                }
                openList.clear();
                closedList.clear();
                return path;
            }
            openList.remove(current);
            closedList.add(current);
            for(int i = 0; i < 9; i++) {
                if (i == 4)continue;
                int x = current.position.getX();
                int y = current.position.getY();
                int xi = (i % 3) - 1;
                int yi = (i / 3) - 1;
                int at = context.getMap().getTile(x + xi, y + yi);
                if(at == 1 || at == 2) continue; // ignore rocks
                Position a = new Position(x + xi, y + yi);
                double gCost = current.gCost + current.position.distance(a);
                double hCost = a.distance(goal);
                Node node = new Node(a, current, gCost, hCost);
                if(positionInList(closedList, a) && gCost >= node.gCost) continue;
                if(!positionInList(openList, a) || gCost < node.gCost) openList.add(node);
            }
        }
        closedList.clear();
        return null;
    }
    
    private boolean positionInList(List<Node> list, Position position) {
        for(Node n : list) {
            if(n.position.equals(position)) return true;
        }
        return false;
    }

Implementation:

@Override
    public void calculateRoute() {
        Position destination = new Position(3,3); // replace with cluster
        if(this.equals(destination)) {
            return;
        }based 
        path = context.getPlayerManager().findPath(this, destination);
        VesselFace face = getFace();
        if(path != null) {
            if(path.size() > 0) {
                int numberOfMoves = getVessel().has3Moves() ? 3 : 4;
                Position currentPosition = this.copy();
                for(int slot = 0; slot <= numberOfMoves; slot++) { //moves to enter
                    int positionIndex = (path.size() - 1) - (slot); //subtract slot to allow multiple moves
                    if(positionIndex < 0 || path.size() < slot) { // make sure it doesn't count too far
                        return;
                    }
                    Position pos = path.get(positionIndex).position;
                    Position left = MoveType.LEFT.getFinalPosition(currentPosition, face);
                    Position right = MoveType.RIGHT.getFinalPosition(currentPosition, face);
                    Position forward = MoveType.FORWARD.getFinalPosition(currentPosition, face);
                    if(left.equals(pos)) {
                        currentPosition.add(left.getX() - getX(), left.getY() - getY());
                        getMoves().setMove(slot, MoveType.LEFT);
                        switch(face) {
                            case NORTH:
                                face = VesselFace.WEST;
                                break;
                            case SOUTH:
                                face = VesselFace.EAST;
                                break;
                            case WEST:
                                face = VesselFace.SOUTH;
                                break;
                            case EAST:
                                face = VesselFace.NORTH;
                                break;
                        }
                    }else if(right.equals(pos)) {
                        currentPosition.add(right.getX() - getX(), right.getY() - getY());
                        getMoves().setMove(slot, MoveType.RIGHT);
                        switch(face) {
                            case NORTH:
                                face = VesselFace.EAST;
                                break;
                            case SOUTH:
                                face = VesselFace.WEST;
                                break;
                            case WEST:
                                face = VesselFace.NORTH;
                                break;
                            case EAST:
                                face = VesselFace.SOUTH;
                                break;
                        }
                    }else if(forward.equals(pos)){
                        currentPosition.add(forward.getX() - getX(), forward.getY() - getY());
                        getMoves().setMove(slot, MoveType.FORWARD);
                        switch(face) {
                            case NORTH:
                                face = VesselFace.NORTH;
                                break;
                            case SOUTH:
                                face = VesselFace.SOUTH;
                                break;
                            case WEST:
                                face = VesselFace.WEST;
                                break;
                            case EAST:
                                face = VesselFace.EAST;
                                break;
                        }
                    }
                }
            }
        }
    }

I use the switch statement and currentPosition.add() method so that when you place 3 moves for that particular turn; it knows where it should end up. Probably not best practice.

Statement that adds a move to the particular slot

getMoves().setMove(slot, MoveType.FORWARD);

Tiles that should be checked every turn based on ship face:

enter image description here

formulas – Google Sheets: How to add data in a specific row after searching a column for a specific keyword?

So I’m trying to figure out how to have sheets look in the username column for a specific username and then find the sum of the numbers in the “kills” column that are in the same row as that specific username.
For Example: I want it to Look for the username “Sinz_y” and for every row that has the name Sinz_y, I was it to find the sum of the “kills” in those rows.

google – Searching in real time

I want to search something on a website that has been recently updated but when I use google to search for the keyword in the website google returns results from the old version of the website to me.

I know that Google indexing is not realtime but Is there any way to make google, search for a keyword in a website at the time you initiated the search query. i.e if i search something now then i want the search engine to search for that keyword in particular website now.

There is a feature in google where you can filter the search result by time i.e (past hour, last 24 hour, etc). Can I leverage it to achieve what i want?

Also can you please point me towards some search engines that allow this kind of searching.

Thankyou!

algorithms – What is the state of the art of full text searching across languages?

I have looked at a few papers on this such as this, and it basically says that full text search is all about English with few resources for languages without spaces between words (like Chinese or Tibetan), and little for languages with complex morphologies like Arabic.

However, when I do a search on Google for different languages, they show matching results. How are they doing this?

enter image description here


enter image description here


enter image description here


Above I am searching for very popular keywords (key texts in those languages), but still, they are finding relevant results. Searching for word fragments, I find matches (in bold) too:

enter image description here


enter image description here


What is Google potentially doing (at a high, theoretical level) to accomplish this? Are they just doing character grams and statistical analysis? Or is something more fancy going on? Wondering what the general state of the art is.

Other sites like bible.com seem to have full-text search across 900+ languages. For example, ᐊᒡᓔᑦ ᐃᑦᔪᕐᖕᓁᑦᑐᑦ. What are they doing?

enter image description here

postgresql – postgres – searching for a close numeric match

I have a large postgres table contain geographic positions (latitude and longitude) both fields are indexed, and both are defined as NUMERIC(9,6).

If I run a query looking for an exact position match, something like this…..

WHERE latitude  = 1.234567890123456789
AND   longitude = 9.876543210987654321

Then get a very fast response, but I get very few results because the database is searching for a very precise match.

For my purposes, I’m looking for positions that match to within a few meters so a match to 4 or 5 decimal places should be fine. This gives me the results I’m looking for…….

WHERE ABS(latitude  - 1.234567890123456789) < 0.0001
AND   ABS(longitude - 9.876543210987654321) < 0.0001

But NOT the performance (it can take 5 minutes to run, compared to a fraction of a second for the exact search)

Next I tried rounding the precision down…….

WHERE ROUND( latitude, 4) = ROUND( 1.234567890123456789, 4)
AND   ROUND( longitude,4) = ROUND( 9.876543210987654321, 4)

Again, same problem. Got the results I wanted, but took far too long.

So, my question is how can I search for a close match between two numbers, without losing performance?

UPDATE – SOLVED
As a couple of commenters have observed, using BETWEEN seems to work fine. Thank you