forked from theonlydude/RandomMetroidSolver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_jm.sh
executable file
·173 lines (151 loc) · 4.8 KB
/
test_jm.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#!/bin/bash
LOG=test_jm.log
> ${LOG}
#> test_jm.err
#> test_jm.csv
if [ $# -ne 2 -a $# -ne 3 ]; then
echo "params: ROM LOOPS [COMPARE]"
exit -1
fi
#ROM=~/supermetroid_random/Super_Metroid_JU.smc
ROM=$1
LOOPS=$2
if [ -n "$3" ]; then
COMPARE=0
else
COMPARE=1
fi
# get git head
if [ ${COMPARE} -eq 0 ]; then
TEMP_DIR=$(mktemp)
rm -f ${TEMP_DIR}
mkdir -p ${TEMP_DIR}
(
cd ${TEMP_DIR}
git clone git@github.com:theonlydude/RandomMetroidSolver.git
cd RandomMetroidSolver
#git reset --hard 14e9088f07f64e093c53b773b016f5042765044b
)
ORIG=${TEMP_DIR}/RandomMetroidSolver/
else
ORIG=.
fi
PRESETS=("regular" "noob" "master")
AREAS=("" "--area")
BOSSES=("" "--bosses")
function generate_params {
SEED="$1"
PRESET="$2"
let S=$RANDOM%${#AREAS[@]}
AREA=${AREAS[$S]}
let S=$RANDOM%${#BOSSES[@]}
BOSS=${BOSSES[$S]}
echo "-r ${ROM} --param standard_presets/${PRESET}.json --seed ${SEED} --progressionSpeed random --morphPlacement random --progressionDifficulty random --missileQty 0 --superQty 0 --powerBombQty 0 --minorQty 0 --energyQty random --majorsSplit random --suitsRestriction random --hideItems random --strictMinors random --superFun CombatRandom --superFun MovementRandom --superFun SuitsRandom --maxDifficulty random ${AREA} ${BOSS}"
}
function computeSeed {
# generate seed
let P=$RANDOM%${#PRESETS[@]}
PRESET=${PRESETS[$P]}
SEED="$RANDOM"
PARAMS=$(generate_params "${SEED}" "${PRESET}")
CSV=test_jm.csv
if [ ! -s "${CSV}" ]; then
echo "seed;diff_cap;rtime old;rtime new;stime old;stime new;;md5sum ok;params;" | tee -a ${CSV}
fi
if [ ${COMPARE} -eq 0 ]; then
OLD_MD5="old n/a"
OUT=$(/usr/bin/time -f "\t%E real" python2 ${ORIG}/randomizer.py ${PARAMS} 2>&1)
if [ $? -ne 0 ]; then
OLD="error"
echo "${OUT}" >> ${LOG}
else
RTIME_OLD=$(echo "${OUT}" | grep real | awk '{print $1}')
ROM_GEN=$(ls -1 VARIA_Randomizer_*X${SEED}_${PRESET}.sfc 2>/dev/null)
if [ $? -eq 0 ]; then
OLD_MD5=$(md5sum ${ROM_GEN} | awk '{print $1}')
fi
fi
fi
NEW_MD5="new n/a"
OUT=$(/usr/bin/time -f "\t%E real" python2 ./randomizer.py ${PARAMS} 2>&1)
if [ $? -ne 0 ]; then
RTIME_NEW="n/a"
else
RTIME_NEW=$(echo "${OUT}" | grep real | awk '{print $1}')
ROM_GEN=$(ls -1 VARIA_Randomizer_*X${SEED}_${PRESET}.sfc 2>/dev/null)
if [ $? -eq 0 ]; then
NEW_MD5=$(md5sum ${ROM_GEN} | awk '{print $1}')
fi
fi
if [ "${OLD_MD5}" != "${NEW_MD5}" -a ${COMPARE} -eq 0 ]; then
if [ "${OLD_MD5}" = "old n/a" ] && [ "${NEW_MD5}" = "new n/a" ]; then
MD5="n/a"
else
MD5="mismatch"
echo "OLD: ${OLD_MD5} NEW: ${NEW_MD5}"
STOP="now"
fi
else
MD5=${NEW_MD5}
fi
# solve seed
ROM_GEN=$(ls -1 VARIA_Randomizer_*X${SEED}_${PRESET}.sfc)
if [ $? -ne 0 ]; then
echo "error;${SEED};${DIFF_CAP};${RTIME_OLD};${RTIME_NEW};${STIME_OLD};${STIME_NEW};${MD5};${PARAMS};" | tee -a ${CSV}
exit 0
fi
if [ ${COMPARE} -eq 0 ]; then
OUT=$(/usr/bin/time -f "\t%E real" python2 ${ORIG}/solver.py -r ${ROM_GEN} --preset standard_presets/${PRESET}.json -g --checkDuplicateMajor 2>&1) > ${ROM_GEN}.old
if [ $? -ne 0 ]; then
echo "${SEED};${DIFF_CAP};${RTIME_OLD};${RTIME_NEW};${STIME_OLD};${STIME_NEW};${MD5};${PARAMS};" | tee -a ${CSV}
echo "Can't solve ${ROM_GEN}" | tee -a ${CSV}
exit 0
STIME_OLD="n/a"
else
STIME_OLD=$(echo "${OUT}" | grep real | awk '{print $1}')
echo "${OUT}" | grep -q "has already been picked up"
DUP_OLD=$?
fi
else
DUP_OLD=1
fi
OUT=$(/usr/bin/time -f "\t%E real" python2 ./solver.py -r ${ROM_GEN} --preset standard_presets/${PRESET}.json -g --checkDuplicateMajor 2>&1) > ${ROM_GEN}.new
if [ $? -ne 0 ]; then
echo "${SEED};${DIFF_CAP};${RTIME_OLD};${RTIME_NEW};${STIME_OLD};${STIME_NEW};${MD5};${PARAMS};" | tee -a ${CSV}
echo "Can't solve ${ROM_GEN}" | tee -a ${CSV}
exit 0
STIME_NEW="n/a"
else
STIME_NEW=$(echo "${OUT}" | grep real | awk '{print $1}')
echo "${OUT}" | grep -q "has already been picked up"
DUP_NEW=$?
fi
if [ ${DUP_NEW} -eq 0 -o ${DUP_OLD} -eq 0 ]; then
DUP="dup major detected"
fi
echo "${SEED};${DIFF_CAP};${RTIME_OLD};${RTIME_NEW};${STIME_OLD};${STIME_NEW};${MD5};${PARAMS};${DUP}" | tee -a ${CSV}
if [ ${COMPARE} -eq 0 ]; then
DIFF=$(diff ${ROM_GEN}.old ${ROM_GEN}.new)
if [ -z "${DIFF}" ]; then
rm -f ${ROM_GEN} ${ROM_GEN}.new ${ROM_GEN}.old
echo "${SEED};${ROM_GEN};SOLVER;${PRESET};OK;" | tee -a test_jm.csv
else
echo "${SEED};${ROM_GEN};SOLVER;${PRESET};NOK;" | tee -a test_jm.csv
STOP="now"
fi
fi
}
STOP=""
let LOOPS=${LOOPS}/4
for i in $(seq 1 ${LOOPS}); do
computeSeed &
computeSeed &
computeSeed &
computeSeed &
wait
if [ "${STOP}" = "now" ]; then
exit 1
fi
done
echo "DONE"
rm -rf ${TEMP_DIR}