From 226a0e1ac448819fcbd11acc94deb4c526ea731b Mon Sep 17 00:00:00 2001 From: Valdos Sine Date: Fri, 2 Oct 2015 00:36:55 +0300 Subject: [PATCH] Tournament "The Return of the Kings": Randomized players for the tour generation --- 2015/1-kings/randomize.py | 32 ++++++++++++++++++++++++++++++++ 2015/1-kings/table.txt | 16 ++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100755 2015/1-kings/randomize.py create mode 100644 2015/1-kings/table.txt diff --git a/2015/1-kings/randomize.py b/2015/1-kings/randomize.py new file mode 100755 index 0000000..60b749b --- /dev/null +++ b/2015/1-kings/randomize.py @@ -0,0 +1,32 @@ +#!/usr/bin/python2 +# -*- coding: utf-8 -*- + +import random, time + +def write_user(username, table_size): + repeater = False + random_seed = random.choice(range(1, table_size)) + tfile = open('table.txt', 'r+a') + tabledata = tfile.readlines() + for line in tabledata: + if line.split(' | ')[0] == str(random_seed): + # repeat from begin + repeater = True + write_user(username, table_size) + # if we haven't matching number, write das line + if repeater == False: + tfile.write("%i | %s\n" % (random_seed, username)) + +def check_file(username, table_size): + try: + tablefile = open('table.txt', 'r') + write_user(username, table_size) + except IOError: + tablefile = open('table.txt', 'w') + tablefile.write("Жеребьевка участников LORChess.\nРазмер таблицы участников: %s.\nДанный файл является неизменяемым и создаваемым один раз.\nUNIX timestamp: %i\n========\n\n" % (table_size - 1, int(time.time()))) + tablefile.close() + write_user(username, table_size) + + +nickname = raw_input("Введите имя игрока: ") +check_file(nickname, 11) diff --git a/2015/1-kings/table.txt b/2015/1-kings/table.txt new file mode 100644 index 0000000..a784af6 --- /dev/null +++ b/2015/1-kings/table.txt @@ -0,0 +1,16 @@ +Жеребьевка участников LORChess. +Размер таблицы участников: 10. +Данный файл является неизменяемым и создаваемым один раз. +UNIX timestamp: 1443734646 +======== + +10 | DoctorSinus +2 | MyTrooName +8 | aptyp +1 | J +5 | redgremlin +7 | Nedis +3 | Genuine +4 | Nokman +9 | trex6 +6 | DeadEye