11 releases
0.5.2 | Aug 11, 2023 |
---|---|
0.5.1 | Oct 12, 2021 |
0.4.2 | Sep 30, 2021 |
0.3.2 | Sep 17, 2021 |
0.1.0 | Sep 9, 2021 |
#5 in #tournament
7MB
2K
SLoC
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
- Apache License, Version 2.0, (LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or https://opensource.org/licenses/MIT)
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.
Dependencies
~18MB
~144K SLoC