用于控制项目产卵中可能性空间的算法

发布于 2025-02-10 03:21:39 字数 452 浏览 4 评论 0原文

我很难找到以下问题的好解决方案(和一个好的标题):

说我有一个球体的蓝图。这个sphere-blueprint包含一系列独特的颜色。产卵后,每个球体都会呈现其颜色阵列的随机颜色。

现在,我有了一个产卵器,其中包含一个说可能产生的100个不同的斜纹刺激性列表。这些都可以具有不同的颜色阵列。现在,产卵器试图从该列表中产生10个领域。

在产生了现在的时间,Spheres可以采用其颜色。但是,没有一个球体在另一个球体之前扮演的颜色!第一个球从其颜色阵列中呈现随机颜色。随后的每个球体都可以看到先前的球体所采用的颜色,并能够选择任何以前的球体都没有选择的颜色。

我如何确保我不产生一个不再有颜色选择的球体,因为其他领域已经采取了颜色阵列中的所有颜色?

我试图使用上面有数字的粘稠笔记来原型,但这肯定不是一个琐碎的问题

I have trouble finding a good solution (and a good title) to the following problem:

Say I have a blueprint of a sphere. This sphere-blueprint contains an array of unique colors. Each sphere will take on a random color of its color array after spawning.

Now I have a Spawner, which holds a list of say 100 different sphere-blueprints it could spawn. Each of these can have differing color arrays. The Spawner now tries to spawn 10 spheres from that list.

After spawning its now time for the spheres to take on their colors. However, no sphere can take on a color another sphere has taken on before! The first sphere takes on a random color from its color array. Each subsequent sphere is are able to see the color previous spheres have taken on and are able to chose a color that hasn't been chosen by any previous sphere.

How can I make sure that I don't spawn a sphere, which could be left with no more color-choices, because all colors within its color-array have been already taken by other spheres?

I tried to prototype this using sticky notes with numbers on them, but it sure is not a trivial problem

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

弃爱 2025-02-17 03:21:39

每个唯一的“蓝图”都需要包含以下...

  • colorArray-将其放置在上面,因此它已经是随机的
  • colorPickerIndex- 0

创建了“ 100个蓝图”列表,您需要将所有唯一的唯一唯一的列表组合在一起。颜色变成全球冠状器。

每个“蓝图”的“ spawn”(实例)都需要包含以下...

  • 索引 - 进入“ 100个蓝图”颜色的列表中
  • - 所选唯一的颜色

示例Spawn BluePrint方法...。

// list of  "100 blueprints"
var blueprints = ...
// set of all unique colors in all of the "blueprints" 
var globalColorsHashSet = ...
// list of "spawn" instances
var spawned = [];

// spawn a blueprint or throw an error
function spawnBlueprint(blueprintIndex) {
  // get the requested blueprint
  var bp = blueprints[blueprintIndex];
  // attempt to spawn the blueprint
  while(true) {
    // blueprint has exhausted its colors so throw an error
    if(bp.colorPickerIndex >= bp.colorArray.length) {
      throw "No Colors Left for this blueprint.";
    }
    // store possible spawn color
    var color = bp.colorArray[colorPickerIndex];
    // increment the color picker index
    bp.colorPickerIndex++;
    // if the color hasn't been used yet, then spawn an instance
    if(globalColorHashSet.has(color)) {
      // remove the color from the global list
      globalColorHashSet.delete(color);
      // create the instance
      var spawn = new Spawn(blueprintIndex, color);
      // save the spawn instance
      spawned.push(spawn);
      // return the spawn instance
      return spawn;
    }
    // loop - try the next color
  }
}

Each of your unique "blueprint" needs to contain the following...

  • ColorArray - pre shuffle it so it's already random
  • ColorPickerIndex - 0 to size of Color Array

Once your list of "100 blueprints" is created you need to combine all of the unique colors into a GlobalColorHashSet.

Each "spawn" (instance) of a "blueprint" needs to contain the following...

  • Index - into the list of "100 blueprints"
  • Color - the chosen unique color

Example spawn blueprint method....

// list of  "100 blueprints"
var blueprints = ...
// set of all unique colors in all of the "blueprints" 
var globalColorsHashSet = ...
// list of "spawn" instances
var spawned = [];

// spawn a blueprint or throw an error
function spawnBlueprint(blueprintIndex) {
  // get the requested blueprint
  var bp = blueprints[blueprintIndex];
  // attempt to spawn the blueprint
  while(true) {
    // blueprint has exhausted its colors so throw an error
    if(bp.colorPickerIndex >= bp.colorArray.length) {
      throw "No Colors Left for this blueprint.";
    }
    // store possible spawn color
    var color = bp.colorArray[colorPickerIndex];
    // increment the color picker index
    bp.colorPickerIndex++;
    // if the color hasn't been used yet, then spawn an instance
    if(globalColorHashSet.has(color)) {
      // remove the color from the global list
      globalColorHashSet.delete(color);
      // create the instance
      var spawn = new Spawn(blueprintIndex, color);
      // save the spawn instance
      spawned.push(spawn);
      // return the spawn instance
      return spawn;
    }
    // loop - try the next color
  }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文