aboutsummaryrefslogtreecommitdiff
path: root/index.ts
diff options
context:
space:
mode:
authoreug-vs <eugene@eug-vs.xyz>2022-03-11 15:14:36 +0300
committereug-vs <eugene@eug-vs.xyz>2022-03-11 15:14:36 +0300
commitc8341b265e69d5a08f0110558297a7a36b8a5394 (patch)
tree6a7a2ac078caa8cfa96417d27d334fef35ba90c6 /index.ts
parent03623a7e835dde461c44acc77fe670574dfe2c4b (diff)
downloadcarcassonne-engine-ts-c8341b265e69d5a08f0110558297a7a36b8a5394.tar.gz
chore: add tests for Cell
Diffstat (limited to 'index.ts')
-rw-r--r--index.ts65
1 files changed, 0 insertions, 65 deletions
diff --git a/index.ts b/index.ts
deleted file mode 100644
index 4ca38ae..0000000
--- a/index.ts
+++ /dev/null
@@ -1,65 +0,0 @@
-import Debug, { Debugger } from 'debug';
-
-enum Direction {
- North,
- East,
- South,
- West
-}
-
-enum Item {
- Empty = " ",
- Road = "R",
- Town = "T",
- River = "I",
- Church = "C",
-}
-
-class Cell {
- center: Item;
- private sides: [Item, Item, Item, Item];
- 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], shield = false) {
- this.center = center;
- this.sides = sides;
- this.shield = shield;
- this.orientation = 0;
-
- this.debug = Debug('cell');
- }
-
- toString() {
- return ` ${this.getSide(Direction.North)} \n${this.getSide(Direction.West)}${this.center}${this.getSide(Direction.East)}\n ${this.getSide(Direction.South)} `;
- }
-
- getSide(direction: Direction) {
- return this.sides[(((this.orientation + direction) % 4) + 4) % 4];
- }
-
- rotate(rotation = 1) {
- this.debug(`Rotating ${rotation} clockwise`)
- this.orientation = this.orientation - rotation;
- }
-
- isAttachable(cell: Cell, side: Direction) {
- return (this.getSide(side) === cell.getSide(side + 2));
- }
-
-}
-
-const test = () => {
- const cell = new Cell(Item.Empty, [Item.Road, Item.Road, Item.Town, Item.Town]);
- console.log(cell.toString());
-
-
- const other = new Cell(Item.Empty, [Item.Road, Item.Road, Item.Town, Item.Town]);
- other.rotate();
- console.log(other.toString());
- console.log(cell.isAttachable(other, Direction.North));
-}
-
-test();