aboutsummaryrefslogtreecommitdiff
path: root/src/Board/Board.ts
diff options
context:
space:
mode:
authoreug-vs <eugene@eug-vs.xyz>2022-03-12 14:36:31 +0300
committereug-vs <eugene@eug-vs.xyz>2022-03-12 14:37:11 +0300
commit8aa2213390e01996e3f9682abfd5910c698df0e2 (patch)
tree86be278563cf285392c58e3938d002a5b288d7a5 /src/Board/Board.ts
parent2b6ba3f395cb62bef07f2cc12a00dab0c1cf2f04 (diff)
downloadcarcassonne-engine-ts-8aa2213390e01996e3f9682abfd5910c698df0e2.tar.gz
feat: add initial Board class
Diffstat (limited to 'src/Board/Board.ts')
-rw-r--r--src/Board/Board.ts26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/Board/Board.ts b/src/Board/Board.ts
new file mode 100644
index 0000000..c511e89
--- /dev/null
+++ b/src/Board/Board.ts
@@ -0,0 +1,26 @@
+import _ from 'lodash';
+import Cell, { Item } from "../Cell/Cell";
+
+const { Road, Town, Empty } = Item;
+
+export default class Board {
+ cells: Cell[];
+
+ constructor(cells?: Cell[]) {
+ if (cells) this.cells = cells;
+ else this.cells = [new Cell(Road, [Town, Road, Empty, Road])]
+ }
+
+ print() {
+ this.cells.forEach(cell => cell.print());
+ }
+
+ getAttachments(cell: Cell) {
+ return _.flatten(this.cells.map(attachTo => attachTo.getAttachments(cell)));
+ }
+
+ getLegalMoves(cell: Cell) {
+ const attachments = this.getAttachments(cell);
+ console.log(attachments);
+ }
+}