Script 'game-add': change the form of variable 'ply_names'.
This commit is contained in:
parent
00e146dd21
commit
9d31706c21
25
game-add
25
game-add
@ -106,7 +106,7 @@ function game_get_info {
|
|||||||
game_get_names
|
game_get_names
|
||||||
|
|
||||||
# Select the names of two players
|
# Select the names of two players
|
||||||
local players=( $(echo -en "$ply_names" | sort -u) )
|
local players=( $(echo -en "$ply_names" | sed "s/ /\\"$'\n'"/" | sort -u) )
|
||||||
[[ ${#players[@]} == 2 ]] || die "Players of the games are not the same."
|
[[ ${#players[@]} == 2 ]] || die "Players of the games are not the same."
|
||||||
|
|
||||||
# Find the white and black players
|
# Find the white and black players
|
||||||
@ -146,7 +146,9 @@ function game_get_names {
|
|||||||
local bk_lichess=$(sed -En "s/\[Black \"([^\"]*)\"\]/\1/p" $pgn)
|
local bk_lichess=$(sed -En "s/\[Black \"([^\"]*)\"\]/\1/p" $pgn)
|
||||||
|
|
||||||
game_add_player $wt_lichess
|
game_add_player $wt_lichess
|
||||||
|
ply_names+=" "
|
||||||
game_add_player $bk_lichess
|
game_add_player $bk_lichess
|
||||||
|
ply_names+="\n"
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -183,7 +185,7 @@ function game_add_player {
|
|||||||
echo -n "Type the name of ${lichess_ply}> "
|
echo -n "Type the name of ${lichess_ply}> "
|
||||||
read ply
|
read ply
|
||||||
done
|
done
|
||||||
ply_names+="${ply}\n"
|
ply_names+=$ply
|
||||||
}
|
}
|
||||||
|
|
||||||
function game_validate {
|
function game_validate {
|
||||||
@ -196,7 +198,7 @@ function game_validate {
|
|||||||
|
|
||||||
# Players' sides should interchange
|
# Players' sides should interchange
|
||||||
|
|
||||||
local length=$(( $(echo -en "$ply_names" | wc -l) / 2 ))
|
local length=$(echo -en "$ply_names" | wc -l)
|
||||||
if $ADD_GAMES && [[ -n $res_old ]]; then
|
if $ADD_GAMES && [[ -n $res_old ]]; then
|
||||||
local residue=$(( $(wc -w <<< "$res_old") % 2 ))
|
local residue=$(( $(wc -w <<< "$res_old") % 2 ))
|
||||||
else
|
else
|
||||||
@ -206,20 +208,22 @@ function game_validate {
|
|||||||
local ply_ordered=
|
local ply_ordered=
|
||||||
for ((i = 0; i < length; i++)); do
|
for ((i = 0; i < length; i++)); do
|
||||||
if (( i % 2 == residue )); then
|
if (( i % 2 == residue )); then
|
||||||
ply_ordered+="${white}\n${black}\n"
|
ply_ordered+="${white} ${black}\n"
|
||||||
else
|
else
|
||||||
ply_ordered+="${black}\n${white}\n"
|
ply_ordered+="${black} ${white}\n"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
# List found games
|
# List found games
|
||||||
echo "$(tput setaf 2)Found games:$(tput sgr0)"
|
echo "$(tput setaf 2)Found games:$(tput sgr0)"
|
||||||
game_display "$ply_names"
|
echo -en "$ply_ordered" \
|
||||||
|
| sed "s/ / - /;s/^/$(tput setaf 6)*$(tput sgr0) /"
|
||||||
|
|
||||||
if [[ "$ply_names" != "$ply_ordered" ]]; then
|
if [[ "$ply_names" != "$ply_ordered" ]]; then
|
||||||
# List expected games
|
# List expected games
|
||||||
echo "$(tput setaf 2)Expected games:$(tput sgr0)"
|
echo "$(tput setaf 2)Expected games:$(tput sgr0)"
|
||||||
game_display "$ply_ordered"
|
echo -en "$ply_ordered" \
|
||||||
|
| sed "s/ / - /;s/^/$(tput setaf 6)*$(tput sgr0) /"
|
||||||
|
|
||||||
local answer
|
local answer
|
||||||
echo -n "Approve games with wrong players' sides? (Y/n)> "
|
echo -n "Approve games with wrong players' sides? (Y/n)> "
|
||||||
@ -228,11 +232,6 @@ function game_validate {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function game_display {
|
|
||||||
echo -e "$1" | xargs -n2 \
|
|
||||||
| sed "s/ / - /;s/^/$(tput setaf 6)*$(tput sgr0) /"
|
|
||||||
}
|
|
||||||
|
|
||||||
function game_store_pgns {
|
function game_store_pgns {
|
||||||
game_dir=$(ls -1 -d 2>/dev/null \
|
game_dir=$(ls -1 -d 2>/dev/null \
|
||||||
${REPO_DIR}/${TOURNAMENT}/tours/${TOUR}/*-${white}-vs-${black})
|
${REPO_DIR}/${TOURNAMENT}/tours/${TOUR}/*-${white}-vs-${black})
|
||||||
@ -301,7 +300,7 @@ function game_get_result {
|
|||||||
|
|
||||||
result+=" $res"
|
result+=" $res"
|
||||||
(( res_index += 1 ))
|
(( res_index += 1 ))
|
||||||
done <<< "$(echo -e "$ply_names" | xargs -n2)"
|
done <<< "$(echo -e "$ply_names")"
|
||||||
|
|
||||||
$ADD_GAMES && [[ -n $res_old ]] && result=" ${res_old}${result}"
|
$ADD_GAMES && [[ -n $res_old ]] && result=" ${res_old}${result}"
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user