@@ -233,12 +233,6 @@ describe('Bot', () => {
233233} ) ;
234234
235235describe ( 'MCTSBot' , ( ) => {
236- test ( 'defaults' , ( ) => {
237- const b = new MCTSBot ( { game : TicTacToe } ) ;
238- expect ( b . iterations ( ) ) . toBe ( 1000 ) ;
239- expect ( b . playoutDepth ( ) ) . toBe ( 50 ) ;
240- } ) ;
241-
242236 test ( 'game that never ends' , ( ) => {
243237 const game = { } ;
244238 const state = InitializeGame ( { game } ) ;
@@ -351,45 +345,53 @@ describe('MCTSBot', () => {
351345 }
352346 } ) ;
353347
354- test ( 'iterations & playout depth settings' , ( ) => {
355- const state = InitializeGame ( { game : TicTacToe } ) ;
348+ describe ( 'iterations & playout depth' , ( ) => {
349+ test ( 'set opts' , ( ) => {
350+ const bot = new MCTSBot ( { game : TicTacToe , enumerate : jest . fn ( ) } ) ;
351+ bot . setOpt ( 'iterations' , 1 ) ;
352+ expect ( bot . opts ( ) [ 'iterations' ] . value ) . toBe ( 1 ) ;
353+ } ) ;
356354
357- // jump ahead in the game because the example iterations
358- // and playoutDepth functions are based on the turn
359- state . ctx . turn = 8 ;
355+ test ( 'functions' , ( ) => {
356+ const state = InitializeGame ( { game : TicTacToe } ) ;
360357
361- const { turn, currentPlayer } = state . ctx ;
358+ // jump ahead in the game because the example iterations
359+ // and playoutDepth functions are based on the turn
360+ state . ctx . turn = 8 ;
362361
363- const enumerateSpy = jest . fn ( enumerate ) ;
362+ const { turn , currentPlayer } = state . ctx ;
364363
365- const bot = new MCTSBot ( {
366- game : TicTacToe ,
367- enumerate : enumerateSpy ,
368- iterations : ( G , ctx ) => ctx . turn * 100 ,
369- playoutDepth : ( G , ctx ) => ctx . turn * 10 ,
370- } ) ;
364+ const enumerateSpy = jest . fn ( enumerate ) ;
365+
366+ const bot = new MCTSBot ( {
367+ game : TicTacToe ,
368+ enumerate : enumerateSpy ,
369+ iterations : ( G , ctx ) => ctx . turn * 100 ,
370+ playoutDepth : ( G , ctx ) => ctx . turn * 10 ,
371+ } ) ;
371372
372- expect ( bot . iterations ( null , { turn } , currentPlayer ) ) . toBe ( turn * 100 ) ;
373- expect ( bot . playoutDepth ( null , { turn } , currentPlayer ) ) . toBe ( turn * 10 ) ;
373+ expect ( bot . iterations ( null , { turn } , currentPlayer ) ) . toBe ( turn * 100 ) ;
374+ expect ( bot . playoutDepth ( null , { turn } , currentPlayer ) ) . toBe ( turn * 10 ) ;
374375
375- // try the playout() function which requests the playoutDepth value
376- bot . playout ( { state } ) ;
376+ // try the playout() function which requests the playoutDepth value
377+ bot . playout ( { state } ) ;
377378
378- expect ( enumerateSpy ) . toHaveBeenCalledWith (
379- state . G ,
380- state . ctx ,
381- currentPlayer
382- ) ;
379+ expect ( enumerateSpy ) . toHaveBeenCalledWith (
380+ state . G ,
381+ state . ctx ,
382+ currentPlayer
383+ ) ;
383384
384- // then try the play() function which requests the iterations value
385- enumerateSpy . mockClear ( ) ;
385+ // then try the play() function which requests the iterations value
386+ enumerateSpy . mockClear ( ) ;
386387
387- bot . play ( state , currentPlayer ) ;
388+ bot . play ( state , currentPlayer ) ;
388389
389- expect ( enumerateSpy ) . toHaveBeenCalledWith (
390- state . G ,
391- state . ctx ,
392- currentPlayer
393- ) ;
390+ expect ( enumerateSpy ) . toHaveBeenCalledWith (
391+ state . G ,
392+ state . ctx ,
393+ currentPlayer
394+ ) ;
395+ } ) ;
394396 } ) ;
395397} ) ;
0 commit comments