Example #1
0
module.exports = function (opts) {
  opts = opts || {}
  var start = typeof opts.start === 'number' ?
    opts.start :
    0
  var end = typeof opts.end === 'number' ?
    opts.end :
    100
  var count = typeof opts.count === 'number' ?
    opts.count :
    1
  if (end <= start) {
    throw new Error('Expected end number to be bigger that start number')
  }
  var numbers = range(start, end)
  if (count > numbers.length) {
    throw new Error('You cannot get more than ' + numbers.length + ' numbers')
  }
  var result = []
  while (count--) {
    numbers = shuffle(numbers)
    result.push(numbers.pop())
  }
  return result
}
Example #2
0
Generators.drawPuzzles = (puzzleCodes, puzzleContainer) => {
	let generatedImages = [],
		i = 0,
		len = 0;

	// Prepare puzzle elements
	// Set src, draggable, index
	puzzleCodes.forEach((el, index) => {
		let singlePuzzle = document.createElement('img');

		singlePuzzle.src = el;
		singlePuzzle.setAttribute('draggable', true);
		singlePuzzle.dataset.index = index + 1;

		generatedImages.push(singlePuzzle);
	});

	// Randomize the puzzles
	generatedImages = shuffle(generatedImages);

	// Draw images on screen
	generatedImages.forEach((el) => {
		puzzleContainer.appendChild(el);
	});
};
Example #3
0
 getMixedCardSet (layers: Array<Object>, groups: Array<Object>, hubs: Array<Object>, maps: Array<Object>, stories: Array<Object>) {
   return _shuffle(layers.map(cardUtil.getLayerCard)
     .concat(groups.map(cardUtil.getGroupCard))
     .concat(hubs.map(cardUtil.getHubCard))
     .concat(maps.map(cardUtil.getMapCard))
     .concat(stories.map(cardUtil.getStoryCard))
   )
 }
Example #4
0
      handler: (request, reply) => {
        let antispam

        if (request.state.antispam && request.state.antispam.roshambo && request.state.antispam.roshambo.fakes) {
          antispam = request.state.antispam
        } else {
          let picks = shuffle(['roche', 'papier', 'ciseaux'])
          antispam = {
            roshambo: {
              toBeat: picks[0],
              picks: shuffle(picks),
              fakes: shuffle(picks)
            }
          }
        }

        reply.view(request.auth && request.auth.isAuthenticated ? 'logged' : 'register', { antispam }).state('antispam', antispam)
      }
Example #5
0
export default function dataReducer (state = initialState, action) {
  switch (action.type) {
    case RESTORE_HIGHSCORE_SUCCESS:
      return {
        ...state,
        highscore: +action.score
      }
    case SET_HIGHSCORE:
      return {
        ...state,
        highscore: action.score
      }
    case NEW_GAME:
      const newGrid = allchinese.substr(0, 16)
      const newChallenges = newGrid.split('').map(zi => {
        return { zi, clue: dict[zi] }
      })
      const randomClue =
        newChallenges[Math.floor(Math.random() * newChallenges.length)]

      return {
        ...state,
        score: 0,
        chinese: shuffle(newGrid),
        challenges: newChallenges,
        zi: randomClue.zi,
        clue: randomClue.clue,
        timeOfLastInteraction: new Date()
      }
    case TOUCH_CORRECT_GLYPH:
      e = Math.max(1, (new Date() - state.timeOfLastInteraction) / 1000)
      return {
        ...state,
        score: state.score + Math.max(1, Math.floor(10 / Math.floor(e))),
        timeOfLastInteraction: new Date()
      }
    case TOUCH_INCORRECT_GLYPH:
      return {
        ...state,
        score: Math.max(0,state.score - 10),
        timeOfLastInteraction: new Date()
      }
    case NEXT_CLUE:
    const current = state.zi
    const filteredArray = state.challenges.filter(x=>x.zi!==current)
      const n =
        filteredArray[Math.floor(Math.random() * filteredArray.length)]
      return {
        ...state,
        zi: n.zi,
        clue: n.clue
      }
    default:
      return state
  }
}
Example #6
0
module.exports = (brokers, globalOptions, exchange, message, opts, _cb) => {
  debug('publish', exchange, message, opts);
  const cb = once(_cb);
  const options = defaults({
    brokers: shuffle(brokers),
    brokerIndex: 0,
  }, opts, globalOptions);
  options.expiresAt = Date.now() + options.timeout;
  publish(exchange, message, options, cb);
};
Example #7
0
    students: function (req, res) {

        return res.render("students", {
            debugMode: debugMode,
            year: (new Date()).getUTCFullYear(),
            title: "Students",
            view: "page-students",
            entries: shuffle(entries)
        });

    },
Example #8
0
    it('allows the user to randomize the output order', function() {
      var shuffle = sinon.stub(_, 'shuffle');
      shuffle.onFirstCall().returns([out2, out1, out4, out3]);

      transaction._changeIndex.should.equal(3);
      transaction.shuffleOutputs();
      transaction.outputs[0].should.equal(out2);
      transaction.outputs[1].should.equal(out1);
      transaction.outputs[2].should.equal(out4);
      transaction.outputs[3].should.equal(out3);
      transaction._changeIndex.should.equal(2);

      _.shuffle.restore();
    });
Example #9
0
/**
 * ## sortTree
 * Sorts all nodes by operation priority.
 *
 * @param {Node} localRoot - current entry point for recursive traversal
 * @param {string} operation - operation for which the quorum shall be assembled, either 'read' or 'write'
 */
function sortTree ( localRoot, operation ) {
    var sortField = operation + 'Priority';
    //first shuffle
    localRoot.childrenEdges = shuffle( localRoot.childrenEdges );
    //then sort, to implement a completely unstable sorting
    localRoot.childrenEdges = localRoot.childrenEdges.sort( function ( e1, e2 ) {
        //ascending sorting of the children
        return e1[sortField] - e2[sortField];
    } );
    if ( localRoot.type === 'virtual' ) {
        var child;
        for ( var i = 0; i < localRoot.childrenEdges.length; i++ ) {
            child = localRoot.childrenEdges[i].target;
            sortTree( child, operation );
        }
    }
}
Example #10
0
        it('should return a random powerUp constructor', function () {
            var called = 0;
            sinon.stub(_, 'shuffle', function () {
                var powerUps = [
                    InvinciblePowerUp,
                    FoodPointMultiplierPowerUp
                ];
                if (called) {
                    powerUps.reverse();
                }
                called++;
                return powerUps;
            });
            game.getRandomPowerUpConstructor().should.eql(InvinciblePowerUp);
            game.getRandomPowerUpConstructor().should.eql(FoodPointMultiplierPowerUp);

            _.shuffle.restore();
        });
Example #11
0
  constructor (props: Props) {
    super(props)
    Reflux.rehydrate(LocaleStore, {locale: props.locale, _csrf: props._csrf})
    if (props.user) {
      Reflux.rehydrate(UserStore, {user: props.user})
    }

    let baseMapContainerInit = {}
    if (props.mapConfig && props.mapConfig.baseMapOptions) {
      baseMapContainerInit = {baseMapOptions: props.mapConfig.baseMapOptions}
    }
    this.BaseMapState = new BaseMapContainer(baseMapContainerInit)

    this.state = {
      featuredLayersCards: _shuffle(props.featuredLayers.map(cardUtil.getLayerCard)),
      featuredGroupsCards: _shuffle(props.featuredGroups.map(cardUtil.getGroupCard)),
      featuredHubsCards: _shuffle(props.featuredHubs.map(cardUtil.getHubCard)),
      featuredMapsCards: _shuffle(props.featuredMaps.map(cardUtil.getMapCard)),
      featuredStoriesCards: _shuffle(props.featuredStories.map(cardUtil.getStoryCard)),
      popularLayersCards: _shuffle(props.popularLayers.map(cardUtil.getLayerCard)),
      popularGroupsCards: _shuffle(props.popularGroups.map(cardUtil.getGroupCard)),
      popularHubsCards: _shuffle(props.popularHubs.map(cardUtil.getHubCard)),
      popularMapsCards: _shuffle(props.popularMaps.map(cardUtil.getMapCard)),
      popularStoriesCards: _shuffle(props.popularStories.map(cardUtil.getStoryCard)),
      recentLayersCards: _shuffle(props.recentLayers.map(cardUtil.getLayerCard)),
      recentGroupsCards: _shuffle(props.recentGroups.map(cardUtil.getGroupCard)),
      recentHubsCards: _shuffle(props.recentHubs.map(cardUtil.getHubCard)),
      recentMapsCards: _shuffle(props.recentMaps.map(cardUtil.getMapCard)),
      recentStoriesCards: _shuffle(props.recentStories.map(cardUtil.getStoryCard)),
      loaded: false
    }
  }
Example #12
0
  constructor (props: Props) {
    super(props)
    Reflux.rehydrate(LocaleStore, {locale: props.locale, _csrf: props._csrf})
    if (props.user) {
      Reflux.rehydrate(UserStore, {user: props.user})
    }
    this.state = {
      storyMode: MAPHUBS_CONFIG.mapHubsPro ? 'popular' : 'featured',
      mapMode: MAPHUBS_CONFIG.mapHubsPro ? 'popular' : 'featured',
      hubMode: MAPHUBS_CONFIG.mapHubsPro ? 'popular' : 'featured',
      groupMode: MAPHUBS_CONFIG.mapHubsPro ? 'popular' : 'featured',
      layerMode: MAPHUBS_CONFIG.mapHubsPro ? 'popular' : 'featured',

      featuredStoryCards: _shuffle(props.featuredStories.map(cardUtil.getStoryCard)),
      popularStoryCards: _shuffle(props.popularStories.map(cardUtil.getStoryCard)),
      recentStoryCards: _shuffle(props.recentStories.map(cardUtil.getStoryCard)),

      featuredMapCards: _shuffle(props.featuredMaps.map(cardUtil.getMapCard)),
      popularMapCards: _shuffle(props.popularMaps.map(cardUtil.getMapCard)),
      recentMapCards: _shuffle(props.recentMaps.map(cardUtil.getMapCard)),

      featuredHubCards: _shuffle(props.featuredHubs.map(cardUtil.getHubCard)),
      popularHubCards: _shuffle(props.popularHubs.map(cardUtil.getHubCard)),
      recentHubCards: _shuffle(props.recentHubs.map(cardUtil.getHubCard)),

      featuredGroupCards: _shuffle(props.featuredGroups.map(cardUtil.getGroupCard)),
      popularGroupCards: _shuffle(props.popularGroups.map(cardUtil.getGroupCard)),
      recentGroupCards: _shuffle(props.recentGroups.map(cardUtil.getGroupCard)),

      featuredLayerCards: _shuffle(props.featuredLayers.map(cardUtil.getLayerCard)),
      popularLayerCards: _shuffle(props.popularLayers.map(cardUtil.getLayerCard)),
      recentLayerCards: _shuffle(props.recentLayers.map(cardUtil.getLayerCard))
    }
  }
Example #13
0
	shuffle() {
		this.images = shuffle(this.images);
	}
Example #14
0
'use strict'

const shuffle = require('lodash.shuffle')

const COLORS = ['green', 'yellow', 'blue', 'magenta', 'cyan', 'red']

module.exports = {
    getAt(i) {
        return COLORS[i % (COLORS.length - 1)]
    },
    getRandom(last) {
        return shuffle(COLORS.filter(c => c !== last))[0]
    }
}
Example #15
0
			setTimeout(() => {
				this.image = shuffle(this.images);
			}, 100);
Example #16
0
 this.getPlaces(parameters, function(results) {
     num = Math.min(results.length,num);
     results = shuffle(results);
     results = results.splice(0,num);
     res.send(JSON.stringify(results));  
 });
Example #17
0
import {
  NEW_GAME,
  TOUCH_CORRECT_GLYPH,
  NEXT_CLUE,
  TOUCH_INCORRECT_GLYPH,
  SET_HIGHSCORE,
  RESTORE_HIGHSCORE_SUCCESS
} from '../constants'
import shuffle from 'lodash.shuffle'
import dict from '../../challenges'
const allchinese = shuffle(Object.keys(dict)).join('')
const grid = allchinese.substr(0, 16)
const initialChallenges = grid.split('').map(zi => {
  return { zi, clue: dict[zi] }
})
const initialClue =
  initialChallenges[Math.floor(Math.random() * initialChallenges.length)]

const initialState = {
  error: false,
  label: '',
  clue: initialClue.clue,
  zi: initialClue.zi,
  challenges: initialChallenges,
  correctAnswer: false,
  correctAnswers: '',
  score: 0,
  highscore: 0,
  chinese: shuffle(grid),
  timeOfLastInteraction: new Date(),
  gameStart: new Date()