From 9b77a4733fc659fdeac408c7101e7356c90a4655 Mon Sep 17 00:00:00 2001 From: Alexandre Date: Thu, 9 Jul 2020 20:33:11 -0300 Subject: [PATCH] Add types to library --- dist/classes/HeuristicValue.d.ts | 6 ++++++ dist/classes/Node.d.ts | 11 +++++++++++ dist/classes/Result.d.ts | 10 ++++++++++ dist/classes/Solution.d.ts | 7 +++++++ dist/classes/StateItemPosition.d.ts | 5 +++++ dist/functions/AStar.d.ts | 5 +++++ dist/functions/heuristic.d.ts | 5 +++++ dist/functions/node.d.ts | 6 ++++++ dist/functions/operations.d.ts | 10 ++++++++++ dist/functions/solution.d.ts | 4 ++++ dist/functions/state.d.ts | 7 +++++++ dist/index.d.ts | 4 ++++ dist/utils/frontier.d.ts | 2 ++ dist/utils/operations.d.ts | 7 +++++++ dist/utils/state.d.ts | 4 ++++ package.json | 1 + tsconfig.json | 1 + 17 files changed, 95 insertions(+) create mode 100644 dist/classes/HeuristicValue.d.ts create mode 100644 dist/classes/Node.d.ts create mode 100644 dist/classes/Result.d.ts create mode 100644 dist/classes/Solution.d.ts create mode 100644 dist/classes/StateItemPosition.d.ts create mode 100644 dist/functions/AStar.d.ts create mode 100644 dist/functions/heuristic.d.ts create mode 100644 dist/functions/node.d.ts create mode 100644 dist/functions/operations.d.ts create mode 100644 dist/functions/solution.d.ts create mode 100644 dist/functions/state.d.ts create mode 100644 dist/index.d.ts create mode 100644 dist/utils/frontier.d.ts create mode 100644 dist/utils/operations.d.ts create mode 100644 dist/utils/state.d.ts diff --git a/dist/classes/HeuristicValue.d.ts b/dist/classes/HeuristicValue.d.ts new file mode 100644 index 0000000..10f129e --- /dev/null +++ b/dist/classes/HeuristicValue.d.ts @@ -0,0 +1,6 @@ +export default class HeuristicValue { + g: number; + h: number; + f: number; + constructor(g: number, h: number, f: number); +} diff --git a/dist/classes/Node.d.ts b/dist/classes/Node.d.ts new file mode 100644 index 0000000..0951980 --- /dev/null +++ b/dist/classes/Node.d.ts @@ -0,0 +1,11 @@ +import { State } from "../utils/state"; +import { operations } from "../utils/operations"; +import HeuristicValue from "./HeuristicValue"; +declare class NodeInfo { + evaluationFunctionValue: HeuristicValue; + operation: operations; + state: State; + previousNode?: NodeInfo; + constructor(efValue: HeuristicValue, op: operations, s: State, prev?: NodeInfo); +} +export { NodeInfo }; diff --git a/dist/classes/Result.d.ts b/dist/classes/Result.d.ts new file mode 100644 index 0000000..ec838f5 --- /dev/null +++ b/dist/classes/Result.d.ts @@ -0,0 +1,10 @@ +import { NodeInfo } from "./Node"; +import SolutionItem from "./Solution"; +export default class Result { + pathCost: number; + iterations: number; + expandedNodes: number; + finalNode: NodeInfo; + solution?: SolutionItem[]; + constructor(pathCost: number, iterations: number, expandedNodes: number, finalNode: NodeInfo, solution?: SolutionItem[]); +} diff --git a/dist/classes/Solution.d.ts b/dist/classes/Solution.d.ts new file mode 100644 index 0000000..618cbdc --- /dev/null +++ b/dist/classes/Solution.d.ts @@ -0,0 +1,7 @@ +import { operations } from './../utils/operations'; +import { StateAsList } from "../utils/state"; +export default class SolutionItem { + state: StateAsList; + operation: operations; + constructor(s: StateAsList, op: operations); +} diff --git a/dist/classes/StateItemPosition.d.ts b/dist/classes/StateItemPosition.d.ts new file mode 100644 index 0000000..bf25a3f --- /dev/null +++ b/dist/classes/StateItemPosition.d.ts @@ -0,0 +1,5 @@ +export default class StateItemPosition { + line: number; + col: number; + constructor(l: number, c: number); +} diff --git a/dist/functions/AStar.d.ts b/dist/functions/AStar.d.ts new file mode 100644 index 0000000..596108a --- /dev/null +++ b/dist/functions/AStar.d.ts @@ -0,0 +1,5 @@ +import { State } from "../utils/state"; +import { NodeInfo } from "../classes/Node"; +import Result from "../classes/Result"; +declare function runAStarLoop(goalState: State, frontier: NodeInfo[], expandedStates: State[]): Result | undefined; +export { runAStarLoop as run }; diff --git a/dist/functions/heuristic.d.ts b/dist/functions/heuristic.d.ts new file mode 100644 index 0000000..34f6b26 --- /dev/null +++ b/dist/functions/heuristic.d.ts @@ -0,0 +1,5 @@ +import { State, StateItem } from "../utils/state"; +import StateItemPosition from "../classes/StateItemPosition"; +declare function calcHValue(actualState: State, goalState: State): number; +declare function calcDistanceOfItem(item: StateItem, itemPosition: StateItemPosition, goalState: State): number; +export { calcHValue, calcDistanceOfItem }; diff --git a/dist/functions/node.d.ts b/dist/functions/node.d.ts new file mode 100644 index 0000000..3361db8 --- /dev/null +++ b/dist/functions/node.d.ts @@ -0,0 +1,6 @@ +import { operations } from './../utils/operations'; +import { NodeInfo } from "../classes/Node"; +import { State } from '../utils/state'; +declare function generateNodeList(node: NodeInfo, goalState: State): NodeInfo[]; +declare function generateNode(state: State, op: operations, goalState: State, gValue: number, previousNode?: NodeInfo): NodeInfo; +export { generateNodeList, generateNode }; diff --git a/dist/functions/operations.d.ts b/dist/functions/operations.d.ts new file mode 100644 index 0000000..ab22f1d --- /dev/null +++ b/dist/functions/operations.d.ts @@ -0,0 +1,10 @@ +import { State } from "../utils/state"; +import { operations } from "../utils/operations"; +import StateItemPosition from "../classes/StateItemPosition"; +declare function applyOperation(state: State, op: operations): State | null | undefined; +declare function moveUpOperation(state: State): State | null; +declare function moveRightOperation(state: State): State | null; +declare function moveDownOperation(state: State): State | null; +declare function moveLeftOperation(state: State): State | null; +declare function getPositionOfBlankItem(state: State): StateItemPosition; +export { applyOperation, moveUpOperation, moveRightOperation, moveDownOperation, moveLeftOperation, getPositionOfBlankItem }; diff --git a/dist/functions/solution.d.ts b/dist/functions/solution.d.ts new file mode 100644 index 0000000..a46a997 --- /dev/null +++ b/dist/functions/solution.d.ts @@ -0,0 +1,4 @@ +import { NodeInfo } from "../classes/Node"; +import SolutionItem from "../classes/Solution"; +declare function getSolutionFromNode(node: NodeInfo, list: SolutionItem[]): SolutionItem[]; +export { getSolutionFromNode }; diff --git a/dist/functions/state.d.ts b/dist/functions/state.d.ts new file mode 100644 index 0000000..fbb8aa2 --- /dev/null +++ b/dist/functions/state.d.ts @@ -0,0 +1,7 @@ +import { State, StateAsList } from "../utils/state"; +declare function areEqual(state1: State, state2: State): boolean; +declare function includes(state: State, list: State[]): boolean; +declare function isSolvable(state: State): boolean; +declare function convertStateInArray(state: State): StateAsList; +declare function convertArrayInState(stateList: StateAsList): State; +export { areEqual, includes, isSolvable, convertArrayInState, convertStateInArray }; diff --git a/dist/index.d.ts b/dist/index.d.ts new file mode 100644 index 0000000..e777742 --- /dev/null +++ b/dist/index.d.ts @@ -0,0 +1,4 @@ +import { State, StateAsList } from "./utils/state"; +import { isSolvable, convertArrayInState, convertStateInArray } from './functions/state'; +declare function index(state: StateAsList, finalState?: State): import("./classes/Result").default; +export { index as solvePuzzle, convertArrayInState, convertStateInArray, isSolvable }; diff --git a/dist/utils/frontier.d.ts b/dist/utils/frontier.d.ts new file mode 100644 index 0000000..9b4fe55 --- /dev/null +++ b/dist/utils/frontier.d.ts @@ -0,0 +1,2 @@ +import { NodeInfo } from "../classes/Node"; +export declare type Frontier = NodeInfo[]; diff --git a/dist/utils/operations.d.ts b/dist/utils/operations.d.ts new file mode 100644 index 0000000..8bc886c --- /dev/null +++ b/dist/utils/operations.d.ts @@ -0,0 +1,7 @@ +export declare enum operations { + up = "UP_OPERATION", + right = "RIGHT_OPERATION", + down = "DOWN_OPERATION", + left = "LEFT_OPERATION", + none = "NONE" +} diff --git a/dist/utils/state.d.ts b/dist/utils/state.d.ts new file mode 100644 index 0000000..4d500a1 --- /dev/null +++ b/dist/utils/state.d.ts @@ -0,0 +1,4 @@ +declare type StateItem = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 0; +declare type State = [[StateItem, StateItem, StateItem], [StateItem, StateItem, StateItem], [StateItem, StateItem, StateItem]]; +declare type StateAsList = StateItem[]; +export { State, StateItem, StateAsList }; diff --git a/package.json b/package.json index e3a8ca7..e5f98ab 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,7 @@ "version": "2.0.1", "description": "A* search algorithm in TypeScript that solves puzzle game problem", "main": "dist/index.js", + "types": "dist/index.d.ts", "dependencies": {}, "devDependencies": { "@types/chai": "^4.2.11", diff --git a/tsconfig.json b/tsconfig.json index 8cd50a7..4261c4f 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -9,6 +9,7 @@ "skipLibCheck": true, /* Skip type checking of declaration files. */ "forceConsistentCasingInFileNames": true, /* Disallow inconsistently-cased references to the same file. */ "sourceMap": true, + "declaration": true }, "include":[ "src/**/*.ts"