Skip to content

Commit

Permalink
v1.0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
pagoru committed Dec 23, 2020
1 parent 61d2fba commit b81a1e0
Show file tree
Hide file tree
Showing 16 changed files with 6,417 additions and 932 deletions.
66 changes: 60 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,61 @@
# node with typescript
# pathfinding.ts

## How to:
1. **Download the zip** or execute `git clone https://github.com/darkaqua/node-with-typescript` in the terminal
2. Run `npm install` in the **/node-with-typescript** directory
3. Run `npm start` and test if the hello world works.
4. Remove this shit and start your project with ts! :3
Finders:
- [x] Jump Point - No Diagonal Movement

### Grid example
Jump point: 10
```ts
const grid = new Grid([
[50, 55, 60, 65, 70],
[45, 0, 0, 0, 75],
[40, 0, 0, 0, 1 ],//x4y2
[35, 0, 0, 0, 5 ],
[30, 25, 20, 15, 10],
]);
```
#### PF example 1
```ts
grid.findPath(
{ x: 4, y: 2 },
{ x: 4, y: 1 },
10,
FinderEnum.JUMP_POINT
);
```
```js
[
{ x: 4, y: 2 },
{ x: 4, y: 4 },
{ x: 0, y: 4 },
{ x: 0, y: 0 },
{ x: 4, y: 0 },
{ x: 4, y: 1 }
]

```
#### PF example 2
```ts
grid.findPath(
{ x: 4, y: 2 },
{ x: 4, y: 1 },
1
);
```
```js
[ ]
```
#### PF example 3
```ts
grid.findPath(
{ x: 4, y: 2 },
{ x: 4, y: 1 },
85
);
```
```js
[
{ x: 4, y: 2 },
{ x: 4, y: 1 }
]
```
64 changes: 64 additions & 0 deletions __tests__/pathFinding.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import {Grid} from "../src";

describe('test path finding', () => {

const grid = new Grid([
[50, 55, 60, 65, 70],
[45, 0, 0, 0, 75],
[40, 0, 0, 0, 1 ],
[35, 0, 0, 0, 5 ],
[30, 25, 20, 15, 10],
]);

it('validates pf {test 1}', () => {
const path = grid.findPath(
{ x: 4, y: 2 },
{ x: 4, y: 1 }
)
expect(path).toEqual([
{x: 4, y: 2},
{x: 4, y: 4},
{x: 0, y: 4},
{x: 0, y: 0},
{x: 4, y: 0},
{x: 4, y: 1}
]);
});

it('validates pf {test 2}', () => {
const path = grid.findPath(
{ x: 4, y: 2 },
{ x: 4, y: 1 },
10
)
expect(path).toEqual([
{x: 4, y: 2},
{x: 4, y: 4},
{x: 0, y: 4},
{x: 0, y: 0},
{x: 4, y: 0},
{x: 4, y: 1}
]);
});

it('validates pf {test 3}', () => {
const path = grid.findPath(
{ x: 4, y: 2 },
{ x: 4, y: 1 },
100
)
expect(path).toEqual([
{ x: 4, y: 2 },
{ x: 4, y: 1 }
]);
});

it('validates pf {test 4}', () => {
const path = grid.findPath(
{ x: 4, y: 2 },
{ x: 4, y: 1 },
1
)
expect(path).toEqual([]);
});
})
16 changes: 16 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module.exports = {
presets: [
[
'@babel/env',
{
targets: {
node: 'current'
}
}
],
'@babel/typescript'
],
plugins: [
["@babel/plugin-transform-typescript", { "allowNamespaces": true }]
]
};
Loading

0 comments on commit b81a1e0

Please sign in to comment.