aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Board/Board.test.ts8
-rw-r--r--src/Board/Board.ts14
-rw-r--r--src/Tile/Tile.test.ts (renamed from src/Cell/Cell.test.ts)16
-rw-r--r--src/Tile/Tile.ts (renamed from src/Cell/Cell.ts)22
4 files changed, 30 insertions, 30 deletions
diff --git a/src/Board/Board.test.ts b/src/Board/Board.test.ts
index ad5509f..c4e5ed1 100644
--- a/src/Board/Board.test.ts
+++ b/src/Board/Board.test.ts
@@ -1,15 +1,15 @@
import assert from 'assert';
-import Cell, { Item } from '../Cell/Cell';
+import Tile, { Feature } from '../Tile/Tile';
import Board from "./Board";
-const { Road, Town, Empty } = Item;
+const { Road, Town, Empty } = Feature;
describe('Board', () => {
describe('constructor', () => {
it('Should initialize empty board with a starting cell', () => {
const board = new Board();
assert.strictEqual(board.cells.length, 1);
- assert.deepStrictEqual(board.cells[0], new Cell(Road, [Town, Road, Empty, Road]));
+ assert.deepStrictEqual(board.cells[0], new Tile(Road, [Town, Road, Empty, Road]));
});
});
@@ -17,7 +17,7 @@ describe('Board', () => {
it('Should correctly determine legal moves for 1-cell board', () => {
const board = new Board();
const attachTo = board.cells[0];
- const cell = new Cell(Town, [Empty, Town, Empty, Town]);
+ const cell = new Tile(Town, [Empty, Town, Empty, Town]);
const legalMoves = board.getAttachments(cell);
assert.strictEqual(legalMoves.length, 4);
diff --git a/src/Board/Board.ts b/src/Board/Board.ts
index c511e89..f1aa45b 100644
--- a/src/Board/Board.ts
+++ b/src/Board/Board.ts
@@ -1,25 +1,25 @@
import _ from 'lodash';
-import Cell, { Item } from "../Cell/Cell";
+import Tile, { Feature } from "../Tile/Tile";
-const { Road, Town, Empty } = Item;
+const { Road, Town, Empty } = Feature;
export default class Board {
- cells: Cell[];
+ cells: Tile[];
- constructor(cells?: Cell[]) {
+ constructor(cells?: Tile[]) {
if (cells) this.cells = cells;
- else this.cells = [new Cell(Road, [Town, Road, Empty, Road])]
+ else this.cells = [new Tile(Road, [Town, Road, Empty, Road])]
}
print() {
this.cells.forEach(cell => cell.print());
}
- getAttachments(cell: Cell) {
+ getAttachments(cell: Tile) {
return _.flatten(this.cells.map(attachTo => attachTo.getAttachments(cell)));
}
- getLegalMoves(cell: Cell) {
+ getLegalMoves(cell: Tile) {
const attachments = this.getAttachments(cell);
console.log(attachments);
}
diff --git a/src/Cell/Cell.test.ts b/src/Tile/Tile.test.ts
index be6f475..62ac51e 100644
--- a/src/Cell/Cell.test.ts
+++ b/src/Tile/Tile.test.ts
@@ -1,13 +1,13 @@
import assert from 'assert';
-import Cell, { Direction, Item } from './Cell';
+import Tile, { Direction, Feature } from './Tile';
const { North, East, South, West } = Direction;
-const { Road, Town, Empty, River } = Item;
+const { Road, Town, Empty, River } = Feature;
-describe('Cell', () => {
+describe('Tile', () => {
describe('getSide', () => {
it('Should get North, East, South and West sides correctly', () => {
- const cell = new Cell(Empty, [Road, Town, Empty, River]);
+ const cell = new Tile(Empty, [Road, Town, Empty, River]);
assert.strictEqual(cell.getSide(North), Road);
assert.strictEqual(cell.getSide(East), Town);
@@ -16,7 +16,7 @@ describe('Cell', () => {
});
it('Should respect cell orientation', () => {
- const cell = new Cell(Empty, [Road, Town, Empty, River]);
+ const cell = new Tile(Empty, [Road, Town, Empty, River]);
cell.rotate(5);
assert.strictEqual(cell.getSide(North), River);
@@ -26,7 +26,7 @@ describe('Cell', () => {
});
it('Should work with negative orientation', () => {
- const cell = new Cell(Empty, [Road, Town, Empty, River]);
+ const cell = new Tile(Empty, [Road, Town, Empty, River]);
cell.rotate(-7);
assert.strictEqual(cell.getSide(North), River);
@@ -38,8 +38,8 @@ describe('Cell', () => {
describe('getAttachments', () => {
it('Should correclty list legal attachments', () => {
- const attachTo = new Cell(Town, [Road, Town, Town, Road])
- const cell = new Cell(Road, [Empty, Road, Road, Empty])
+ const attachTo = new Tile(Town, [Road, Town, Town, Road])
+ const cell = new Tile(Road, [Empty, Road, Road, Empty])
cell.print();
attachTo.print();
diff --git a/src/Cell/Cell.ts b/src/Tile/Tile.ts
index 70bb792..4eee263 100644
--- a/src/Cell/Cell.ts
+++ b/src/Tile/Tile.ts
@@ -10,7 +10,7 @@ export enum Direction {
West
}
-export enum Item {
+export enum Feature {
Empty = " ",
Road = "R",
Town = "T",
@@ -19,23 +19,23 @@ export enum Item {
}
export interface Attachment {
- attachTo: Cell;
+ attachTo: Tile;
side: Direction;
- cell: Cell;
+ cell: Tile;
rotation: number; // Clockwise rotation of a cell
}
-export default class Cell {
- center: Item;
- private sides: [Item, Item, Item, Item];
- neighbors: [Cell, Cell, Cell, Cell];
+export default class Tile {
+ center: Feature;
+ private sides: [Feature, Feature, Feature, Feature];
+ neighbors: [Tile, Tile, Tile, Tile];
private orientation: number // amount of 90-degree counter-clockwise rotations from original orientation
shield?: boolean;
debug: Debugger;
- public constructor(center: Item, sides: [Item, Item, Item, Item], orientation = 0, shield = false) {
+ public constructor(center: Feature, sides: [Feature, Feature, Feature, Feature], orientation = 0, shield = false) {
this.center = center;
this.sides = sides;
this.shield = shield;
@@ -55,7 +55,7 @@ export default class Cell {
this.orientation = this.orientation - rotation;
}
- getAttachments(cell: Cell) {
+ getAttachments(cell: Tile) {
return _.flatten([0, 1, 2, 3].map(side => {
const item = this.getSide(side);
return [0, 1, 2, 3]
@@ -64,12 +64,12 @@ export default class Cell {
cell,
rotation,
side,
- attachTo: this as Cell
+ attachTo: this as Tile
}))
}));
}
- attach(cell: Cell, side: Direction) {
+ attach(cell: Tile, side: Direction) {
if (this.neighbors[side]) throw new Error('There is something already attached to this side!');
this.neighbors[side] = cell;
}