sombriks

Untitled

Mar 28th, 2014
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 20.66 KB | None | 0 0
  1. #
  2. # -*- coding: utf-8 -*-
  3. #
  4.  
  5. import pickle
  6. import os.path
  7.  
  8. # nome do time, pontuacao, gols marcados, gols sofridos
  9. selecao = [
  10.     [  
  11.         ['BRASIL', 0, 0, 0], ['CROACIA', 0, 0, 0], ['MEXICO', 0, 0, 0], ['CAMAROES', 0, 0, 0, ]
  12.     ], [  
  13.         ['ESPANHA', 0, 0, 0], ['HOLANDA', 0, 0, 0], ['CHILE', 0, 0, 0], ['AUSTRALIA', 0, 0, 0]
  14.     ], [  
  15.         ['COLOMBIA', 0, 0, 0], ['GRECIA', 0, 0, 0], ['C. DO MARFIM', 0, 0, 0], ['JAPÃO', 0, 0, 0]
  16.     ], [
  17.         ['URUGUAI', 0, 0, 0], ['COSTA RICA', 0, 0, 0], ['INGLATERRA', 0, 0, 0], ['ITÁLIA', 0, 0, 0]
  18.     ], [  
  19.         ['SUIÇA', 0, 0, 0], ['EQUADOR', 0, 0, 0], ['FRANÇA', 0, 0, 0], ['HONDURAS', 0, 0, 0]
  20.     ], [  
  21.         ['ARGENTINA', 0, 0, 0], ['BOSNIA', 0, 0, 0], ['IRA', 0, 0, 0], ['NIGERIA', 0, 0, 0]
  22.     ], [  
  23.         ['ALEMANHA', 0, 0, 0], ['PORTUGAL', 0, 0, 0], ['GANA', 0, 0, 0], ['EUA', 0, 0, 0]
  24.     ], [
  25.         ['BELGICA', 0, 0, 0], ['ARGELIA', 0, 0, 0], ['RÚSSIA', 0, 0, 0], ['C. DO SUL', 0, 0, 0]
  26.     ]
  27. ]
  28.  
  29. times_oitavas = []
  30.  
  31. times_quartas = []
  32.  
  33. times_semifinais = []
  34.  
  35. # TODO o array de cidades, ele é praticamente inútil
  36. cid = ['FORTALEZA', 'NATAL', 'RECIFE', 'SALVADOR', 'BRASÍLIA', 'BELO HORIZONTE', 'SÃO PAULO',
  37.        'CUIABÁ', 'MANAUS', 'RIO DE JANEIRO', 'CURITIBA', 'PORTO ALEGRE']
  38.  
  39. grupos = [
  40.       [  # grupo A
  41.         [selecao[0][0], selecao[0][1], '12/06/2014', 'Quinta-Feira', '16:00h', cid[6], 3, 2],
  42.         [selecao[0][2], selecao[0][3], '13/06/2014', 'Sexta-Feira', '13:00h', cid[1], 5, 0],
  43.         [selecao[0][0], selecao[0][2], '17/06/2014', 'Terça-Feira', '16:00h', cid[0], 2, 1],
  44.         [selecao[0][3], selecao[0][1], '18/06/2014', 'Quarta-Feira', '19:00h', cid[8], 3, 3],
  45.         [selecao[0][1], selecao[0][2], '23/06/2014', 'Segunda-Feira', '17:00h', cid[2], 2, 0],
  46.         [selecao[0][3], selecao[0][0], '23/06/2014', 'Segunda-Feira', '17:00h', cid[4], 0, 0]
  47.     ], [  # grupo B
  48.         [selecao[1][0], selecao[1][1], '13/06/2014', 'Sexta-Feira', '16:00h', cid[3], 1, 4],
  49.         [selecao[1][2], selecao[1][3], '13/06/2014', 'Sexta-Feira', '19:00h', cid[7], 4, 6],
  50.         [selecao[1][0], selecao[1][2], '18/06/2014', 'Quarta-Feira', '13:00h', cid[11], 1, 1],
  51.         [selecao[1][3], selecao[1][1], '18/06/2014', 'Quarta-Feira', '16:00h', cid[9], 0, 7],
  52.         [selecao[1][1], selecao[1][2], '23/06/2014', 'Segunda-Feira', '13:00h', cid[10], 2, 2],
  53.         [selecao[1][3], selecao[1][0], '23/06/2014', 'Segunda-Feira', '13:00h', cid[6], 1, 1]
  54.     ], [  # grupo C
  55.         [selecao[2][0], selecao[2][1], '14/06/2014', 'Sábado', '13:00h', cid[5], 10, 0],
  56.         [selecao[2][2], selecao[2][3], '14/06/2014', 'Sábado', '22:00h', cid[2], 4, 2],
  57.         [selecao[2][0], selecao[2][2], '19/06/2014', 'Quinta-feira', '13:00h', cid[4], 2, 1],
  58.         [selecao[2][3], selecao[2][1], '19/06/2014', 'Quinta-feira', '19:00h', cid[1], 1, 1],
  59.         [selecao[2][1], selecao[2][2], '24/06/2014', 'Terça-Feira', '17:00h', cid[7], 3, 7],
  60.         [selecao[2][3], selecao[2][0], '24/06/2014', 'Terça-Feira', '17:00h', cid[0], 0, 0]
  61.     ], [  # grupo D
  62.         [selecao[3][0], selecao[3][1], '14/06/2014', 'Sábado', '16:00h', cid[0], 0, 1],
  63.         [selecao[3][2], selecao[3][3], '14/06/2014', 'Sábado', '19:00h', cid[8], 0, 2],
  64.         [selecao[3][0], selecao[3][2], '19/06/2014', 'Quinta-feira', '16:00h', cid[6], 0, 3],
  65.         [selecao[3][3], selecao[3][1], '20/06/2014', 'Sexta-feira', '13:00h', cid[2], 0, 4],
  66.         [selecao[3][1], selecao[3][2], '24/06/2014', 'Terça-Feira', '13:00h', cid[1], 0, 5],
  67.         [selecao[3][3], selecao[3][0], '24/06/2014', 'Terça-Feira', '13:00h', cid[5], 0, 6]
  68.     ], [  # grupo E
  69.         [selecao[4][0], selecao[4][1], '15/06/2014', 'Domingo', '13:00h', cid[4], 0, 0],
  70.         [selecao[4][2], selecao[4][3], '15/06/2014', 'Domingo', '16:00h', cid[11], 1, 1],
  71.         [selecao[4][0], selecao[4][2], '20/06/2014', 'Sexta-feira', '16:00h', cid[3], 2, 3],
  72.         [selecao[4][3], selecao[4][1], '20/06/2014', 'Sexta-feira', '19:00h', cid[10], 0, 0],
  73.         [selecao[4][1], selecao[4][2], '25/06/2014', 'Quarta-Feira', '17:00h', cid[8], 5, 2],
  74.         [selecao[4][3], selecao[4][0], '25/06/2014', 'Quarta-Feira', '17:00h', cid[9], 3, 6]
  75.     ], [  # grupo F
  76.         [selecao[5][0], selecao[5][1], '15/06/2014', 'Domingo', '19:00h', cid[9], 0, 1],
  77.         [selecao[5][2], selecao[5][3], '16/06/2014', 'Segunda-Feira', '16:00h', cid[10], 1, 1],
  78.         [selecao[5][0], selecao[5][2], '21/06/2014', 'Sábado', '13:00h', cid[5], 1, 2],
  79.         [selecao[5][3], selecao[5][1], '21/06/2014', 'Sábado', '19:00h', cid[7], 1, 0],
  80.         [selecao[5][1], selecao[5][2], '25/06/2014', 'Quarta-Feira', '13:00h', cid[3], 2, 1],
  81.         [selecao[5][3], selecao[5][0], '25/06/2014', 'Quarta-Feira', '13:00h', cid[11], 8, 1]
  82.     ], [  # grupo G
  83.         [selecao[6][0], selecao[6][1], '16/06/2014', 'Segunda-Feira', '13:00h', cid[3], 2, 1],
  84.         [selecao[6][2], selecao[6][3], '16/06/2014', 'Segunda-Feira', '19:00h', cid[1], 1, 3],
  85.         [selecao[6][0], selecao[6][2], '21/06/2014', 'Sábado', '16:00h', cid[0], 4, 1],
  86.         [selecao[6][3], selecao[6][1], '22/06/2014', 'Domingo', '19:00h', cid[8], 1, 5],
  87.         [selecao[6][1], selecao[6][2], '26/06/2014', 'Quinta-Feira', '13:00h', cid[4], 6, 1],
  88.         [selecao[6][3], selecao[6][0], '26/06/2014', 'Quinta-Feira', '13:00h', cid[2], 7, 1]
  89.     ], [  # grupo H
  90.         [selecao[7][0], selecao[7][1], '17/06/2014', 'Terça-Feira', '13:00h', cid[5], 4, 2],
  91.         [selecao[7][2], selecao[7][3], '17/06/2014', 'Terça-Feira', '19:00h', cid[7], 2, 1],
  92.         [selecao[7][0], selecao[7][2], '22/06/2014', 'Domingo', '13:00h', cid[9], 1, 5],
  93.         [selecao[7][3], selecao[7][1], '22/06/2014', 'Domingo', '16:00h', cid[11], 2, 2],
  94.         [selecao[7][1], selecao[7][2], '26/06/2014', 'Quinta-Feira', '17:00h', cid[10], 0, 0],
  95.         [selecao[7][3], selecao[7][0], '26/06/2014', 'Quinta-Feira', '17:00h', cid[6], 1, 8]
  96.     ]
  97. ]
  98.  
  99. #
  100. # grupos = [
  101. #       [  # grupo A
  102. #         [selecao[0][0], selecao[0][1], '12/06/2014', 'Quinta-Feira', '16:00h', cid[6], '__', '__'],
  103. #         [selecao[0][2], selecao[0][3], '13/06/2014', 'Sexta-Feira', '13:00h', cid[1], '__', '__'],
  104. #         [selecao[0][0], selecao[0][2], '17/06/2014', 'Terça-Feira', '16:00h', cid[0], '__', '__'],
  105. #         [selecao[0][3], selecao[0][1], '18/06/2014', 'Quarta-Feira', '19:00h', cid[8], '__', '__'],
  106. #         [selecao[0][1], selecao[0][2], '23/06/2014', 'Segunda-Feira', '17:00h', cid[2], '__', '__'],
  107. #         [selecao[0][3], selecao[0][0], '23/06/2014', 'Segunda-Feira', '17:00h', cid[4], '__', '__']
  108. #     ], [  # grupo B
  109. #         [selecao[1][0], selecao[1][1], '13/06/2014', 'Sexta-Feira', '16:00h', cid[3], '__', '__'],
  110. #         [selecao[1][2], selecao[1][3], '13/06/2014', 'Sexta-Feira', '19:00h', cid[7], '__', '__'],
  111. #         [selecao[1][0], selecao[1][2], '18/06/2014', 'Quarta-Feira', '13:00h', cid[11], '__', '__'],
  112. #         [selecao[1][3], selecao[1][1], '18/06/2014', 'Quarta-Feira', '16:00h', cid[9], '__', '__'],
  113. #         [selecao[1][1], selecao[1][2], '23/06/2014', 'Segunda-Feira', '13:00h', cid[10], '__', '__'],
  114. #         [selecao[1][3], selecao[1][0], '23/06/2014', 'Segunda-Feira', '13:00h', cid[6], '__', '__']
  115. #     ], [  # grupo C
  116. #         [selecao[2][0], selecao[2][1], '14/06/2014', 'Sábado', '13:00h', cid[5], '__', '__'],
  117. #         [selecao[2][2], selecao[2][3], '14/06/2014', 'Sábado', '22:00h', cid[2], '__', '__'],
  118. #         [selecao[2][0], selecao[2][2], '19/06/2014', 'Quinta-feira', '13:00h', cid[4], '__', '__'],
  119. #         [selecao[2][3], selecao[2][1], '19/06/2014', 'Quinta-feira', '19:00h', cid[1], '__', '__'],
  120. #         [selecao[2][1], selecao[2][2], '24/06/2014', 'Terça-Feira', '17:00h', cid[7], '__', '__'],
  121. #         [selecao[2][3], selecao[2][0], '24/06/2014', 'Terça-Feira', '17:00h', cid[0], '__', '__']
  122. #     ], [  # grupo D
  123. #         [selecao[3][0], selecao[3][1], '14/06/2014', 'Sábado', '16:00h', cid[0], '__', '__'],
  124. #         [selecao[3][2], selecao[3][3], '14/06/2014', 'Sábado', '19:00h', cid[8], '__', '__'],
  125. #         [selecao[3][0], selecao[3][2], '19/06/2014', 'Quinta-feira', '16:00h', cid[6], '__', '__'],
  126. #         [selecao[3][3], selecao[3][1], '20/06/2014', 'Sexta-feira', '13:00h', cid[2], '__', '__'],
  127. #         [selecao[3][1], selecao[3][2], '24/06/2014', 'Terça-Feira', '13:00h', cid[1], '__', '__'],
  128. #         [selecao[3][3], selecao[3][0], '24/06/2014', 'Terça-Feira', '13:00h', cid[5], '__', '__']
  129. #     ], [  # grupo E
  130. #         [selecao[4][0], selecao[4][1], '15/06/2014', 'Domingo', '13:00h', cid[4], '__', '__'],
  131. #         [selecao[4][2], selecao[4][3], '15/06/2014', 'Domingo', '16:00h', cid[11], '__', '__'],
  132. #         [selecao[4][0], selecao[4][2], '20/06/2014', 'Sexta-feira', '16:00h', cid[3], '__', '__'],
  133. #         [selecao[4][3], selecao[4][1], '20/06/2014', 'Sexta-feira', '19:00h', cid[10], '__', '__'],
  134. #         [selecao[4][1], selecao[4][2], '25/06/2014', 'Quarta-Feira', '17:00h', cid[8], '__', '__'],
  135. #         [selecao[4][3], selecao[4][0], '25/06/2014', 'Quarta-Feira', '17:00h', cid[9], '__', '__']
  136. #     ], [  # grupo F
  137. #         [selecao[5][0], selecao[5][1], '15/06/2014', 'Domingo', '19:00h', cid[9], '__', '__'],
  138. #         [selecao[5][2], selecao[5][3], '16/06/2014', 'Segunda-Feira', '16:00h', cid[10], '__', '__'],
  139. #         [selecao[5][0], selecao[5][2], '21/06/2014', 'Sábado', '13:00h', cid[5], '__', '__'],
  140. #         [selecao[5][3], selecao[5][1], '21/06/2014', 'Sábado', '19:00h', cid[7], '__', '__'],
  141. #         [selecao[5][1], selecao[5][2], '25/06/2014', 'Quarta-Feira', '13:00h', cid[3], '__', '__'],
  142. #         [selecao[5][3], selecao[5][0], '25/06/2014', 'Quarta-Feira', '13:00h', cid[11], '__', '__']
  143. #     ], [  # grupo G
  144. #         [selecao[6][0], selecao[6][1], '16/06/2014', 'Segunda-Feira', '13:00h', cid[3], '__', '__'],
  145. #         [selecao[6][2], selecao[6][3], '16/06/2014', 'Segunda-Feira', '19:00h', cid[1], '__', '__'],
  146. #         [selecao[6][0], selecao[6][2], '21/06/2014', 'Sábado', '16:00h', cid[0], '__', '__'],
  147. #         [selecao[6][3], selecao[6][1], '22/06/2014', 'Domingo', '19:00h', cid[8], '__', '__'],
  148. #         [selecao[6][1], selecao[6][2], '26/06/2014', 'Quinta-Feira', '13:00h', cid[4], '__', '__'],
  149. #         [selecao[6][3], selecao[6][0], '26/06/2014', 'Quinta-Feira', '13:00h', cid[2], '__', '__']
  150. #     ], [  # grupo H
  151. #         [selecao[7][0], selecao[7][1], '17/06/2014', 'Terça-Feira', '13:00h', cid[5], '__', '__'],
  152. #         [selecao[7][2], selecao[7][3], '17/06/2014', 'Terça-Feira', '19:00h', cid[7], '__', '__'],
  153. #         [selecao[7][0], selecao[7][2], '22/06/2014', 'Domingo', '13:00h', cid[9], '__', '__'],
  154. #         [selecao[7][3], selecao[7][1], '22/06/2014', 'Domingo', '16:00h', cid[11], '__', '__'],
  155. #         [selecao[7][1], selecao[7][2], '26/06/2014', 'Quinta-Feira', '17:00h', cid[10], '__', '__'],
  156. #         [selecao[7][3], selecao[7][0], '26/06/2014', 'Quinta-Feira', '17:00h', cid[6], '__', '__']
  157. #     ]
  158. # ]
  159.  
  160. oitavas = [
  161.     ['  ', '   ', '28/06/2014', 'Sábado', '13:00h', cid[5], 1, 0 ],
  162.     ['  ', '   ', '28/06/2014', 'Sábado', '17:00h', cid[6], 2, 0 ],
  163.     ['  ', '   ', '30/06/2014', 'Segunda-Feira', '13:00h', cid[5], 0, 0],
  164.     ['  ', '   ', '30/06/2014', 'Segunda-Feira', '17:00h', cid[5], 2, 3 ],
  165.     ['  ', '   ', '29/06/2014', 'Domingo', '13:00h', cid[0], 1, 3 ],
  166.     ['  ', '   ', '29/06/2014', 'Domingo', '17:00h', cid[2], 3, 3 ],
  167.     ['  ', '   ', '01/07/2014', 'Terça-Feira', '13:00h', cid[6], 1, 1],
  168.     ['  ', '   ', '01/07/2014', 'Terça-Feira', '17:00h', cid[5], 4, 1]
  169. ]
  170.  
  171. quartas = [
  172.     ['  ', '   ', '04/07/2014', 'Sexta-Feira', '17:00h', cid[0], '__', '__' ],
  173.     ['  ', '   ', '04/07/2014', 'Sexta-Feira', '13:00h', cid[9], '__', '__'],
  174.     ['  ', '   ', '05/07/2014', 'Sábado', '17:00h', cid[5], '__', '__'],
  175.     ['  ', '   ', '05/07/2014', 'Sábado', '13:00h', cid[5], '__', '__']
  176. ]
  177.  
  178. semifinal = [
  179.     ['  ', '   ', '08/07/2014', 'Terça-Feira', '17:00h', cid[5], '__', '__' ],
  180.     ['  ', '   ', '09/07/2014', 'Quarta-Feira', '17:00h', cid[6], '__', '__' ]
  181. ]
  182.  
  183. terceiro_e_quarto = ['  ', '   ', '12/07/2014', 'Sábado', '17:00h', cid[4], '__', '__' ]
  184.  
  185. disputa_final = ['  ', '   ', '13/07/2014', 'Domingo', '17:00h', cid[9], '__', '__' ]
  186.  
  187. objetos = [selecao, times_oitavas, times_quartas, times_semifinais, cid, grupos, oitavas, quartas, semifinal, terceiro_e_quarto, disputa_final]
  188.  
  189.  
  190. grps = ["A", "B", "C", "D", "E", "F", "G", "H"]
  191.  
  192. # nome do time, pontuacao, gols marcados, gols sofridos, saldo de gols
  193. def print_tabela_pontos():
  194.     g = ["A", "B", "C", "D", "E", "F", "G", "H"]
  195.     for n in range(len(selecao)):
  196.         print("Grupo {}:".format(g[n]))
  197.         for i in selecao[n]:
  198.             s = "seleção: {:<15}, pontos: {}, gols marcados: {}, gols sofridos: {} saldo de gols: {}"
  199.             print(s.format(i[0], i[1], i[2], i[3], i[2] - i[3]))
  200.  
  201. # seleção 1, seleção 2, data, dia semana, hora, cidade, r1, r2
  202. def print_partida(p, n=""):
  203.     # Brasil 3 X Croácia 2, Quinta-Feira às 16:00h, 12/06/2014 em São Paulo
  204.     s = "{} {} {} X {} {}, {} às {}, {} em {}"
  205.     s = s.format(n, p[0][0], p[6], p[1][0], p[7], p[3], p[4], p[2], p[5])
  206.     print(s)
  207.  
  208. def pts(a, b):
  209.     return b[1] - a[1]
  210.  
  211. def atualiza_oitavas():
  212.     # ordena cada grupo pelos pontos marcados
  213.     for g in range(len(selecao)):
  214.         selecao[g] = sorted(selecao[g], cmp=pts)
  215.     # http://stackoverflow.com/questions/1400608/how-to-empty-a-list-in-python
  216.     times_oitavas[:] = []
  217.     # 1º Grupo A x 2º Grupo B
  218.     oitavas[0][0] = selecao[0][0]
  219.     oitavas[0][1] = selecao[1][1]
  220.     times_oitavas.append([selecao[0][0], selecao[1][1]])  # p81
  221.     # 1º Grupo C x 2º Grupo D
  222.     oitavas[1][0] = selecao[2][0]
  223.     oitavas[1][1] = selecao[3][1]
  224.     times_oitavas.append([selecao[2][0], selecao[3][1]])  # p82
  225.     # 1º Grupo B x 2º Grupo A
  226.     oitavas[2][0] = selecao[1][0]
  227.     oitavas[2][1] = selecao[0][1]
  228.     times_oitavas.append([selecao[1][0], selecao[0][1]])  # p83
  229.     # 1º Grupo D x 2º Grupo C
  230.     oitavas[3][0] = selecao[3][0]
  231.     oitavas[3][1] = selecao[2][1]
  232.     times_oitavas.append([selecao[3][0], selecao[2][1]])  # p84
  233.     # 1º Grupo E x 2º Grupo F
  234.     oitavas[4][0] = selecao[4][0]
  235.     oitavas[4][1] = selecao[5][1]
  236.     times_oitavas.append([selecao[4][0], selecao[5][1]])  # p85
  237.     # 1º Grupo G x 2º Grupo H
  238.     oitavas[5][0] = selecao[6][0]
  239.     oitavas[5][1] = selecao[7][1]
  240.     times_oitavas.append([selecao[6][0], selecao[7][1]])  # p86
  241.     # 1º Grupo F x 2º Grupo E
  242.     oitavas[6][0] = selecao[5][0]
  243.     oitavas[6][1] = selecao[4][1]
  244.     times_oitavas.append([selecao[5][0], selecao[4][1]])  # p87
  245.     # 1º Grupo H x 2º Grupo G
  246.     oitavas[7][0] = selecao[7][0]
  247.     oitavas[7][1] = selecao[6][1]
  248.     times_oitavas.append([selecao[7][0], selecao[6][1]])  # p88
  249.    
  250.    
  251. def atualiza_quartas():
  252.     # ordena os grupos de oitava pelos pontos marcados
  253.     for g in range(len(times_oitavas)):
  254.         times_oitavas[g] = sorted(times_oitavas[g], cmp=pts)
  255.     times_quartas[:] = []
  256.     # Vencedor 5 x Vencedor 6
  257.     quartas[0][0] = times_oitavas[4][0]
  258.     quartas[0][1] = times_oitavas[5][0]
  259.     times_quartas.append([times_oitavas[4][0], times_oitavas[5][0]])
  260.     # Vencedor 1 x Vencedor 2
  261.     quartas[1][0] = times_oitavas[0][0]
  262.     quartas[1][1] = times_oitavas[1][0]
  263.     times_quartas.append([times_oitavas[0][0], times_oitavas[1][0]])
  264.     # Vencedor 7 x Vencedor 8
  265.     quartas[2][0] = times_oitavas[6][0]
  266.     quartas[2][1] = times_oitavas[7][0]
  267.     times_quartas.append([times_oitavas[6][0], times_oitavas[7][0]])
  268.     # Vencedor 3 x Vencedor 4
  269.     quartas[3][0] = times_oitavas[2][0]
  270.     quartas[3][1] = times_oitavas[3][0]
  271.     times_quartas.append([times_oitavas[2][0], times_oitavas[3][0]])
  272.  
  273. def atualiza_semifinal():
  274.     # ordena os grupos de oitava pelos pontos marcados
  275.     for g in range(len(times_quartas)):
  276.         times_quartas[g] = sorted(times_quartas[g], cmp=pts)
  277.     times_semifinais[:] = []
  278.     # Vencedor Q1 x Vencedor Q2
  279.     semifinal[0][0] = times_quartas[0][0]
  280.     semifinal[0][1] = times_quartas[1][0]
  281.     times_semifinais.append([times_quartas[0][0], times_quartas[1][0]])
  282.     # Vencedor Q3 x Vencedor Q4
  283.     semifinal[1][0] = times_quartas[2][0]
  284.     semifinal[1][1] = times_quartas[3][0]
  285.     times_semifinais.append([times_quartas[2][0], times_quartas[3][0]])
  286.  
  287. def atualiza_terceiro_e_final():
  288.     # ordena os grupos de oitava pelos pontos marcados
  289.     for g in range(len(times_semifinais)):
  290.         times_semifinais[g] = sorted(times_semifinais[g], cmp=pts)
  291.     terceiro_e_quarto[0] = times_semifinais[0][1]
  292.     terceiro_e_quarto[1] = times_semifinais[1][1]
  293.     disputa_final[0] = times_semifinais[0][0]
  294.     disputa_final[1] = times_semifinais[1][0]
  295.  
  296. def tem_oitavas():
  297.     for g in range(len(grupos)):
  298.         for h in range(len(grupos[g])):
  299.             if grupos[g][h][6] == '__' or grupos[g][h][7] == '__' :
  300.                 return False
  301.     return True  
  302.  
  303. def tem_quartas():
  304.     for g in range(len(oitavas)):
  305.         if oitavas[g][6] == '__' or oitavas[g][7] == '__' :
  306.             return False
  307.     return True
  308.  
  309. def tem_semifinal():
  310.     for g in range(len(quartas)):
  311.         if quartas[g][6] == '__' or quartas[g][7] == '__' :
  312.             return False
  313.     return True
  314.  
  315. def tem_terceiro_e_final():
  316.     for g in range(len(semifinal)):
  317.         if semifinal[g][6] == '__' or semifinal[g][7] == '__' :
  318.             return False
  319.     return True
  320.  
  321. def resultado_partida(prt):
  322.     print("Informe o resultado para {}".format(prt[0][0]))
  323.     r1 = int(input())
  324.     print("Informe o resultado para {}".format(prt[1][0]))
  325.     r2 = int(input())
  326.     prt[0][2] = prt[0][2] + r1
  327.     prt[0][3] = prt[0][3] + r2
  328.     prt[1][2] = prt[1][2] + r2
  329.     prt[1][3] = prt[1][3] + r1
  330.     prt[6] = r1
  331.     prt[7] = r2
  332.     if r1 == r2:
  333.         prt[0][1] = prt[0][1] + 1
  334.         prt[1][1] = prt[1][1] + 1
  335.     elif r1 > r2:
  336.         prt[0][1] = prt[0][1] + 3
  337.     else:
  338.         prt[1][1] = prt[1][1] + 3
  339.  
  340. def print_resultado():
  341.     # atualiza
  342.     atualiza_tabelas()
  343.     for g in range(len(grps)):
  344.         print("\r\nGrupo {}:".format(grps[g]))
  345.         for p in grupos[g]:
  346.             print_partida(p)
  347.     if tem_oitavas():
  348.         print("\r\nOitavas:")
  349.         for g in range(len(oitavas)):
  350.             print_partida(oitavas[g])
  351.     if tem_quartas():
  352.         print("\r\nQuartas:")
  353.         for g in range(len(quartas)):
  354.             print_partida(quartas[g])
  355.     if tem_semifinal():
  356.         print("Semifinal:")
  357.         for g in range(len(semifinal)):
  358.             print_partida(semifinal[g])
  359.     if tem_terceiro_e_final():
  360.         print("Disputa do terceiro lugar:")
  361.         print_partida(terceiro_e_quarto)
  362.         print("Final:")
  363.         print_partida(disputa_final)
  364.  
  365. def atualiza_tabelas():
  366.     if tem_oitavas():
  367.        atualiza_oitavas()
  368.     if tem_quartas():
  369.        atualiza_quartas()
  370.     if tem_semifinal():
  371.        atualiza_semifinal()
  372.     if tem_terceiro_e_final():
  373.        atualiza_terceiro_e_final()
  374.  
  375. def print_grupos():
  376.     # menu básico
  377.     print("Informe o grupo:")
  378.     for g in range(len(grps)):
  379.         print("{}. Grupo {}".format(g + 1, grps[g]))
  380.     if tem_oitavas():
  381.         print("9. Oitavas de final")
  382.     if tem_quartas():
  383.         print("10. Quartas de final")
  384.     if tem_semifinal():
  385.         print("11. Semifinal")
  386.     if tem_terceiro_e_final():
  387.         print("12. Terceiro lugar")
  388.         print("13. Final")
  389.     # descobrindo a opção do usuário
  390.     op = input()
  391.     if op < 9:
  392.         grp = grupos[op - 1]
  393.     elif op == 9:
  394.         grp = oitavas
  395.     elif op == 10:
  396.         grp = quartas
  397.     elif op == 11:
  398.         grp = semifinal
  399.  
  400.     for i in range(len(grp)):
  401.         print_partida(grp[i], i)
  402.     print("Informe a partida:")
  403.     op = int(input())
  404.    
  405.     # processando
  406.     resultado_partida(grp[op])
  407.    
  408.     # atualiza
  409.     atualiza_tabelas()
  410.    
  411.  
  412. def recarrega():
  413.     if os.path.isfile("jogos.ser"):
  414.         objetos = pickle.load("jogos.ser")
  415.         selecao = objetos[0]
  416.         times_oitavas = objetos[1]
  417.         times_quartas = objetos[2]
  418.         times_semifinais = objetos[3]
  419.         cid = objetos[4]
  420.         grupos = objetos[5]
  421.         oitavas = objetos[6]
  422.         quartas = objetos[7]
  423.         semifinal = objetos[8]
  424.         terceiro_e_quarto = objetos[9]
  425.         disputa_final = objetos[10]
  426.  
  427. def menu():
  428.     op = 1
  429.     while op > -1:
  430.         print("1. Ver resultados")
  431.         print("2. Ver tabela de pontos dos times")
  432.         print("3. Inserir resultado")
  433.         print("4. Sair")
  434.         print("op: ")
  435.         op = int(input())
  436.         if op == 1:
  437.             print_resultado()
  438.         elif op == 2:
  439.             print_tabela_pontos()
  440.         elif op == 3:
  441.             print_grupos()
  442.         else:
  443.             print("Saindo....")
  444.            
  445.             op = -1
  446.  
  447. recarrega()
  448. menu()
  449.  
  450. # print_partida(grupos[0][0])
Add Comment
Please, Sign In to add comment