Giter Club home page Giter Club logo

fair-play-app's Introduction

TeamBalancer

TeamBalancer is a Fair Team Distribution App developed using JavaScript that aims to create two equally balanced teams based on the skill levels of players. The app allows users to input player names and their corresponding skill levels, and then employs an algorithm to distribute the players into two teams.

View Live Demo

Table of Contents

Algorithm

The app follows a two-step process to achieve fair team distribution. First, it ensures that both teams have an equal number of players. This helps maintain a balanced playing field by preventing one team from having a numerical advantage over the other. Once the teams have an equal number of players, the app distributes the players based on their skill levels to ensure fairness in terms of skill distribution.

The recursive algorithm used in the app follows these steps:

function balanceTeamsBySkillLevel(arr1, arr2) {
    let diff = Math.abs(
        arr1.reduce((a, b) => a + b.skillLevel, 0) -
        arr2.reduce((a, b) => a + b.skillLevel, 0)
    );

    for (let i = 0; i < arr1.length; i++) {
        for (let j = 0; j < arr2.length; j++) {
            let newDiff = Math.abs(
                arr1.reduce((a, b) => a + b.skillLevel, 0) - arr1[i].skillLevel + arr2[j].skillLevel -
                (arr2.reduce((a, b) => a + b.skillLevel, 0) - arr2[j].skillLevel + arr1[i].skillLevel)
            );
            if (newDiff < diff) {
                let temp1 = arr1[i];
                let temp2 = arr2[j];
                arr1[i] = temp2;
                arr2[j] = temp1;
                return balanceTeamsBySkillLevel(arr1, arr2);
            }
        }
    }
    return [arr1, arr2];
}
  1. First, it calculates the initial difference between the total skill levels of the two teams.
  2. Next, it iterates over each player in Team 1.
  3. For each player in Team 1, it further iterates over each player in Team 2.
  4. At each iteration, it calculates the new difference in skill levels if the players were to be swapped between the teams.
  5. If the new difference is found to be smaller than the initial difference, it performs the swap between the two players.
  6. After the swap, the function recursively calls itself with the updated teams.
  7. Steps 2-6 are repeated until no further improvement can be achieved.
  8. Finally, the function returns the balanced teams.

This recursive algorithm aims to find an optimal distribution of players between the two teams by iteratively swapping players to minimize the difference in skill levels. By recursively exploring all possible player swaps, it strives to achieve a fair balance between the teams based on their skill levels.

By providing a user-friendly interface with input fields for player names and skill levels, along with a distribution algorithm that prioritizes fairness, the TeamBalancer simplifies the process of creating balanced teams for various team-based activities, such as sports events, gaming competitions, or group projects.

Installation

To install the TeamBalancer, follow these instructions:

  1. Download the project files: Obtain the project files from the source, either by downloading the zip file from a repository or cloning the project using Git.

  2. Set up the project structure: Extract the downloaded zip file (if applicable) and navigate to the project folder.

  3. Open the project in a code editor: Use a code editor of your choice (e.g., Visual Studio Code, Atom, Sublime Text) to open the project folder.

  4. Set up a local development server (optional): If you want to run the app on a local development server, ensure you have a server environment set up. You can use tools like Node.js or Python's SimpleHTTPServer to serve the app locally. Alternatively, you can directly open the HTML file in a web browser without a local server.

  5. Open the HTML file: Locate the HTML file (e.g., index.html) in the project folder and open it in a web browser or by launching the local development server.

  6. Interact with the app: Once the app is open in the browser, you'll see the interface with options to add player names and skill levels. Use the "Add Player" button to enter the details for each player. The app will display the selected skill level when you choose it from the dropdown menu. Continue adding players until you have included all the participants.

  7. Click the "Get Teams" button: After adding all the players, click the "Get Teams" button. The app will distribute the players into two teams, ensuring equal team sizes and fair skill distribution.

  8. View the team results: The app will display the two teams with their respective player names and skill levels. You can observe how the algorithm has distributed the players to create balanced teams.

Usage

Users can utilize the TeamBalancer by following these steps:

  1. Access the App: Open the TeamBalancer in a web browser by entering the URL or launching the local development server where the app is hosted.

  2. Add Player Details: On the app interface, users can see input fields for player names and select dropdowns for skill levels. They can click on the "Add Player" button to dynamically add more input fields for additional players.

Features

The TeamBalancer is designed to help users distribute players into two teams in a fair and balanced manner. It offers the following key features and functionalities:

  • Interactive Interface The app provides a user-friendly interface where users can easily input player details and interact with various elements.

  • Add Players Users can dynamically add players by clicking the "Add Player" button. This feature allows them to include any number of players for team distribution.

  • Select Skill Levels For each player, users can choose the skill level from a dropdown menu. The skill levels range from 1 to 10, allowing users to assign appropriate skill levels to the players.

Screenshots


Contributing

Thank you for your interest in contributing to the TeamBalancer! We welcome contributions from the community to help improve and enhance the functionality of the app. Your contributions will be greatly valued in improving the TeamBalancer.

Note: By contributing to the project, you agree to abide by the project's code of conduct.

License

The TeamBalancer is released under the MIT License.

Contact

Nury Amanmadov - @amanmadov - [email protected]

(back to top)

fair-play-app's People

Contributors

amanmadov avatar

Stargazers

 avatar

Watchers

 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.