Here is the code for my function so far. It is supposed to calculate the Scrabble score of a phrase in a variable, and output the score to another variable.
Code: Select all
@echo off
set "myString=Hello"
call :scrabbleScore myString score
echo Phrase: %myString%
echo Score: %score%
pause >nul
exit /b
:scrabbleScore
setlocal enabledelayedexpansion
set "_=A!%~1!"
set #=0
for /l %%g in (12,-1,0) do (set /a "#|=1<<%%g"
for %%h in (!#!) do if "!_:~%%h,1!"=="" set /a "#&=~1<<%%g")
set "@=%1"
set "$=0"
for /l %%g in (1,1,%#%) do (
for %%h in (A a E e I i L l N n O o R r S s T t U u) do if !%@%:~%%g,1!==%%h set /a $+=1
for %%h in (D d G g) do if !%@%:~%%g,1!==%%h set /a $+=2
for %%h in (B b C c M m P p) do if !%@%:~%%g,1!==%%h set /a $+=3
for %%h in (F f H h V v W w Y y) do if !%@%:~%%g,1!==%%h set /a $+=4
for %%h in (K k) do if !%@%:~%%g,1!==%%h set /a $+=5
for %%h in (J j X x) do if !%@%:~%%g,1!==%%h set /a $+=8
for %%h in (Q q Z z) do if !%@%:~%%g,1!==%%h set /a $+=10
)
endlocal
if "%~2" neq "" set %~2=%$%
exit /b
Code: Select all
Phrase: Hello
Score: 8