2013-10-01 10:28:23 +04:00
|
|
|
|
#!/usr/bin/env bash
|
2015-01-09 16:09:52 +04:00
|
|
|
|
# Copyright 2014, 2015 Vladimir Ivanov <ivvl82@gmail.com>
|
2014-09-06 14:13:45 +04:00
|
|
|
|
# Distributed under the terms of the GNU General Public License v2
|
2013-10-01 10:28:23 +04:00
|
|
|
|
|
2014-09-06 14:13:45 +04:00
|
|
|
|
REPO_DIR=
|
2013-10-01 10:28:23 +04:00
|
|
|
|
|
2014-09-06 14:13:45 +04:00
|
|
|
|
# Specify the tournament here
|
|
|
|
|
TOURNAMENT=
|
2013-10-01 10:28:23 +04:00
|
|
|
|
|
2014-09-06 14:13:45 +04:00
|
|
|
|
function parse_setup {
|
2015-01-08 14:26:28 +04:00
|
|
|
|
: ${REPO_DIR:=`dirname "$0"`}
|
2013-10-01 10:28:23 +04:00
|
|
|
|
|
2014-09-06 14:13:45 +04:00
|
|
|
|
# If no tournament given, set it to the last one
|
|
|
|
|
if [[ -z $TOURNAMENT ]]; then
|
|
|
|
|
local year_dir=$(ls -1 -d ${REPO_DIR}/[0-9][0-9][0-9][0-9]/ | tail -1)
|
|
|
|
|
TOURNAMENT=$(ls -1 -d ${year_dir}[0-9]-*/ | tail -1 \
|
2015-01-08 14:26:28 +04:00
|
|
|
|
| sed -E "s|${REPO_DIR}/(.*)/|\1|")
|
2014-09-06 14:13:45 +04:00
|
|
|
|
fi
|
|
|
|
|
}
|
2013-10-01 10:28:23 +04:00
|
|
|
|
|
2014-09-06 14:13:45 +04:00
|
|
|
|
function parse_tour_info {
|
|
|
|
|
# Add a newline at the end of 'tour_info' to parse the last line
|
|
|
|
|
local tour_info=$(cat "${REPO_DIR}/${TOURNAMENT}/tours/${tour}/tour_info"; echo)
|
2013-10-01 10:28:23 +04:00
|
|
|
|
|
2014-09-06 14:13:45 +04:00
|
|
|
|
local date_re="[0-9?]{2}\.[0-9?]{2}\.[0-9?]{4}"
|
2015-01-06 01:28:25 +04:00
|
|
|
|
local res_re="(1|½|0|\+|−)"
|
2014-09-06 14:13:45 +04:00
|
|
|
|
while read line; do
|
2015-01-01 15:25:01 +04:00
|
|
|
|
if [[ $line =~ ^($date_re)\ +([^\ ]+)\ +-\ +([^\ ]+)(\ +$res_re-$res_re)? ]]; then
|
2014-09-06 14:13:45 +04:00
|
|
|
|
local date=${BASH_REMATCH[1]}
|
|
|
|
|
local white=${BASH_REMATCH[2]}
|
|
|
|
|
local black=${BASH_REMATCH[3]}
|
2015-01-01 15:25:01 +04:00
|
|
|
|
local result=${BASH_REMATCH[5]}-${BASH_REMATCH[6]}
|
2014-09-06 14:13:45 +04:00
|
|
|
|
local round=$(echo "($tour - 1)/($ply_count - 1) + 1" | bc)
|
|
|
|
|
parse_to_ini
|
2015-01-09 16:09:52 +04:00
|
|
|
|
(( game_counter++ ))
|
2013-10-01 10:28:23 +04:00
|
|
|
|
fi
|
|
|
|
|
done <<< "$tour_info"
|
2014-09-06 14:13:45 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function parse_to_ini {
|
|
|
|
|
echo "[game${game_counter}]"
|
|
|
|
|
echo "round = $round"
|
2014-09-06 14:20:41 +04:00
|
|
|
|
[[ ! $date =~ \? ]] && echo "date = $date"
|
2014-09-06 14:13:45 +04:00
|
|
|
|
echo "white = $white"
|
|
|
|
|
echo "black = $black"
|
2015-01-01 15:25:01 +04:00
|
|
|
|
[[ $result == "-" ]] || echo "result = \"$result\""
|
2014-09-06 14:13:45 +04:00
|
|
|
|
echo
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
parse_setup
|
|
|
|
|
# Configuration file for players
|
|
|
|
|
ply_ini=${REPO_DIR}/${TOURNAMENT}/players.ini
|
|
|
|
|
|
|
|
|
|
ply_count=$(grep "^\[player" "$ply_ini" | wc -l)
|
|
|
|
|
tour_seq=$(ls -1 -d ${REPO_DIR}/${TOURNAMENT}/tours/[0-9][0-9]/ \
|
2015-01-08 14:26:28 +04:00
|
|
|
|
| sed -E "s|${REPO_DIR}/${TOURNAMENT}/tours/([0-9]{2})/|\1|")
|
2014-09-06 14:13:45 +04:00
|
|
|
|
|
|
|
|
|
game_counter=1
|
|
|
|
|
for tour in $tour_seq; do
|
|
|
|
|
parse_tour_info
|
2013-10-01 10:28:23 +04:00
|
|
|
|
done
|
2014-09-06 14:13:45 +04:00
|
|
|
|
|
|
|
|
|
exit 0
|