All files Path.ts

16.66% Statements 2/12
0% Branches 0/3
0% Functions 0/4
16.66% Lines 2/12

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55        1x                               1x                                                                    
/**
 * @author Timo Lehnertz
 */
import { BoardPosition } from "./BoardPosition";
import { Heading, HeadingHelper } from "./Heading";
 
export interface PathPart {
  from: BoardPosition;
  to: BoardPosition;
  heading: Heading;
}
 
export interface IndexedPathPart {
  from: PathPart;
  to: PathPart;
}
 
/**
 * Mutable Path class representing a path from one field to another
 */
export class Path {
  public readonly parts: PathPart[];
  // private readonly indexedParts: (IndexedPathPart | null)[][] = [];
 
  public constructor(parts: PathPart[]) {
    this.parts = parts;
    // for (let x = 0; x < width; x++) {
    //   for (let x = 0; x < width; x++) {
    //     const element = array[x];
 
    //   }
    // }
  }
 
  public getHeadings(position: BoardPosition): Heading[] {
    const headings: Heading[] = [];
    for (const part of this.parts) {
      if (part.from.equals(position)) {
        headings.push(part.heading);
      } else Iif (part.to.equals(position)) {
        headings.push(new HeadingHelper(part.heading).inverted);
      }
    }
    return headings;
  }
 
  public get length(): number {
    return this.parts.length;
  }
 
  public getPart(index: number): PathPart {
    return this.parts[index];
  }
}