Giter VIP home page Giter VIP logo

autogroup's Introduction

按实力平均分组,可分多组。分组后,每组的实力尽量接近,每组的人数也尽量接近。

示例:

选手数据

var players = [
    {
        "player": "a",
        "score": 22
    },
    {
        "player": "b",
        "score": -9
    },
    {
        "player": "c",
        "score": 13
    },
    {
        "player": "d",
        "score": 17
    },
    {
        "player": "e",
        "score": 0
    },
    {
        "player": "f",
        "score": -11
    },
    {
        "player": "g",
        "score": -2
    }
];

总共7人,分成两组3v4:

new AutoGroup(players, 2).divide();

分组结果:

[
  [
    {
      "player": "a",
      "score": 22,
      "value": 33
    },
    {
      "player": "e",
      "score": 0,
      "value": 11
    },
    {
      "player": "g",
      "score": -2,
      "value": 9
    },
    {
      "player": "f",
      "score": -11,
      "value": 0
    }
  ],
  [
    {
      "player": "d",
      "score": 17,
      "value": 28
    },
    {
      "player": "c",
      "score": 13,
      "value": 24
    },
    {
      "player": "b",
      "score": -9,
      "value": 2
    }
  ]
]

第一组4个人,实力53;第二组3个人,实力54。

分成三组3v2v2:

new AutoGroup(players, 3).divide();

分组结果:

[
  [
    {
      "player": "a",
      "score": 22,
      "value": 33
    },
    {
      "player": "b",
      "score": -9,
      "value": 2
    },
    {
      "player": "f",
      "score": -11,
      "value": 0
    }
  ],
  [
    {
      "player": "c",
      "score": 13,
      "value": 24
    },
    {
      "player": "e",
      "score": 0,
      "value": 11
    }
  ],
  [
    {
      "player": "d",
      "score": 17,
      "value": 28
    },
    {
      "player": "g",
      "score": -2,
      "value": 9
    }
  ]
]

第一组3个人,实力35;第二组2个人,实力35;第三组2个人,实力37。

autogroup's People

Contributors

iammapping avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.