From 571164a50d4bf7cb6771e9a34dd13550cb8b6019 Mon Sep 17 00:00:00 2001 From: zepumph Date: Fri, 22 Jan 2021 10:36:28 -0900 Subject: [PATCH] create dotRandom and use instead of phet.joist.random, https://github.com/phetsims/joist/issues/685 --- js/linegame/model/BaseChallengeFactory.js | 9 +++++---- js/linegame/model/BaseGameModel.js | 3 ++- js/linegame/model/ValuePool.js | 3 ++- js/linegame/view/GLRewardNode.js | 7 ++++--- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/js/linegame/model/BaseChallengeFactory.js b/js/linegame/model/BaseChallengeFactory.js index 073cddc3..058bb07c 100644 --- a/js/linegame/model/BaseChallengeFactory.js +++ b/js/linegame/model/BaseChallengeFactory.js @@ -6,6 +6,7 @@ * @author Chris Malley (PixelZoom, Inc.) */ +import dotRandom from '../../../../dot/js/dotRandom.js'; import Utils from '../../../../dot/js/Utils.js'; import Vector2 from '../../../../dot/js/Vector2.js'; import merge from '../../../../phet-core/js/merge.js'; @@ -85,13 +86,13 @@ class BaseChallengeFactory { // x const minX = ( run >= 0 ) ? graphXRange.min : graphXRange.min - run; const maxX = ( run >= 0 ) ? graphXRange.max - run : graphXRange.max; - const x = Utils.roundSymmetric( minX + ( phet.joist.random.nextDouble() * ( maxX - minX ) ) ); + const x = Utils.roundSymmetric( minX + ( dotRandom.nextDouble() * ( maxX - minX ) ) ); assert && assert( x >= minX && x <= maxX, 'x out of range: ' + x ); // y const minY = ( rise >= 0 ) ? graphYRange.min : graphYRange.min - rise; const maxY = ( rise >= 0 ) ? graphYRange.max - rise : graphYRange.max; - const y = Utils.roundSymmetric( minY + ( phet.joist.random.nextDouble() * ( maxY - minY ) ) ); + const y = Utils.roundSymmetric( minY + ( dotRandom.nextDouble() * ( maxY - minY ) ) ); assert && assert( y >= minY && y <= maxY, 'y out of range: ' + y ); return new Vector2( x, y ); @@ -116,13 +117,13 @@ class BaseChallengeFactory { // x1 coordinates const minX1 = ( run >= 0 ) ? graphXRange.max - run + 1 : graphXRange.min; const maxX1 = ( run >= 0 ) ? graphXRange.max : graphXRange.min - run - 1; - const x1 = Utils.roundSymmetric( minX1 + ( phet.joist.random.nextDouble() * ( maxX1 - minX1 ) ) ); + const x1 = Utils.roundSymmetric( minX1 + ( dotRandom.nextDouble() * ( maxX1 - minX1 ) ) ); assert && assert( x1 >= minX1 && x1 <= maxX1, 'x1 out of range: ' + x1 ); // y1 coordinates const minY1 = ( rise >= 0 ) ? graphYRange.max - rise + 1 : graphYRange.min; const maxY1 = ( rise >= 0 ) ? graphYRange.max : graphYRange.min - rise - 1; - const y1 = Utils.roundSymmetric( minY1 + ( phet.joist.random.nextDouble() * ( maxY1 - minY1 ) ) ); + const y1 = Utils.roundSymmetric( minY1 + ( dotRandom.nextDouble() * ( maxY1 - minY1 ) ) ); assert && assert( y1 >= minY1 && y1 <= maxY1, 'y1 out of range: ' + y1 ); // compute (x2,y2) for validation diff --git a/js/linegame/model/BaseGameModel.js b/js/linegame/model/BaseGameModel.js index f6824fc3..192d2f9f 100644 --- a/js/linegame/model/BaseGameModel.js +++ b/js/linegame/model/BaseGameModel.js @@ -15,6 +15,7 @@ import BooleanProperty from '../../../../axon/js/BooleanProperty.js'; import EnumerationProperty from '../../../../axon/js/EnumerationProperty.js'; import NumberProperty from '../../../../axon/js/NumberProperty.js'; import Property from '../../../../axon/js/Property.js'; +import dotRandom from '../../../../dot/js/dotRandom.js'; import GameTimer from '../../../../vegas/js/GameTimer.js'; import GLConstants from '../../common/GLConstants.js'; import GLQueryParameters from '../../common/GLQueryParameters.js'; @@ -256,7 +257,7 @@ class BaseGameModel { // generate challenges this.challenges = this.challengeFactories[ level ].createChallenges(); if ( GLQueryParameters.shuffle ) { - this.challenges = phet.joist.random.shuffle( this.challenges ); + this.challenges = dotRandom.shuffle( this.challenges ); } // set the number of challenges diff --git a/js/linegame/model/ValuePool.js b/js/linegame/model/ValuePool.js index 1bf723eb..c303d601 100644 --- a/js/linegame/model/ValuePool.js +++ b/js/linegame/model/ValuePool.js @@ -8,6 +8,7 @@ * @author Chris Malley (PixelZoom, Inc.) */ +import dotRandom from '../../../../dot/js/dotRandom.js'; import merge from '../../../../phet-core/js/merge.js'; import graphingLines from '../../graphingLines.js'; @@ -67,7 +68,7 @@ class ValuePool { */ static choose( array ) { assert && assert( array && array.length > 0, 'array is empty' ); - const index = phet.joist.random.nextIntBetween( 0, array.length - 1 ); + const index = dotRandom.nextIntBetween( 0, array.length - 1 ); assert && assert( index !== -1 ); const item = array[ index ]; array.splice( index, 1 ); diff --git a/js/linegame/view/GLRewardNode.js b/js/linegame/view/GLRewardNode.js index 6eb2cbaa..cd042efd 100644 --- a/js/linegame/view/GLRewardNode.js +++ b/js/linegame/view/GLRewardNode.js @@ -18,6 +18,7 @@ */ import Property from '../../../../axon/js/Property.js'; +import dotRandom from '../../../../dot/js/dotRandom.js'; import Utils from '../../../../dot/js/Utils.js'; import StringUtils from '../../../../phetcommon/js/util/StringUtils.js'; import FaceNode from '../../../../scenery-phet/js/FaceNode.js'; @@ -137,7 +138,7 @@ function getRandomY() { } function getRandomNonZeroInteger( min, max ) { - let i = Utils.roundSymmetric( min + ( phet.joist.random.nextDouble() * ( max - min ) ) ); + let i = Utils.roundSymmetric( min + ( dotRandom.nextDouble() * ( max - min ) ) ); if ( i === 0 ) { i = 1; } return i; } @@ -150,7 +151,7 @@ function getRandomNonZeroInteger( min, max ) { // Creates a random equation with the specified color. function createEquationNode( color ) { let node; - if ( phet.joist.random.nextDouble() < 0.5 ) { + if ( dotRandom.nextDouble() < 0.5 ) { node = SlopeInterceptEquationNode.createDynamicLabel( new Property( Line.createSlopeIntercept( getRandomY(), getRandomX(), getRandomY(), color ) ), { fontSize: EQUATION_FONT_SIZE @@ -168,7 +169,7 @@ function createEquationNode( color ) { // Creates a random graph with the specified color. function createGraphNode( color ) { let node; - if ( phet.joist.random.nextDouble() < 0.5 ) { + if ( dotRandom.nextDouble() < 0.5 ) { node = GLIconFactory.createGraphIcon( GRAPH_WIDTH, color, -3, -3, 3, 3 ); // y = +x } else {