Skip to content

This is a library for creating tournament schedules for the sport I love.

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE_APACHE
MIT
LICENSE_MIT
Notifications You must be signed in to change notification settings

Flocksserver/social_tournament

Repository files navigation

crates.io Documentation Workflow License License: MIT

Social Tournament

This is a library for creating tournament schedules for the sport I love.

🏓 table tennis 🏓

The focus is on meeting as many opponents and teammates as possible during the tournament. One can draw a single or double tournament.

Example

Single

Get rounds for a single tournament (round robin)

use social_tournament::{Round, SocialTournament, TournamentConfig, TableConfig};

let mut tournament = SocialTournament::new(TournamentConfig::Single {
    number_of_players: 12,
    number_of_rounds: 2,
    table_config: TableConfig { available_tables: 10, distribution_option: None }
});

tournament.draw().unwrap();
let rounds: Vec<Round> = tournament.rounds.unwrap();
/*
Creates:
Round number: 0
SingleMatch { a: 0, b: 9 }
SingleMatch { a: 1, b: 8 }
SingleMatch { a: 2, b: 7 }
SingleMatch { a: 3, b: 6 }
SingleMatch { a: 4, b: 5 }
--------------
Round number: 1
SingleMatch { a: 1, b: 9 }
SingleMatch { a: 2, b: 0 }
SingleMatch { a: 3, b: 8 }
SingleMatch { a: 4, b: 7 }
SingleMatch { a: 5, b: 6 }
--------------
...
*/

Double

If you want to get rounds for a double tournament you have to do the following:

use social_tournament::{Round, SocialTournament, TournamentConfig, TableConfig};

let mut tournament = SocialTournament::new(TournamentConfig::Double {
    number_of_players: 24,
    number_of_rounds: 2,
    draw_option: None,
    table_config: TableConfig { available_tables: 10, distribution_option: None }
});

tournament.draw().unwrap();
let rounds: Vec<Round> = tournament.rounds.unwrap();
/*
Creates:
Round number: 0
DoubleMatch { double_a: (2, 37), double_b: (1, 38) }
DoubleMatch { double_a: (3, 36), double_b: (4, 35) }
DoubleMatch { double_a: (5, 34), double_b: (6, 33) }
DoubleMatch { double_a: (7, 32), double_b: (8, 31) }
DoubleMatch { double_a: (9, 30), double_b: (10, 29) }
DoubleMatch { double_a: (11, 28), double_b: (12, 27) }
DoubleMatch { double_a: (13, 26), double_b: (14, 25) }
DoubleMatch { double_a: (15, 24), double_b: (16, 23) }
DoubleMatch { double_a: (17, 22), double_b: (18, 21) }
--------------
Round number: 1
DoubleMatch { double_a: (20, 21), double_b: (2, 0) }
DoubleMatch { double_a: (3, 38), double_b: (7, 34) }
DoubleMatch { double_a: (4, 37), double_b: (6, 35) }
DoubleMatch { double_a: (5, 36), double_b: (9, 32) }
DoubleMatch { double_a: (8, 33), double_b: (10, 31) }
DoubleMatch { double_a: (11, 30), double_b: (15, 26) }
DoubleMatch { double_a: (12, 29), double_b: (14, 27) }
DoubleMatch { double_a: (13, 28), double_b: (17, 24) }
DoubleMatch { double_a: (16, 25), double_b: (18, 23) }
--------------
...
*/

Double Options

For number of players that are not completely divisible by 4 you can choose between three DrawOption. Depending on the selected option you can have doubles with only 3 players, single matches or player with byes. You have to make sure that the player ids >= number_of_players in the schedule post processed correctly. So that you can mark them as byes for example.

Table distribution

Tournament matches take place on tables in a room or gym. If the tournament is drawn, you can distribute the matches in each round to available tables. Specify how many tables you can provide for the tournament in your room or gym. The algorithm ensures that enough sub-rounds are formed. You can specify the forming method by providing the DistributionOption. Depending on the option you choose, can have as many matches as possible in a sub-round or mainly even matches in each sub-round.

use social_tournament::{Round, SocialTournament, TournamentConfig, TableConfig};
use social_tournament::table::Table;

let mut tournament = SocialTournament::new(TournamentConfig::Double {
    number_of_players: 24,
    number_of_rounds: 2,
    draw_option: None,
    table_config: TableConfig { available_tables: 10, distribution_option: None }
});

tournament.draw().unwrap();
tournament.distribute().unwrap();

let tables: Vec<Vec<Table>> = tournament.tables.unwrap();
/*
Creates:
Table { table_number: 0, occupied_number: 0 }
Table { table_number: 1, occupied_number: 0 }
Table { table_number: 2, occupied_number: 0 }
Table { table_number: 3, occupied_number: 0 }
Table { table_number: 0, occupied_number: 1 }
Table { table_number: 1, occupied_number: 1 }
--------------
Table { table_number: 0, occupied_number: 0 }
Table { table_number: 1, occupied_number: 0 }
Table { table_number: 2, occupied_number: 0 }
Table { table_number: 3, occupied_number: 0 }
Table { table_number: 0, occupied_number: 1 }
Table { table_number: 1, occupied_number: 1 }
--------------
*/

PDF creation

Currently, there is only the possibility for double tournaments to generate route cards as pdf. In the future will follow singles and referee sheet generation. Available languages are English and German.

use social_tournament::{Round, SocialTournament, TournamentConfig, TableConfig};
use social_tournament::table::Table;
use social_tournament::pdf::language::Language;

let mut tournament = SocialTournament::new(TournamentConfig::Double {
    number_of_players: 24,
    number_of_rounds: 2,
    draw_option: None,
    table_config: TableConfig { available_tables: 10, distribution_option: None }
});

tournament.draw().unwrap();
tournament.distribute().unwrap();
tournament.create_route_cards_pdf(Language::EN).unwrap();

let pdf: Vec<u8> = tournament.pdf.unwrap();

A sample pdf looks like this.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

About

This is a library for creating tournament schedules for the sport I love.

Topics

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE_APACHE
MIT
LICENSE_MIT

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages