diff options
Diffstat (limited to 'src/Board')
-rw-r--r-- | src/Board/Board.test.ts | 25 | ||||
-rw-r--r-- | src/Board/Board.ts | 21 |
2 files changed, 24 insertions, 22 deletions
diff --git a/src/Board/Board.test.ts b/src/Board/Board.test.ts index c4e5ed1..1370a87 100644 --- a/src/Board/Board.test.ts +++ b/src/Board/Board.test.ts @@ -1,30 +1,31 @@ import assert from 'assert'; import Tile, { Feature } from '../Tile/Tile'; -import Board from "./Board"; +import TileOnBoard from '../Tile/TileOnBoard'; +import Board from './Board'; const { Road, Town, Empty } = Feature; describe('Board', () => { describe('constructor', () => { - it('Should initialize empty board with a starting cell', () => { + it('Should initialize empty board with a starting tile', () => { const board = new Board(); - assert.strictEqual(board.cells.length, 1); - assert.deepStrictEqual(board.cells[0], new Tile(Road, [Town, Road, Empty, Road])); + assert.strictEqual(board.tiles.length, 1); + assert.deepStrictEqual(board.tiles[0], new TileOnBoard(Road, [Town, Road, Empty, Road])); }); }); describe('getAttachments', () => { - it('Should correctly determine legal moves for 1-cell board', () => { + it('Should correctly determine legal moves for 1-tile board', () => { const board = new Board(); - const attachTo = board.cells[0]; - const cell = new Tile(Town, [Empty, Town, Empty, Town]); - const legalMoves = board.getAttachments(cell); + const attachTo = board.tiles[0]; + const tile = new Tile(Town, [Empty, Town, Empty, Town]); + const legalMoves = board.getAttachments(tile); assert.strictEqual(legalMoves.length, 4); - assert.deepStrictEqual(legalMoves[0], { side: 0, rotation: 1, attachTo, cell }); - assert.deepStrictEqual(legalMoves[1], { side: 0, rotation: 3, attachTo, cell }); - assert.deepStrictEqual(legalMoves[2], { side: 2, rotation: 0, attachTo, cell }); - assert.deepStrictEqual(legalMoves[3], { side: 2, rotation: 2, attachTo, cell }); + assert.deepStrictEqual(legalMoves[0], { side: 0, rotation: 1, attachTo, tile }); + assert.deepStrictEqual(legalMoves[1], { side: 0, rotation: 3, attachTo, tile }); + assert.deepStrictEqual(legalMoves[2], { side: 2, rotation: 0, attachTo, tile }); + assert.deepStrictEqual(legalMoves[3], { side: 2, rotation: 2, attachTo, tile }); }); }); }); diff --git a/src/Board/Board.ts b/src/Board/Board.ts index f1aa45b..59afd31 100644 --- a/src/Board/Board.ts +++ b/src/Board/Board.ts @@ -1,26 +1,27 @@ import _ from 'lodash'; -import Tile, { Feature } from "../Tile/Tile"; +import Tile, { Feature } from '../Tile/Tile'; +import TileOnBoard from '../Tile/TileOnBoard'; const { Road, Town, Empty } = Feature; export default class Board { - cells: Tile[]; + tiles: TileOnBoard[]; - constructor(cells?: Tile[]) { - if (cells) this.cells = cells; - else this.cells = [new Tile(Road, [Town, Road, Empty, Road])] + constructor(tiles?: TileOnBoard[]) { + if (tiles) this.tiles = tiles; + else this.tiles = [new TileOnBoard(Road, [Town, Road, Empty, Road])] } print() { - this.cells.forEach(cell => cell.print()); + this.tiles.forEach(tile => tile.print()); } - getAttachments(cell: Tile) { - return _.flatten(this.cells.map(attachTo => attachTo.getAttachments(cell))); + getAttachments(tile: Tile) { + return _.flatten(this.tiles.map(attachTo => attachTo.getAttachments(tile))); } - getLegalMoves(cell: Tile) { - const attachments = this.getAttachments(cell); + getLegalMoves(tile: Tile) { + const attachments = this.getAttachments(tile); console.log(attachments); } } |