-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
75 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
const moveRegex = /(\d)?([CSF])?([a-h][1-8])(?:([<>+-])([1-8]+))?/g; | ||
|
||
class Move { | ||
private stone: string = "F"; | ||
constructor(ptn: string) { | ||
let parsed = ptn.match(moveRegex); | ||
if(!parsed) throw new Error("Invalid PTN string"); | ||
if(parsed[2]) { | ||
this.stone = parsed[2]; | ||
} | ||
|
||
} | ||
|
||
static fromPtn(ptn: string): Move { | ||
return new Move(ptn); | ||
} | ||
} | ||
|
||
export = Move; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,19 @@ | ||
"use strict"; | ||
const expect = require("chai").expect; | ||
const GameState = require("../dist/gameState") | ||
const ptnFile = require('./resources/ptnFile') | ||
|
||
describe("GameState", () => { | ||
it("should assume a board size of 5", () => { | ||
var state = new GameState(); | ||
expect(state.size).to.equal(5); | ||
}); | ||
it("should read data from PTN file", () => { | ||
var state = GameState.fromPtnFile(ptnFile.simplePtnFile); | ||
expect(state.size).to.equal(6); | ||
expect(state.playerOne).to.equal("NohatCoder"); | ||
expect(state.playerTwo).to.equal("fwwwwibib"); | ||
expect(state.isGameOver).to.be.true; | ||
expect(state.result).to.equal("R-0"); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
exports.simplePtnFile = `[Site "PlayTak.com"] | ||
[Event "Online Play"] | ||
[Date "2018.10.28"] | ||
[Time "16:10:44"] | ||
[Player1 "NohatCoder"] | ||
[Player2 "fwwwwibib"] | ||
[Clock "10:0 +20"] | ||
[Result "R-0"] | ||
[Size "6"] | ||
1. a6 f6 | ||
2. d4 c4 | ||
3. d3 c3 | ||
4. d5 c5 | ||
5. d2 Ce4 | ||
6. c2 e3 | ||
7. e2 b2 | ||
8. Cb3 1e4<1 | ||
9. 1d3<1 Sd1 | ||
10. a3 1d1+1` |