Skip to content

Commit

Permalink
Add types to library
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexandreKavalerski committed Jul 9, 2020
1 parent f4dc22c commit 9b77a47
Show file tree
Hide file tree
Showing 17 changed files with 95 additions and 0 deletions.
6 changes: 6 additions & 0 deletions dist/classes/HeuristicValue.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export default class HeuristicValue {
g: number;
h: number;
f: number;
constructor(g: number, h: number, f: number);
}
11 changes: 11 additions & 0 deletions dist/classes/Node.d.ts
Original file line number Diff line number Diff line change
@@ -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 };
10 changes: 10 additions & 0 deletions dist/classes/Result.d.ts
Original file line number Diff line number Diff line change
@@ -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[]);
}
7 changes: 7 additions & 0 deletions dist/classes/Solution.d.ts
Original file line number Diff line number Diff line change
@@ -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);
}
5 changes: 5 additions & 0 deletions dist/classes/StateItemPosition.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default class StateItemPosition {
line: number;
col: number;
constructor(l: number, c: number);
}
5 changes: 5 additions & 0 deletions dist/functions/AStar.d.ts
Original file line number Diff line number Diff line change
@@ -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 };
5 changes: 5 additions & 0 deletions dist/functions/heuristic.d.ts
Original file line number Diff line number Diff line change
@@ -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 };
6 changes: 6 additions & 0 deletions dist/functions/node.d.ts
Original file line number Diff line number Diff line change
@@ -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 };
10 changes: 10 additions & 0 deletions dist/functions/operations.d.ts
Original file line number Diff line number Diff line change
@@ -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 };
4 changes: 4 additions & 0 deletions dist/functions/solution.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { NodeInfo } from "../classes/Node";
import SolutionItem from "../classes/Solution";
declare function getSolutionFromNode(node: NodeInfo, list: SolutionItem[]): SolutionItem[];
export { getSolutionFromNode };
7 changes: 7 additions & 0 deletions dist/functions/state.d.ts
Original file line number Diff line number Diff line change
@@ -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 };
4 changes: 4 additions & 0 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
@@ -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 };
2 changes: 2 additions & 0 deletions dist/utils/frontier.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import { NodeInfo } from "../classes/Node";
export declare type Frontier = NodeInfo[];
7 changes: 7 additions & 0 deletions dist/utils/operations.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export declare enum operations {
up = "UP_OPERATION",
right = "RIGHT_OPERATION",
down = "DOWN_OPERATION",
left = "LEFT_OPERATION",
none = "NONE"
}
4 changes: 4 additions & 0 deletions dist/utils/state.d.ts
Original file line number Diff line number Diff line change
@@ -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 };
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 9b77a47

Please sign in to comment.