LoginSignup
0
0

TypeScriptでA*アルゴリズムを実装してみた

Last updated at Posted at 2023-08-01

TypeScriptでA*アルゴリズムを実装してみました。

※ 実装の詳細については、後日追記します。

実コスト(actualCost)と推定コスト(heuristicCost)を用いてソートします。

class AStarNode {
  private cell: Cell;
  private actualCost: number;
  private heuristicCost: number;
  private prev: AStarNode;

  constructor(cell: Cell) {
    this.cell = cell;
    this.actualCost = Number.MAX_VALUE;
    this.heuristicCost = 0;
    this.prev = null;
  }

  public getCell(): Cell {
    return this.cell;
  }
  public getActualCost(): number {
    return this.actualCost;
  }
  public getHeuristicCost(): number {
    return this.heuristicCost;
  }
  public getPrevNode(): AStarNode {
    return this.prev;
  }
  public setActualCost(actualCost: number): void {
    this.actualCost = actualCost;
  }
  public setHeuristicCost(heuristicCost: number): void {
    this.heuristicCost = heuristicCost;
  }
  public setPrevNode(prevNode: AStarNode): void {
    this.prev = prevNode;
  }
}

↓の優先度付きキューと組み合わせて使います。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0