Skip to content

Commit

Permalink
tools: small fixes, add appraise-deck.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
dsuchka committed Oct 22, 2023
1 parent e3b73fa commit 40fc05c
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 6 deletions.
4 changes: 2 additions & 2 deletions data/bges.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Combined Arms: Enhance All Coalition 10; Rally all 10; Enfeeble all 10; Strike a
//Combined Arms: Rally all 10; Enfeeble all 10; Strike all 10
Inspired: Rally all 25
Blightblast: Enfeeble all 35
Emergency Aid: Heal All 10; Protect all 10; Enhance all Absorb 125
Emergency Aid: Enhance all Absorb 125; Heal All 10; Protect all 10
Landmine: Entrap all 25; Weaken all 25
Triage: Enhance all Fortify 35; Heal 25; Protect 25
//Triage: Heal 25; Protect 25
Expand Down Expand Up @@ -162,4 +162,4 @@ Blood Lust: Enhance all Leech 2
Blood Frenzy: Enhance all Leech 3
Noxious Fog: Enhance all Poison 1
Noxious Mist: Enhance all Poison 2
Noxious Haze: Enhance all Poison 3
Noxious Haze: Enhance all Poison 3
4 changes: 2 additions & 2 deletions data/download-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
curr_dir=$(dirname "$0")
olds_dir="$curr_dir/old-xmls.d"

#BASE_URL="https://mobile.tyrantonline.com/assets/"
BASE_URL="https://mobile-dev.tyrantonline.com/assets/"
BASE_URL="https://mobile.tyrantonline.com/assets/"
#BASE_URL="https://mobile-dev.tyrantonline.com/assets/"
FILES=(
fusion_recipes_cj2.xml
missions.xml
Expand Down
72 changes: 72 additions & 0 deletions tools/appraise-deck.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#!/bin/bash

#SUFFIX="virulence"
#SUFFIX="avenge"
#SUFFIX="flux"
#SUFFIX="SF_SF_x_TC"
INPUT_FILE="$1"
OUTPUT_FILE="${2:-$(dirname "$1")/appraised-deck${SUFFIX:+.${SUFFIX}}.$(basename "$1")}"

declare -i ITERS=5000

DECK="Razogoth Immortal, Krellus' Nexus, Infernal Diabolic, Megalift Foundry, Cleave Condemner, Megalift Foundry, Gaia's Specialist, Armada Xonar, Cleave Condemner, Mephalus Gorge, Infernal Diabolic, Armada Xonar"

TUO_OPTIONS=(
brawl
-t 4
#-e "Virulence"
no-db
no-ml
)

TMP_DIR="/tmp"
TMP_FILE_PREFIX="."
TMP_FILE_SUFFIX=".$(basename "$1" ".txt").appraising-deck~"

die() {
echo " ** ERROR ** $@" 1>&2
exit 255
}

msg() {
echo "[$(date +%F' '%T)] $@"
}

# check input file
[[ -f $INPUT_FILE ]] || die "Bad input file (no such file or file isn't regular): $INPUT_FILE"

# reset output file or die
:> "$OUTPUT_FILE" || die "Can't open file for writing: $OUTPUT_FILE"

# show start message
msg "Starting appraise deck (reorder per enemy) for gauntlet $INPUT_FILE (output to $OUTPUT_FILE)"

IFS=$'\n'
while read -r line; do
if [[ $line =~ (^[a-zA-Z0-9_.+-]+[^:]+):\ ([^/].+[^/])$ ]]; then
user="${BASH_REMATCH[1]}"
deck="${BASH_REMATCH[2]}"
msg "Reordering deck against $user ..."
TMP_FILE="${TMP_DIR}/${TMP_FILE_PREFIX}${user}${SUFFIX:+.${SUFFIX}}${TMP_FILE_SUFFIX}"
[[ -f $TMP_FILE ]] && die "Temporary file already exists: $TMP_FILE"
tuo.sh "$DECK" "$deck" "${TUO_OPTIONS[@]}" reorder $ITERS &> "$TMP_FILE" &
declare -i tuo_pid=$!
wait $tuo_pid
result_line=$(tail -n3 "$TMP_FILE" | fgrep 'Optimized Deck:' )
if [[ $result_line =~ ^Optimized\ Deck:.*\ \(([0-9.]+)%\ win\)\ ([0-9.]+)(\ \[([0-9.]+)\ per\ win\])?:\ ([^:]+)$ ]]; then
opt_winrate="${BASH_REMATCH[1]}"
opt_score="${BASH_REMATCH[2]}"
opt_win_score="${BASH_REMATCH[4]}"
opt_deck="${BASH_REMATCH[5]}"
echo "$(printf "%-8s %-8s %-8s" "$opt_winrate" "$opt_score" "$opt_win_score") $user: $opt_deck" >> "$OUTPUT_FILE"
rm -rf "$TMP_FILE"
else
die "Failed at $user (deck: $deck), see $TMP_FILE for more details"
fi
else
echo "$line" >> "$OUTPUT_FILE"
fi
done < "$INPUT_FILE"

# show finish message
msg "Appraising deck finished"
3 changes: 3 additions & 0 deletions tools/appraise-gauntlet.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ TUO_OPTIONS=(
# enemy is defender (in surge mode) / with IA(2) against MF / use valid custom BGEs!
#ee "Tartarian Gift"
#ye "Progenitor Tech"

no-db
no-ml
)

TMP_DIR="/tmp"
Expand Down
3 changes: 3 additions & 0 deletions tools/reorder-gauntlet.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ TUO_OPTIONS=(
# enemy is defender (in surge mode) / with IA(2) against MF / use valid custom BGEs!
#ee "Divine Blessing"
#ye "Divine Blessing"

no-db
no-ml
)

TMP_DIR="/tmp"
Expand Down
5 changes: 3 additions & 2 deletions tools/tu-deck-grabber.py
Original file line number Diff line number Diff line change
Expand Up @@ -666,10 +666,11 @@ def doHuntAndEnrichUserDb(client):
if user_db._dirty:
user_db._dirty = False
tmp_udb_fname = udb_fname + '~'
old_udb_fname = udb_fname + '.old'
with open(tmp_udb_fname, 'wb') as f:
pickle.dump(user_db, f)
if (os.path.exists(udb_fname)):
os.remove(udb_fname)
os.renames(udb_fname, old_udb_fname)
os.renames(tmp_udb_fname, udb_fname)
print('INFO: user-db: synced to disk: {} (total {} entries)'.format(udb_fname, user_db.size()))

Expand Down Expand Up @@ -847,7 +848,7 @@ def doGrabLastDeck(client):
continue
if args[0] == 'salvage':
if len(args) < 2:
print('USAGE: salvage <CARD_ID|commons|rares> [CARD_ID:COUNT]')
print('USAGE: salvage <CARD_ID|commons|rares> [COUNT]')
continue
if args[1] == 'commons':
rsp = client.salvageL1CommonCards()
Expand Down
3 changes: 3 additions & 0 deletions tools/tuo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ if (( ! found_ownedcards )) && (( TUO_RESTRICT_OWNEDCARDS )); then
ARGS+=("-o=${TUO_ROOT}/data/ownedcards_${TUO_LOGIN}.txt")
fi

## ignore db/ml
ARGS+=(no-db no-ml)

## append globally exported tuo flags
ARGS+=($TUO_FLAGS)

Expand Down

0 comments on commit 40fc05c

Please sign in to comment.