Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Demo] Use AI to codemod this repo to TS #31

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions lib/camelot-engine.js

This file was deleted.

42 changes: 21 additions & 21 deletions lib/camelot-engine.test.js → lib/camelot-engine.test.ts
Original file line number Diff line number Diff line change
@@ -1,71 +1,71 @@
'use strict';

var expect = require('chai').expect,
camelotEngine = require('..');
import { expect } from 'chai';
import camelotEngine from '..';
import { GameState, Player, MovePart, Row, Col, Space } from 'my-global-types';

describe('camelot-engine', function() {
describe('camelot-engine', () => {

describe('createEmptyGame', function() {
describe('createEmptyGame', () => {

it('should have turnCount = 0', function() {
it('should have turnCount = 0', () => {
expect(camelotEngine().createEmptyGame()).to.have.property('turnCount', 0);
});

it('should have no captured pieces', function() {
it('should have no captured pieces', () => {
expect(camelotEngine().createEmptyGame().capturedPieces).to.deep.equal({
playerA: {pawn: 0, knight: 0},
playerB: {pawn: 0, knight: 0}
});
});

it('should create board spaces', function() {
it('should create board spaces', () => {
expect(camelotEngine().createEmptyGame().boardSpaces).to.have.property('length', 172);
});

});

describe('query', function() {
describe('query', () => {

it('exports isGoal', function() {
it('exports isGoal', () => {
expect(camelotEngine().query().isGoal).to.be.a('function');
});

it('exports isValidMove', function() {
it('exports isValidMove', () => {
expect(camelotEngine().query().isValidMove).to.be.a('function');
});

it('exports getGameWinner', function() {
it('exports getGameWinner', () => {
expect(camelotEngine().query().getGameWinner).to.be.a('function');
});

it('exports getBoardSpace', function() {
it('exports getBoardSpace', () => {
expect(camelotEngine().query().getBoardSpace).to.be.a('function');
});

it('exports getAllBoardSpaces', function() {
it('exports getAllBoardSpaces', () => {
expect(camelotEngine().query().getAllBoardSpaces).to.be.a('function');
});

it('exports getCoordsBetween', function() {
it('exports getCoordsBetween', () => {
expect(camelotEngine().query().getCoordsBetween).to.be.a('function');
});

});

describe('update', function() {
it('exports applyMoves', function() {
describe('update', () => {
it('exports applyMoves', () => {
expect(camelotEngine().update().applyMoves).to.be.a('function');
});
});

describe('constants', function() {
it('exports KNIGHT', function() {
describe('constants', () => {
it('exports KNIGHT', () => {
expect(camelotEngine().constants().KNIGHT).to.be.a('string');
});

it('exports PAWN', function() {
it('exports PAWN', () => {
expect(camelotEngine().constants().PAWN).to.be.a('string');
});
});

});
});
23 changes: 23 additions & 0 deletions lib/camelot-engine.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

import { GameState, Player, MovePart, Row, Col, Space } from 'my-global-types';

export default function camelotEngine(): {
createEmptyGame: (numPlayers: number) => GameState;
query: (gameState: GameState) => {
getCurrentPlayer: () => Player;
getLegalMoves: () => MovePart[];
getPieceAtSpace: (row: Row, col: Col) => Space;
};
update: (gameState: GameState, moveParts: MovePart[]) => GameState;
constants: {
numRows: number;
numCols: number;
};
} {
return {
createEmptyGame: require('./init/create-empty-game'),
query: require('./query/query'),
update: require('./update/update'),
constants: require('./get-constants')
};
}
52 changes: 0 additions & 52 deletions lib/get-constants.js

This file was deleted.

43 changes: 43 additions & 0 deletions lib/get-constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@

import { GameState, Player, MovePart, Row, Col, Space } from 'my-global-types';

export const BOARD_WIDTH = 12;
export const BOARD_HEIGHT = 17;
export const KNIGHT = 'knight';
export const PAWN = 'pawn';
export const PLAYER_A = 'playerA';
export const PLAYER_B = 'playerB';
export const COUNT_PIECES_NEEDED_TO_WIN = 2;
export const PLAYER_A_GOAL_ROW: Row = 0;
export const PLAYER_B_GOAL_ROW: Row = BOARD_HEIGHT - 1;
export const STARTING_POSITIONS: Array<{
ROW: Row;
COL_START: Col;
COUNT_PAWNS: number;
COLOR: Player;
}> = [
{
ROW: 5,
COL_START: 2,
COUNT_PAWNS: 6,
COLOR: PLAYER_A
},
{
ROW: 6,
COL_START: 3,
COUNT_PAWNS: 4,
COLOR: PLAYER_A
},
{
ROW: 9,
COL_START: 3,
COUNT_PAWNS: 4,
COLOR: PLAYER_B
},
{
ROW: 10,
COL_START: 2,
COUNT_PAWNS: 6,
COLOR: PLAYER_B
},
];
24 changes: 0 additions & 24 deletions lib/init/create-board-spaces.js

This file was deleted.

24 changes: 0 additions & 24 deletions lib/init/create-board-spaces.test.js

This file was deleted.

24 changes: 24 additions & 0 deletions lib/init/create-board-spaces.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

import { expect } from 'chai';
import _ from 'lodash';
import createBoardSpaces from './create-board-spaces';
import { GameState, Player, MovePart, Row, Col, Space } from 'my-global-types';

describe('get-board-spaces', () => {

it('should create 172 board spaces', () => {
// TODO Is this the right number?
expect(createBoardSpaces()).to.have.length(172);
});

it('should have 16 rows', () => {
const generatedRows = _(createBoardSpaces())
.pluck('row')
.unique()
.sortBy(_.identity)
.valueOf();

expect(generatedRows).to.deep.equal(_.range(17));
});

});
20 changes: 20 additions & 0 deletions lib/init/create-board-spaces.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

import _ from 'lodash';
import { GameState, Player, MovePart, Row, Col, Space } from 'my-global-types';
import getRangeForRow from './get-range-for-row';

export function getBoardSpaces(): Space[] {
// TODO verify that this is actually correct

return _.flatten([
getRangeForRow(0, 5),
getRangeForRow(1, 2),
getRangeForRow(2, 1),
_.range(3, 14).map((row) => {
return getRangeForRow(row, 0);
}),
getRangeForRow(14, 1),
getRangeForRow(15, 2),
getRangeForRow(16, 5),
]);
}
31 changes: 0 additions & 31 deletions lib/init/create-empty-game.js

This file was deleted.

Loading