Skip to content

Commit 4063d00

Browse files
committed
Add number of wins as black swiss tie-break
1 parent c6678d6 commit 4063d00

File tree

3 files changed

+58
-3
lines changed

3 files changed

+58
-3
lines changed

docs/changelog.rst

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,39 @@ Output::
4646

4747
...
4848

49+
**3. Add number of wins with black swiss tie-break**
50+
51+
Tie breaks::
52+
53+
TB1 = Buchholz cut 1
54+
TB2 = Buchholz
55+
TB3 = Sonneborn-Berger
56+
TB4 = Direct Encounter
57+
TB5 = Most number of wins
58+
TB6 = Most number of wins with black
59+
60+
Output::
61+
62+
Rank Name Rating RChg R1 R2 R3 R4 R5 R6 R7 R8 R9 R10 R11 Games Score Score% TB1 TB2 TB3 TB4 TB5 TB6
63+
1 Firouzja, Alireza 2770 11.31 93W1 35B1 7W1 4B= 6W= 8B= 33W1 31W1 2B0 9W1 3B= 11 8.0 72.73 0.0 0.0 0.00 0.0 0 0
64+
2 Caruana, Fabiano 2800 1.06 55W1 18B= 36W= 35B= 9W1 33B= 13W= 24B1 1W1 6B= 7W= 11 7.5 68.18 67.0 72.5 49.75 0.0 4 1
65+
3 Oparin, Grigoriy 2654 21.62 62W= 78B1 17W= 70B= 26W= 5B= 73W1 19B1 7W= 23B1 1W= 11 7.5 68.18 63.5 68.5 45.75 0.0 4 3
66+
4 Yu, Yangyi 2704 9.20 5W= 63B1 61W1 1W= 49B= 13B= 15W= 28B= 33W1 8B= 6W= 11 7.0 63.64 66.5 72.0 44.50 0.0 3 1
67+
5 Keymer, Vincent 2630 22.06 4B= 27W1 25B= 10W= 59B= 3W= 24B0 82W1 53B1 29W1 9B= 11 7.0 63.64 65.5 70.0 43.25 0.0 4 1
68+
6 Vachier-Lagrave, Maxime 2763 2.12 52B= 51W1 71B= 60W1 1B= 32W1 31B= 8W= 11B= 2W= 4B= 11 7.0 63.64 65.0 70.0 43.50 0.0 3 0
69+
7 Predke, Alexandr 2666 14.22 46B1 54W1 1B0 47W= 42B1 31W0 57B1 49W1 3B= 11W= 2B= 11 7.0 63.64 64.5 70.0 42.25 0.0 5 3
70+
8 Shirov, Alexei 2659 16.99 43B= 87W1 50B= 92W1 36B1 1W= 14B= 6B= 23W= 4W= 10B= 11 7.0 63.64 64.5 68.5 41.50 0.0 3 1
71+
9 Howell, David W L 2658 15.43 82B1 92W= 72B= 50W= 2B0 54W1 47B1 14W1 12W1 1B0 5W= 11 7.0 63.64 62.5 66.5 40.25 0.0 5 2
72+
10 Sargissian, Gabriel 2664 10.56 72W= 83B= 94W1 5B= 70W1 15B= 18W= 34B= 28W1 13B= 8W= 11 7.0 63.64 61.5 65.5 40.50 0.0 3 0
73+
11 Anton Guijarro, David 2658 13.25 37W= 70B= 62W1 17B0 98W1 91B1 19W= 21B1 6W= 7B= 13W= 11 7.0 63.64 61.0 65.0 39.25 0.0 4 2
74+
12 Korobov, Anton 2690 6.07 48B= 20W1 47B= 42W= 50B1 49W= 17B= 41W1 9B0 34W= 31B1 11 7.0 63.64 60.5 66.0 41.50 0.0 4 2
75+
13 Sevian, Samuel 2654 15.89 80B= 84W1 92B= 72W1 32B= 4W= 2B= 53W1 30B= 10W= 11B= 11 7.0 63.64 60.5 64.5 39.75 0.0 3 0
76+
14 Esipenko, Andrey 2720 3.08 58B= 42W= 81B= 63W1 71B= 56W1 8W= 9B0 64B1 31W1 15B= 11 7.0 63.64 60.0 64.5 40.00 0.0 4 1
77+
15 Deac, Bogdan-Daniel 2643 15.05 89B= 104W= 106B1 53W= 29B1 10W= 4B= 25W= 18B= 38B1 14W= 11 7.0 63.64 60.0 63.0 39.25 0.0 3 3
78+
16 Artemiev, Vladislav 2699 4.40 76B1 50W= 75B= 31W= 51B= 47W= 48B= 52W= 49B1 17W= 34B1 11 7.0 63.64 56.5 61.5 39.00 0.0 3 3
79+
80+
...
81+
4982

5083
Version 0.9.0 [2022-06-25]
5184
""""""""""""""""""""""""""

src/pgnhelper/swiss.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,16 @@ def table(self) -> pd.DataFrame:
211211
tb_label.append('TB5')
212212
df_tb5 = df_tb5.reset_index(drop=True)
213213

214-
df_final = df_tb5.copy()
214+
# 1.5 Apply most number of wins with black.
215+
df_tb6 = pgnhelper.tiebreak.num_wins(self.record, df_tb5, label='TB6', bwins=True)
216+
df_tb6 = df_tb6.sort_values(
217+
by=['Score', 'TB1', 'TB2', 'TB3', 'TB4', 'TB5', 'TB6'],
218+
ascending=[False, False, False, False, False, False, False]
219+
)
220+
tb_label.append('TB6')
221+
df_tb6 = df_tb6.reset_index(drop=True)
222+
223+
df_final = df_tb6.copy()
215224

216225
# 2. Build a swiss table dataframe.
217226
if self.israting:
@@ -253,6 +262,7 @@ def table(self) -> pd.DataFrame:
253262
df_swiss[tb_label[2]] = df_tb3[tb_label[2]].round(2)
254263
df_swiss[tb_label[3]] = df_tb4[tb_label[3]].round(2)
255264
df_swiss[tb_label[4]] = df_tb5[tb_label[4]].round(2)
265+
df_swiss[tb_label[5]] = df_tb6[tb_label[5]].round(2)
256266

257267
# 4. Insert rank column at first column.
258268
df_swiss.insert(loc=0, column='Rank', value=range(1, len(df_swiss) + 1))

src/pgnhelper/tiebreak.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,31 @@ def played_each_other(result_df, tie_df) -> bool:
2727
return True
2828

2929

30-
def num_wins(result_df: pd.DataFrame, ranking_df: pd.DataFrame, label='Wins') -> pd.DataFrame:
30+
def num_wins(result_df: pd.DataFrame, ranking_df: pd.DataFrame, label='Wins', bwins: bool=False) -> pd.DataFrame:
3131
"""Creates a dataframe with Win column.
3232
3333
If a game has an armageddon tie-break, we will only count the number of wins
3434
based from the normal game only.
35+
36+
Args:
37+
result_df: The result dataframe.
38+
ranking_df: Ranking of players based on score.
39+
label: The label or header of the resulting dataframe.
40+
bwins: If true then only count wins by black. If not count all wins.
41+
42+
Returns:
43+
A dataframe of ranking with Wins column for tie-break.
3544
"""
3645
ret = ranking_df.copy()
3746
players = list(ret.Name)
3847
tb = {}
3948
for _, g in ret.groupby(['Score']):
4049
if len(g) > 1:
4150
for p in g.Name:
42-
df_w = result_df.loc[(result_df.White == p) & (result_df.Result == '1-0') & (result_df.Arm == 0)]
51+
if not bwins:
52+
df_w = result_df.loc[(result_df.White == p) & (result_df.Result == '1-0') & (result_df.Arm == 0)]
53+
else:
54+
df_w = pd.DataFrame()
4355
df_b = result_df.loc[(result_df.Black == p) & (result_df.Result == '0-1') & (result_df.Arm == 0)]
4456
num_wins = len(df_w) + len(df_b)
4557
tb.update({p: num_wins})

0 commit comments

Comments
 (0)