Linux.org.ru chess tournament logs and tables
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
1.9KB

  1. #!/usr/bin/env bash
  2. # Copyright 2014, 2015 Vladimir Ivanov <ivvl82@gmail.com>
  3. # Distributed under the terms of the GNU General Public License v2
  4. REPO_DIR=
  5. # Specify the tournament here
  6. TOURNAMENT=
  7. function parse_setup {
  8. : ${REPO_DIR:=`dirname "$0"`}
  9. # If no tournament given, set it to the last one
  10. if [[ -z $TOURNAMENT ]]; then
  11. local year_dir=$(ls -1 -d ${REPO_DIR}/[0-9][0-9][0-9][0-9]/ | tail -1)
  12. TOURNAMENT=$(ls -1 -d ${year_dir}[0-9]-*/ | tail -1 \
  13. | sed -E "s|${REPO_DIR}/(.*)/|\1|")
  14. fi
  15. }
  16. function parse_tour_info {
  17. # Add a newline at the end of 'tour_info' to parse the last line
  18. local tour_info=$(cat "${REPO_DIR}/${TOURNAMENT}/tours/${tour}/tour_info"; echo)
  19. local date_re="[0-9?]{2}\.[0-9?]{2}\.[0-9?]{4}"
  20. local res_re="(1|½|0|\+|−)"
  21. while read line; do
  22. if [[ $line =~ ^($date_re)\ +([^\ ]+)\ +-\ +([^\ ]+)(\ +$res_re-$res_re)? ]]; then
  23. local date=${BASH_REMATCH[1]}
  24. local white=${BASH_REMATCH[2]}
  25. local black=${BASH_REMATCH[3]}
  26. local result=${BASH_REMATCH[5]}-${BASH_REMATCH[6]}
  27. local round=$(echo "($tour - 1)/($ply_count - 1) + 1" | bc)
  28. parse_to_ini
  29. (( game_counter++ ))
  30. fi
  31. done <<< "$tour_info"
  32. }
  33. function parse_to_ini {
  34. echo "[game${game_counter}]"
  35. echo "round = $round"
  36. [[ ! $date =~ \? ]] && echo "date = $date"
  37. echo "white = $white"
  38. echo "black = $black"
  39. [[ $result == "-" ]] || echo "result = \"$result\""
  40. echo
  41. }
  42. parse_setup
  43. # Configuration file for players
  44. ply_ini=${REPO_DIR}/${TOURNAMENT}/players.ini
  45. ply_count=$(grep "^\[player" "$ply_ini" | wc -l)
  46. tour_seq=$(ls -1 -d ${REPO_DIR}/${TOURNAMENT}/tours/[0-9][0-9]/ \
  47. | sed -E "s|${REPO_DIR}/${TOURNAMENT}/tours/([0-9]{2})/|\1|")
  48. game_counter=1
  49. for tour in $tour_seq; do
  50. parse_tour_info
  51. done
  52. exit 0