Page 1 of 1

NFL fantasy league draft batch program. Thoughts?

Posted: 08 Sep 2020 18:08
by purpleglow
I'm trying to develop a fantasy league draft manager. I want it to color code players that get picked. The program seems to slow down when several players are selected. Any good ways to optimize this? I already feel like I am going to need a billion goto statements to update every players status.

Code: Select all

@echo off
cls

Set /A RB1=0
Set /A RB2=0
Set /A RB3=0

REM ======================
REM 2020 Draft Hero
REM ======================

:mainloop
cls

echo =====================
echo 2020 Draft Hero
echo =====================

echo.
echo RBs:
echo T1:
REM echo [001] Christian McCaffrey (CAR)
if %RB1%==0 echo [001] Christian McCaffrey (CAR)
if %RB1%==1 goto rb1show
:rb1return
REM echo [002] Saquon Barkley (NYG)
if %RB2%==0 echo [002] Saquon Barkley (NYG)
if %RB2%==1 goto rb2show
:rb2return
REM echo [003] Ezekiel Elliott (DAL)
if %RB3%==0 echo [003] Ezekiel Elliott (DAL)
if %RB3%==1 goto rb3show
:rb3return
echo [004] Alvin Kamara (NOR)
echo T2:
echo [005] Dalvin Cook (MIN)
echo [006] Derrick Henry (TEN)
echo [007] Clyde Edwards-Helaire (KAN)
echo [008] Austin Ekeler (LAC)
echo [009] Joe Mixon (CIN)

echo.
echo [x] exit
REM echo [WR] WR list
REM echo [RB] RB list
REM echo [QB] QB list
REM echo [TE] TE list
echo [123] number of player to draft (only 001, 002 and 003 have been coded so far)

REM get user input

set choice=
set /p choice=Draft a player!
if not '%choice%'=='' set choice=%choice:~0,3%
if '%choice%'=='x' goto end
if '%choice%'=='001' goto rb1
if '%choice%'=='002' goto rb2
if '%choice%'=='003' goto rb3
ECHO "%choice%" is not valid, try again
pause
goto mainloop

:rb1show

MD UniqueTempFolder
CD UniqueTempFolder
echo   ^x>"DRAFTED CHRISTIAN MCCAFFREY (CAR)"
findstr /A:0e /S "x" "DRAFTED CHRISTIAN MCCAFFREY (CAR)"
CD..
RD /S /Q UniqueTempFolder
goto rb1return

:rb1

Set /A RB1=1
goto mainloop

:rb1show

:rb2show

MD UniqueTempFolder
CD UniqueTempFolder
echo   ^x>"DRAFTED SAQUON BARKLEY (NYG)"
findstr /A:0e /S "x" "DRAFTED SAQUON BARKLEY (NYG)"
CD..
RD /S /Q UniqueTempFolder
goto rb2return

:rb2

Set /A RB2=1
goto mainloop

:rb2show

:rb3show

MD UniqueTempFolder
CD UniqueTempFolder
echo   ^x>"DRAFTED EZEKIEL ELLIOTT (DAL)"
findstr /A:0e /S "x" "DRAFTED EZEKIEL ELLIOTT (DAL)"
CD..
RD /S /Q UniqueTempFolder
goto rb3return

:rb3

Set /A RB3=1
goto mainloop

:rb3show

:end

Re: NFL fantasy league draft batch program. Thoughts?

Posted: 09 Sep 2020 14:12
by T3RRY
alot of what your doing to control choices could be achived with the actual choice command.

Code: Select all

Setlocal EnableDelayedExpansion
For %%v in (1 2 3)Do Set "rb%%v=0"
:Pick
For /F "Delims=" %%G in ('Choice /N /C 123')Do (If "!rb%%G!"=="0" (Set "rb%%G=1"&Goto RB%%G)Else (Echo/Pick %%G already Selected& Goto :Pick))
Additionally, the labels may be uneccessary if the commands being enacted within the label are simple enough. You could instead Assign a command or group of commands to an indexed variable as a macro.

A couple of pointers:

The syntax for If condition testing when comparing strings Should be:

Code: Select all

If "String"=="value" (Command)
or

Code: Select all

If "String"=="value" (Command)Else (Other command)
With the /I switch used when case is to be ignored: If /I "string"=="value" ...

This syntax is used as Doublequotes provide an element of protection against 'poison' characters when performing string comparisons - especially important when taking input via Set /P. Characters other than doublequotes do not afford the same certainty regardings the scripts safe execution.

Variable naming conventions:
Variables names should idealy be meaningful to enhance script readability - for yourself and others. If you use a meaningful variable name, you'll know at a glance what it's being used for.
Concise or abbreviated Variable names can be used, and there is an advantage where long/complex scripts are concerned with regards to performance - however remarks at the point of definition describing what they are used to achieve / track will help not only you in keeping track of what different components of your script are for, but in allowing others to read it and understand the purpose of it's component parts without having to chase down what's doing which thing where. - It's definitely worth making the effort in when asking for help /opinions from others.

Script Design:
Begin your script not with code, but with goals. Detail what you want to achieve, what options / menus / features etc you wish to present and list methods / tools or scripting techniques that you can or will use to achieve those outcomes. It'll save you a tonne of time. Once the script is finished, you can do away with the Build plan.

Lastly: Version Control
When implementing Changes, Save and test as a copy.

A few batch techniques for you to research that may enlighten you to ways of handling variables in more powerful way in batch:
- Batch Macro's with parameters
- Command Macro's with Substring Modification
- Functions
----- the above are diferent ways that allow you to reuse blocks of code to handle similar Sets of commands /actions or Data types
In addition to the above techniques, consider developing an undestanding of the diferent ways of processing or using variables in batch, from substring modification to indexed lists and arrays