aboutsummaryrefslogtreecommitdiff
path: root/src/Board/Board.ts
blob: 2c4a2154999726efa42bbb233e3309f83e7c1c3b (plain)
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
import _ from 'lodash';
import Tile, { Feature } from '../Tile/Tile';
import TileOnBoard from '../Tile/TileOnBoard';

const { Road, Town, Grass } = Feature;

export default class Board {
  tiles: TileOnBoard[];

  constructor(tiles?: TileOnBoard[]) {
    if (tiles) this.tiles = tiles;
    else this.tiles = [new TileOnBoard(Road, [Town, Road, Grass, Road])]
  }

  print() {
    this.tiles.forEach(tile => tile.print());
  }

  getAttachments(tile: Tile) {
    return _.flatten(this.tiles.map(attachTo => attachTo.getAttachments(tile)));
  }

  getLegalMoves(tile: Tile) {
    const attachments = this.getAttachments(tile);
    console.log(attachments);
  }
}