Advertisement
Guest User

Untitled

a guest
Nov 30th, 2021
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.91 KB | None | 0 0
  1. """
  2. входной файл f.txt
  3. ---------
  4. [Event "Casual Rapid game"]
  5. [Site "yxpC0GIN"]
  6. [Date "2021.11.29"]
  7. [White "Roman8274518"]
  8. [Black "Sliver777"]
  9. [Result "0-1"]
  10. [UTCDate "2021.11.29"]
  11. [UTCTime "16:13:59"]
  12. [WhiteElo "2227"]
  13. [BlackElo "2294"]
  14. [Variant "Standard"]
  15. [TimeControl "600+5"]
  16. [ECO "B03"]
  17. [Termination "Normal"]
  18.  
  19. 1. e4 Nf6 2. e5 Nd5 3. c4 Nb6 4. d4 d6 5. exd6 cxd6 6. Be3 g6 7. Nc3 Bg7 8. h3 O-O 9. Nf3 Nc6 10. Rc1 d5 11. b3 e5 12. dxe5 d4 13. Nxd4 Nxe5 14. Be2 f5 15. f4 Qh4+ 16. Kf1 Ng4 17. Bxg4 fxg4 18. Qe1 g3 19. Nf3 Qf6 20. Ne4 Qc6 21. Nxg3 Bd7 22. Kf2 Rae8 23. Qd2 g5 24. Nxg5 Qh6 25. c5 Qxg5 26. cxb6 Rxe3 27. Qxe3 Bd4 28. Ke2 Qb5+ 29. Qd3 Re8+ 30. Kd2 Qa5+ 31. Kd1 Qxb6 32. Qc4+ Be6 33. Qd3 Rd8 34. Kc2 Bf7 35. f5 Be5 36. Qe4 Qf2+ 37. Ne2 Bf6 38. Rhf1 Qc5+ 39. Kb1 Qa3 40. Qc2 Bd5 41. Nc3 Rc8 42. Rfd1 Rxc3 43. Qxc3 Be4+ 44. Ka1 Bxc3+ 45. Rxc3 Qb4 46. Rc8+ Kf7 47. Rd7+ Kf6 48. Rf8+ Qxf8 0-1
  20. ---------
  21. """
  22.  
  23. import re
  24. D = dict()
  25. with open('f.txt') as f:
  26. for s in f:
  27. s = s.strip().lstrip('[').rstrip(']')
  28. if s:
  29. if s[0].isalpha():
  30. a = s.find(' ') + 1
  31. b = s.find('"') + 1
  32. c = s.rfind('"')
  33. D[s[:a]] = s[b:c]
  34. elif s[0] is '1':
  35. pattern = '(\s)(\d+\.\s)'
  36. repl = r'$$$\2'
  37. moves = re.sub(pattern, repl, s).split('$$$')
  38. moves = [a.split('. ') for a in moves]
  39. moves = dict((int(a[0]),a[1].split()) for a in moves)
  40.  
  41. print(D)
  42. print(moves)
  43.  
  44. """
  45. на выходе
  46. -------------
  47. ==================
  48. {'Event ': 'Casual Rapid game', 'Site ': 'yxpC0GIN', 'Date ': '2021.11.29', 'White ': 'Roman8274518', 'Black ': 'Sliver777', 'Result ': '0-1', 'UTCDate ': '2021.11.29', 'UTCTime ': '16:13:59', 'WhiteElo ': '2227', 'BlackElo ': '2294', 'Variant ': 'Standard', 'TimeControl ': '600+5', 'ECO ': 'B03', 'Termination ': 'Normal'}
  49. {1: ['e4', 'Nf6'], 2: ['e5', 'Nd5'], 3: ['c4', 'Nb6'], 4: ['d4', 'd6'], 5: ['exd6', 'cxd6'], 6: ['Be3', 'g6'], 7: ['Nc3', 'Bg7'], 8: ['h3', 'O-O'], 9: ['Nf3', 'Nc6'], 10: ['Rc1', 'd5'], 11: ['b3', 'e5'], 12: ['dxe5', 'd4'], 13: ['Nxd4', 'Nxe5'], 14: ['Be2', 'f5'], 15: ['f4', 'Qh4+'], 16: ['Kf1', 'Ng4'], 17: ['Bxg4', 'fxg4'], 18: ['Qe1', 'g3'], 19: ['Nf3', 'Qf6'], 20: ['Ne4', 'Qc6'], 21: ['Nxg3', 'Bd7'], 22: ['Kf2', 'Rae8'], 23: ['Qd2', 'g5'], 24: ['Nxg5', 'Qh6'], 25: ['c5', 'Qxg5'], 26: ['cxb6', 'Rxe3'], 27: ['Qxe3', 'Bd4'], 28: ['Ke2', 'Qb5+'], 29: ['Qd3', 'Re8+'], 30: ['Kd2', 'Qa5+'], 31: ['Kd1', 'Qxb6'], 32: ['Qc4+', 'Be6'], 33: ['Qd3', 'Rd8'], 34: ['Kc2', 'Bf7'], 35: ['f5', 'Be5'], 36: ['Qe4', 'Qf2+'], 37: ['Ne2', 'Bf6'], 38: ['Rhf1', 'Qc5+'], 39: ['Kb1', 'Qa3'], 40: ['Qc2', 'Bd5'], 41: ['Nc3', 'Rc8'], 42: ['Rfd1', 'Rxc3'], 43: ['Qxc3', 'Be4+'], 44: ['Ka1', 'Bxc3+'], 45: ['Rxc3', 'Qb4'], 46: ['Rc8+', 'Kf7'], 47: ['Rd7+', 'Kf6'], 48: ['Rf8+', 'Qxf8', '0-1']}
  50. >>>
  51. """
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement