0

Hello i would like help for tic tac toe .. I want to do something when the 1st and the 2nd case is checked by a player ..

@echo off
setlocal EnableDelayedExpansion EnableExtensions
set case9=player
set case13=player
set case17=player
for /l %%a in (9, 4, 17) do (
    set x_case%%a=!case%%a!
    if "!x_case%%a!"=="player" if "!x_case%%a+%%a!"=="player" (
        batbox /g 17 14 /d " X "
    )
)
pause

It's named case 9 13 17 because of the length of the console and the tic tac toe grid. I want help and explanation about how can i do %%a + %%a, i tried

set plus_case=%%a+4
echo !case%plus_case%!

but it still don't work because we're in for section ... Thanks you for help and can you help me to find a title, i don't know what title can i put.

mirtexfr
  • 15
  • 1
  • Use `set /A plus_case=%%a+4` and then `call echo %%case!plus_case!%%` or `for %%i in (!plus_case!) do echo !case%%i!`. This management is explained at [this answer](http://stackoverflow.com/questions/10166386/arrays-linked-lists-and-other-data-structures-in-cmd-exe-batch-script/10167990#10167990) – Aacini Apr 09 '17 at 03:07

1 Answers1

0

Not really sure what you are trying to compare - but even had your code worked as you expected, you would be comparing case9 to case18, case13 to case26 and case17 to case34.

Even by adding 4, you'd be comparing case17 to case21

If you want to see whether at least 2 of the variables contain player then

@echo off
setlocal EnableDelayedExpansion EnableExtensions
set case9=player
set case13=player
set case17=player
set match=0
for /l %%a in (9, 4, 17) do (
    if "!case%%a!"=="player" set /a match+=1
)
if %match% geq 2  batbox /g 17 14 /d " X "

pause

Now quite what you actually want is not clear. The above line will execute batbox if 2 or 3 (Greater or EQual to 2) "player"s are found. If you want exactly 2, change geq to equ. If they have to be case13 and either case9 or case17 then it's probably easier to use

if "%case13%"=="player" if "%case13%"=="%case9%" (batbox /g 17 14 /d " X "
) else if "%case13%"=="%case17%" (batbox /g 17 14 /d " X ")
Magoo
  • 77,302
  • 8
  • 62
  • 84
  • in fact, i want to do `if "%case9%"=="checkbyplayer" and if "%case9%"=="checkbyplayer" set check13=checkbycomputer` and `if "%case17%"=="checkbyplayer" and if "%case13%"=="checkbyplayer" set check9=checkbycomputer` or `if "%case9%"=="checkbycomputer" and if "%case9%"=="checkbycomputer" set check13=checkbyplayer` and `if "%case17%"=="checkbycomputer" and if "%case13%"=="checkbycomputer" set check9=checkbyplayer` but more simply for my tic tac toe ... thanks for your proposition i misspoke. – mirtexfr Apr 09 '17 at 16:15