Skip to content

Commit

Permalink
Merge pull request #2 from comuns-rpgmaker/development
Browse files Browse the repository at this point in the history
MVP
  • Loading branch information
masked-rpgmaker authored Oct 3, 2020
2 parents 583360c + 09daeb5 commit 19aeca8
Show file tree
Hide file tree
Showing 42 changed files with 1,118 additions and 297 deletions.
1 change: 1 addition & 0 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ jobs:
--excludeNotExported \
--excludePrivate \
--excludeExternals \
--exclude "**/*+.spec.ts" \
--externalPattern "node_modules/**" \
--readme README.md \
--out docs \
Expand Down
23 changes: 0 additions & 23 deletions .github/workflows/tests.yml

This file was deleted.

10 changes: 10 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"devDependencies": {
"@comuns-rpgmaker/plugin-metadata": "^0.2.3",
"@istanbuljs/nyc-config-typescript": "^1.0.1",
"@rollup/plugin-replace": "^2.3.3",
"@rollup/plugin-typescript": "^5.0.2",
"@types/jasmine": "^3.5.13",
"@types/node": "^14.6.0",
Expand Down
207 changes: 205 additions & 2 deletions plugin-metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ languages:
- pt

description:
default: Shortest path algorithm implementation.
pt: Implementação de algoritmo de menor caminho.
default: Shortest path algorithm implementations.
pt: Implementação de algoritmos de menor caminho.

help:
default: |-
Expand All @@ -28,3 +28,206 @@ help:
Também é possível extender o plugin definindo estratégias
personalizadas de cálculo e seguimento de caminho.
commands:
#==========================================================================
# Event -> Player
#==========================================================================
- name: event_follow_player
text:
default: Event follow player
pt: Evento seguir jogador
description:
default: Makes an event follow the player using pathfinding.
pt: Faz com que um evento siga o jogador usando pathfinding.
args:
- name: event_id
type: number
min: 0
text:
default: Event Id
pt: Id do Evento
description:
default: Event Id
pt: Id do evento

- name: strategy
type: text
text:
default: Strategy
pt: Estrategia
description:
default: |-
Pathfinding strategy class to use. The default is usually
best.
pt: |-
Classe de strategia de pathfinding a ser usada. O padrão
costuma ser a melhor opção.
default: Schach.Pathfinding.Strategy.StandardStrategy

#==========================================================================
# Event -> Point
#==========================================================================
- name: event_to_point
text:
default: Event to point
pt: Evento para ponto
description:
default: Makes an event go to a point on the map using pathfinding.
pt: Faz com que um evento vá até um ponto no mapa usando pathfinding.
args:
- name: event_id
min: 0
text:
default: Event Id
pt: Id do Evento
description:
default: Event Id
pt: Id do evento
type: number

- name: point_x
type: number
min: 0
text:
default: Point X
pt: Ponto X
description:
default: X coordinate of the target point.
pt: Coordenada X do ponto de destino.

- name: point_y
type: number
min: 0
text:
default: Point Y
pt: Ponto Y
description:
default: Y coordinate of the target point.
pt: Coordenada Y do ponto de destino.

- name: strategy
type: text
text:
default: Strategy
pt: Estrategia
description:
default: |-
Pathfinding strategy class to use. The default is usually
best.
pt: |-
Classe de strategia de pathfinding a ser usada. O padrão
costuma ser a melhor opção.
default: Schach.Pathfinding.Strategy.StandardStrategy

#==========================================================================
# Event clear
#==========================================================================
- name: event_clear
text:
default: Clear Event path
pt: Limpar caminho de Evento
description:
default: Cancels path following for an event.
pt: Cancela o seguimento de caminho para um evento.
args:
- name: event_id
min: 0
text:
default: Event Id
pt: Id do Evento
description:
default: Event Id
pt: Id do evento
type: number

#==========================================================================
# Player -> Event
#==========================================================================
- name: player_follow_event
text:
default: Player follow event
pt: Jogador seguir evento
description:
default: Makes the player follow an event using pathfinding.
pt: Faz com que o jogador siga um evento usando pathfinding.
args:
- name: event_id
type: number
min: 0
text:
default: Event Id
pt: Id do Evento
description:
default: Event Id
pt: Id do evento

- name: strategy
type: text
text:
default: Strategy
pt: Estrategia
description:
default: |-
Pathfinding strategy class to use. The default is usually
best.
pt: |-
Classe de strategia de pathfinding a ser usada. O padrão
costuma ser a melhor opção.
default: Schach.Pathfinding.Strategy.StandardStrategy

#==========================================================================
# Player -> Point
#==========================================================================
- name: player_to_point
text:
default: Player to point
pt: Jogador para ponto
description:
default: Makes the player go to a point on the map using pathfinding.
pt: Faz com que o jogador vá até um ponto no mapa usando pathfinding.
args:
- name: point_x
type: number
min: 0
text:
default: Point X
pt: Ponto X
description:
default: X coordinate of the target point.
pt: Coordenada X do ponto de destino.

- name: point_y
type: number
min: 0
text:
default: Point Y
pt: Ponto Y
description:
default: Y coordinate of the target point.
pt: Coordenada Y do ponto de destino.

- name: strategy
type: text
text:
default: Strategy
pt: Estrategia
description:
default: |-
Pathfinding strategy class to use. The default is usually
best.
pt: |-
Classe de strategia de pathfinding a ser usada. O padrão
costuma ser a melhor opção.
default: Schach.Pathfinding.Strategy.StandardStrategy

#==========================================================================
# Player clear
#==========================================================================
- name: player_clear
text:
default: Clear Player path
pt: Limpar caminho do Jogador
description:
default: Cancels path following for the player.
pt: Cancela o seguimento de caminho para o jogador.
15 changes: 13 additions & 2 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import typescript from '@rollup/plugin-typescript';
import replace from '@rollup/plugin-replace';

import { terser } from 'rollup-plugin-terser';
import externalGlobals from "rollup-plugin-external-globals";
Expand All @@ -25,6 +26,9 @@ export default [
sourcemap: false,
outro: wasm,
plugins: [
replace({
__pluginId__: pkg.name
}),
terser({
format: {
comments: false,
Expand All @@ -40,14 +44,21 @@ export default [
name: pkg.namespace,
format: 'iife',
sourcemap: true,
outro: wasm
banner: header,
outro: wasm,
plugins: [
replace({
__pluginId__: `${pkg.name}.debug`
})
]
}
],
plugins: [
typescript(),
externalGlobals({
"rmmz": "window"
})
]
],
onwarn: () => {}
}
];
28 changes: 22 additions & 6 deletions src/algorithm/a-star.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ export function aStar<T>(
source: T,
target: T,
g: Graph<T> & Weighted<T>,
heuristic: (s: T, t: T) => number
): Deque<T> | undefined
heuristic: (s: T, t: T) => number,
maxlen: number
): Deque<T>
{
const sourceId = g.id(source)!;
const targetId = g.id(target)!;
Expand All @@ -38,7 +39,11 @@ export function aStar<T>(
gscore.set(sourceId, 0);

const fscore = new Map<number, number>();
fscore.set(sourceId, heuristic(source, target));
const f = heuristic(source, target);
fscore.set(sourceId, f);

let best = source;
let bestH = f;

const q = new PriorityQueue<{ id: number, node: T }>(
({ id: idA }, { id: idB }) => fscore.get(idA)! < fscore.get(idB)!);
Expand All @@ -65,11 +70,22 @@ export function aStar<T>(
const score = nodeScore + g.weight(node, neighbor)!;

const neighborId = g.id(neighbor)!;
if (score < (gscore.get(neighborId) ?? Infinity))
if (score < maxlen &&
score < (gscore.get(neighborId) ?? Infinity)
)
{
cameFrom.set(neighborId, node);
gscore.set(neighborId, score);
fscore.set(neighborId, score + heuristic(neighbor, target));

const h = heuristic(neighbor, target);
const f = score + h;
fscore.set(neighborId, f);

if (h < bestH)
{
best = neighbor;
bestH = h;
}

if (!open.has(neighborId)) {
q.add({ id: neighborId, node: neighbor });
Expand All @@ -80,7 +96,7 @@ export function aStar<T>(
}
}

return undefined;
return makePath(g, best, cameFrom);
}

function makePath<T>(g: Graph<T>, target: T, cameFrom: Map<number, T>): Deque<T>
Expand Down
3 changes: 3 additions & 0 deletions src/algorithm/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './a-star';
export * from './flood-fill';
export * from './rea-star';
Loading

0 comments on commit 19aeca8

Please sign in to comment.