-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf: Add tests for Ultimate-Tic-Tac-Toe and ability to set duration …
…on each call of getAction()
- Loading branch information
Philippe Vaillancourt
committed
May 2, 2018
1 parent
2085c78
commit 1d7c40b
Showing
7 changed files
with
401 additions
and
8 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
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
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,57 @@ | ||
import { UTicTacToeState, UTicTacToeMove, uTicTacToeFuncs } from './ultimate-tic-tac-toe' | ||
import { Macao } from '../../src/macao' | ||
import { loopFor } from '../../src/utils' | ||
|
||
xdescribe('The Macao instance', () => { | ||
let uTicTacToeBoard: number[][][][] | ||
let state: UTicTacToeState | ||
let mcts: Macao<UTicTacToeState, UTicTacToeMove> | ||
|
||
describe('when used to simulate 100 Ultimate Tic Tac Toe games', () => { | ||
describe('given 85 ms per turn and an exploration param of 1.414', () => { | ||
it('should end in a draw 95% of the time or better', () => { | ||
let results = 0 | ||
loopFor(100).turns(() => { | ||
mcts = new Macao( | ||
{ | ||
stateIsTerminal: uTicTacToeFuncs.stateIsTerminal, | ||
generateActions: uTicTacToeFuncs.generateActions, | ||
applyAction: uTicTacToeFuncs.applyAction, | ||
calculateReward: uTicTacToeFuncs.calculateReward | ||
}, | ||
{ duration: 85 } | ||
) | ||
uTicTacToeBoard = [ | ||
[ | ||
[[0, 0, 0], [0, 0, 0], [0, 0, 0]], | ||
[[0, 0, 0], [0, 0, 0], [0, 0, 0]], | ||
[[0, 0, 0], [0, 0, 0], [0, 0, 0]] | ||
], | ||
[ | ||
[[0, 0, 0], [0, 0, 0], [0, 0, 0]], | ||
[[0, 0, 0], [0, 0, 0], [0, 0, 0]], | ||
[[0, 0, 0], [0, 0, 0], [0, 0, 0]] | ||
], | ||
[ | ||
[[0, 0, 0], [0, 0, 0], [0, 0, 0]], | ||
[[0, 0, 0], [0, 0, 0], [0, 0, 0]], | ||
[[0, 0, 0], [0, 0, 0], [0, 0, 0]] | ||
] | ||
] | ||
state = { | ||
board: uTicTacToeBoard, | ||
player: -1, | ||
previousAction: { bigRow: -1, bigCol: -1, smallRow: -1, smallCol: -1 } | ||
} | ||
while (!uTicTacToeFuncs.stateIsTerminal(state)) { | ||
const action = mcts.getAction(state) | ||
state = uTicTacToeFuncs.applyAction(state, action) | ||
} | ||
|
||
results += uTicTacToeFuncs.calculateReward(state, 1) === 0 ? 1 : 0 | ||
}) | ||
expect(results).toBeGreaterThan(95) | ||
}) | ||
}) | ||
}) | ||
}) |
Oops, something went wrong.