• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript random-js.bool函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中random-js.bool函数的典型用法代码示例。如果您正苦于以下问题:TypeScript bool函数的具体用法?TypeScript bool怎么用?TypeScript bool使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了bool函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: mutateNode

function mutateNode(keys: string[], random: Random, entity: Entity): Entity {
  const willMutate = random.bool(MUTATE_PERCENTAGE);

  if (!willMutate) {
    return entity;
  }

  const mutationId = random.integer(MIN_SEED, MAX_SEED);
  const mutation = chooseMutation(keys, mutationId, entity);

  return applyMutation(entity, mutation);
}
开发者ID:helix-pi,项目名称:helix-pi,代码行数:12,代码来源:index.ts


示例2: percent

 percent(p: number) {
     return randomjs.bool(p)(this.engine);
 }
开发者ID:sbj42,项目名称:sbj42.github.io,代码行数:3,代码来源:random.ts


示例3: bool

export function bool(numerator?: number, denominator?: number): boolean {
    // any below because of bad TS definitions in the @types package.
    return Random.bool(numerator as any, denominator as any)(engine);
}
开发者ID:MPennanti,项目名称:HungryDragon,代码行数:4,代码来源:random.ts


示例4: generateEntity

export function generateEntity(
  seed: number,
  keys: string[],
  depth = 0
): Entity {
  const random = new Random(Random.engines.mt19937().seed(seed));

  const isLeaf = depth > 1 || random.bool();

  if (isLeaf) {
    const possibleCommands = [
      "move",
      "setVelocity",
      "multiplyVelocity",
      "noop"
    ];

    const command = random.pick(possibleCommands);

    if (command === "noop") {
      return {
        type: command,
        id: seed.toString()
      };
    }

    if (command === "move") {
      const direction = random.pick([
        "up",
        "right",
        "left",
        "down"
      ]) as Direction;
      const amount = random.integer(0, 20) / 10;

      return {
        type: command,
        id: seed.toString(),
        direction,
        amount
      };
    }

    if (command === "setVelocity") {
      let velocity;

      if (random.bool(0.5)) {
        // cardinal direction
        const scalar = random.integer(0, 20) / 20;

        velocity = random.pick([
          { x: 0, y: -scalar },
          { x: scalar, y: 0 },
          { x: -scalar, y: 0 },
          { x: 0, y: scalar }
        ]);
      } else {
        velocity = {
          x: random.integer(-20, 20) / 20,
          y: random.integer(-20, 20) / 20
        };
      }

      return {
        type: command,
        id: seed.toString(),
        velocity
      };
    }

    if (command === "multiplyVelocity") {
      const scalar = random.integer(-20, 20) / 20;

      return {
        type: command,
        id: seed.toString(),
        scalar
      };
    }

    throw new Error("Unimplemented command");
  } else {
    const possibleCommands = [
      "sequence",
      "inputConditional",
      "collisionConditional"
    ];

    if (depth === 0) {
      possibleCommands.push("onCreate");
    }
    // TODO - fix definitely typed definition
    const command = (random as any).pick(possibleCommands) as any;

    if (command === "collisionConditional") {
      return {
        type: command,
        id: seed.toString(),
        children: makeChildren(random, 1, keys, depth)
      };
//.........这里部分代码省略.........
开发者ID:helix-pi,项目名称:helix-pi,代码行数:101,代码来源:index.ts


示例5: chooseMutation

function chooseMutation(
  keys: string[],
  seed: number,
  entity: Entity
): Mutation {
  const random = new Random(Random.engines.mt19937().seed(seed));

  if (random.bool(0.5)) {
    return {
      id: seed.toString(),
      type: "ConvertToNoopMutation"
    };
  }

  if (entity.type === "sequence") {
    const types = [
      "NewEntityMutation",
      "RemovalMutation",
      "SwitchMutation",
      "ReplaceMutation"
    ];

    const mutationType = random.pick(types);

    if (mutationType === "NewEntityMutation") {
      const newEntity = generateEntity(
        random.integer(MIN_SEED, MAX_SEED),
        keys,
        0
      );

      return {
        id: seed.toString(),
        type: mutationType,
        newEntity,
        spliceIndex: random.integer(0, (entity as Branch).children.length)
      };
    }

    if (mutationType === "ReplaceMutation") {
      const newEntity = generateEntity(
        random.integer(MIN_SEED, MAX_SEED),
        keys,
        0
      );

      return {
        id: seed.toString(),
        type: mutationType,
        newEntity,
        spliceIndex: random.integer(0, (entity as Branch).children.length - 1)
      };
    }

    if (mutationType === "RemovalMutation") {
      return {
        id: seed.toString(),
        type: mutationType,
        removeIndex: random.integer(0, entity.children.length - 1)
      };
    }

    if (mutationType === "SwitchMutation") {
      return {
        id: seed.toString(),
        type: mutationType,
        fromIndex: random.integer(0, entity.children.length - 1),
        toIndex: random.integer(0, entity.children.length - 1)
      };
    }
  }

  if (entity.type === "onCreate") {
    const newEntity = generateEntity(
      random.integer(MIN_SEED, MAX_SEED),
      keys,
      0
    );

    return {
      id: seed.toString(),
      type: "ReplaceMutation",
      newEntity,
      spliceIndex: random.pick([0, 1])
    };
  }

  if (entity.type === "collisionConditional") {
    const newEntity = generateEntity(
      random.integer(MIN_SEED, MAX_SEED),
      keys,
      0
    );

    return {
      id: seed.toString(),
      type: "ReplaceMutation",
      newEntity,
      spliceIndex: random.pick([0, 1])
    };
//.........这里部分代码省略.........
开发者ID:helix-pi,项目名称:helix-pi,代码行数:101,代码来源:index.ts



注:本文中的random-js.bool函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript random-js.integer函数代码示例发布时间:2022-05-25
下一篇:
TypeScript pluck.pluck函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap