Skip to content

Instantly share code, notes, and snippets.

@capsulecorplab
Last active August 23, 2019 15:19
Show Gist options
  • Save capsulecorplab/fca80881301c0d42bd8221c7c328d430 to your computer and use it in GitHub Desktop.
Save capsulecorplab/fca80881301c0d42bd8221c7c328d430 to your computer and use it in GitHub Desktop.
a python script for randomly dividing up players into teams
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
.pytest_cache/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
db.sqlite3
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
target/
# Jupyter Notebook
*.ipynb
.ipynb_checkpoints
# pyenv
.python-version
# celery beat schedule file
celerybeat-schedule
# SageMath parsed files
*.sage.py
# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# mypy
.mypy_cache/
# vscode
.vscode/

GameNight

a python script for randomly dividing up players into teams

Pre-requisites

  • python3

Installation & Setup

Note: It is recommended you run the following in a virtual environment.

Clone the project:

git clone https://gist.github.com/fca80881301c0d42bd8221c7c328d430.git gamenight
cd gamenight

Install requirements:

pip3 install -r requirements.txt

CLI Usage

Modify config.yaml, such that all participating players are listed under players as list elements. Likewise, team names, and their respective team sizes, should be listed under teams as key-value pairs.

Note: players and/or team names can be (un)commented out as needed.

Once config.yaml has been configured, run the following in terminal:

python3 gamenight.py

LICENSE

Use of this software is granted under the terms of the MIT License.

See the LICENSE for the full license text.

players:
# list of all players to be randomly placed into teams
- eli
- roxana
- josh
- sean
- juan
- jay
- liz
- christy
# - tim
teams:
# key-value pairs of team names and their respective team sizes
Mystic: 5
Valor: 2
Instinct: 1
#!/usr/bin/env python3
from random import seed, shuffle
from yaml import dump, unsafe_load
seed()
def generate_teams(filename: str = "config.yaml") -> dict:
with open(filename, "r") as f:
config = dict(unsafe_load(f.read()))
players = config["players"]
shuffle(players)
teams = config["teams"]
buffer = dict()
for team in list(teams.keys()):
buffer[team] = list()
while True:
try:
buffer[team].append(players.pop())
if len(buffer[team]) >= teams[team]:
break
except:
pass
return buffer
if __name__ == "__main__":
print(dump(generate_teams(), default_flow_style=False))
MIT License
Copyright (c) 2019 gamenight.py
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment