Batch Games

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
misol101
Posts: 465
Joined: 02 May 2016 18:20

Re: Batch Games

#16 Post by misol101 » 25 Sep 2020 16:20

Lowsun wrote:
25 Sep 2020 15:17
I have also made lots of pure Batch games like platformers, rogue-likes, and other stuff. They're are all here

https://lowsun.itch.io/
These are nice. Maybe not so much for the gameplay, but because you create an atmosphere with the story+music.

Lowsun
Posts: 15
Joined: 14 Apr 2019 17:22

Re: Batch Games

#17 Post by Lowsun » 25 Sep 2020 16:54

@misol101

Thanks. I had a hard time adding stuff to make gameplay better, since the performance would drop really low, or it would be unwieldy in batch. But yeah, I tried to compensate with some extra effort into story.

T3RRY
Posts: 96
Joined: 06 May 2020 10:14

Re: Batch Games

#18 Post by T3RRY » 01 Oct 2020 23:05

Untitled: 16595 bytes
Cat wrote:
25 Apr 2012 19:15
Coded this a LONG time ago. Horrible coding, but it's too big for me to really redo.

Code: Select all

@ECho off
:s
set a1=_&set a2=_&set a3=_&set a4=_&set b1=_&set b2=_&set b3=_&set b4=_&set c1=_&set c2=_&set c3=_&set c4=_
set d3=_&set d4=_&set e1=_&set e2=_&set e3=_&set e4=_&set f1=_&set f2=_&set f3=_&set f4=_&set d1=_&set d2=_
set moves=0&set AC=1&set BC=1&set CC=1&set DC=1&set FC=1&set EC=1
cls&call :board
:start
call :player
call :winlist
GOTO :computer
:AFTER
set /a moves= %moves% + 1
if %moves%==12 goto tie
GOTO START
:player
call :board&set /p P1="ENTER A LETTER:"
if /i %p1%%AC%==A1 set A1=X&Set /a AC= %AC%+1&EXIT /B
if /i %p1%%AC%==A2 set A2=X&Set /a AC= %AC%+1&EXIT /B
if /i %p1%%AC%==A3 set A3=X&Set /a AC= %AC%+1&EXIT /B
if /i %p1%%AC%==A4 set A4=X&Set /a AC= %AC%+1&EXIT /B
if /i %p1%%BC%==B1 set B1=X&set /a BC= %BC%+1&EXIT /B
if /i %p1%%BC%==B2 set B2=X&set /a BC= %BC%+1&EXIT /B
if /i %p1%%BC%==B3 set B3=X&set /a BC= %BC%+1&EXIT /B
if /i %p1%%BC%==B4 set B4=X&set /a BC= %BC%+1&EXIT /B
if /i %p1%%CC%==C1 set C1=X&set /a CC= %CC%+1&EXIT /B
if /i %p1%%CC%==C2 set C2=X&set /a CC= %CC%+1&EXIT /B
if /i %p1%%CC%==C3 set C3=X&set /a CC= %CC%+1&EXIT /B
if /i %p1%%CC%==C4 set C4=X&set /a CC= %CC%+1&EXIT /B
if /i %p1%%DC%==D1 set D1=X&set /a DC= %DC%+1&EXIT /B
if /i %p1%%DC%==D2 set D2=X&set /a DC= %DC%+1&EXIT /B
if /i %p1%%DC%==D3 set D3=X&set /a DC= %DC%+1&EXIT /B
if /i %p1%%DC%==D4 set D4=X&set /a DC= %DC%+1&EXIT /B
if /i %p1%%EC%==E1 set E1=X&set /a EC= %EC%+1&EXIT /B
if /i %p1%%EC%==E2 set E2=X&set /a EC= %EC%+1&EXIT /B
if /i %p1%%EC%==E3 set E3=X&set /a EC= %EC%+1&EXIT /B
if /i %p1%%EC%==E4 set E4=X&set /a EC= %EC%+1&EXIT /B
if /i %p1%%FC%==F1 set F1=X&set /a FC= %FC%+1&EXIT /B
if /i %p1%%FC%==F2 set F2=X&set /a FC= %FC%+1&EXIT /B
if /i %p1%%FC%==F3 set F3=X&set /a FC= %FC%+1&EXIT /B
if /i %p1%%FC%==F4 set F4=X&set /a FC= %FC%+1&EXIT /B
ECHO Invalid&timeout /t 1 /nobreak>nul&GOTO START
:COMPUTER
CALL :ATTACKER
CALL :DEFENDER
:RANDOMERROR
set /a N=%random% %% 6 
IF %N%%AC%==05 GOTO RANDOMERROR
IF %N%%BC%==15 GOTO RANDOMERROR
IF %N%%CC%==25 GOTO RANDOMERROR
IF %N%%DC%==35 GOTO RANDOMERROR
IF %N%%EC%==45 GOTO RANDOMERROR
IF %N%%FC%==55 GOTO RANDOMERROR
IF %N%==0 SET A%AC%=O&SET /A AC= %AC%+1
IF %N%==1 SET B%BC%=O&SET /A BC= %BC%+1
IF %N%==2 SET C%CC%=O&SET /A CC= %CC%+1
IF %N%==3 SET D%DC%=O&SET /A DC= %DC%+1
IF %N%==4 SET E%EC%=O&SET /A EC= %EC%+1
IF %N%==5 SET F%FC%=O&SET /A FC= %FC%+1
call :board&GOTO AFTER
:lose 
call :board&ECho Computer wins&ECho.&ECho Press any key to restart&pause>nul&goto s
:tie
call :board&ECho Tie&ECho.&ECho Press any key to restart&pause>nul&goto s
:win
call :board&EChO You Win&ECho.&ECho Press any key to restart&pause>nul&goto s
:board
cls&ECho.&ECho  _ _ _ _ _ _&ECho ^|%A4%^|%B4%^|%C4%^|%D4%^|%E4%^|%F4%^|
ECho ^|%A3%^|%B3%^|%C3%^|%D3%^|%E3%^|%F3%^|&ECho ^|%A2%^|%B2%^|%C2%^|%D2%^|%E2%^|%F2%^|
ECho ^|%A1%^|%B1%^|%C1%^|%D1%^|%E1%^|%F1%^|&ECho  A B C D E F&ECho.&exit /b
:defender
if %A1%%A2%%A3%%A4%==XXX_ set A4=O&set /a AC= %AC%+1& GOTO AFTER
if %A1%%A2%%A3%%A4%==XX_X set A3=O&set /a AC= %AC%+1& GOTO AFTER
if %A1%%A2%%A3%%A4%==X_XX set A2=O&set /a AC= %AC%+1& GOTO AFTER
if %A1%%A2%%A3%%A4%==_XXX set A1=O&set /a AC= %AC%+1& GOTO AFTER
if %B1%%B2%%B3%%B4%==XXX_ set B4=O&set /a BC= %BC%+1& GOTO AFTER
if %B1%%B2%%B3%%B4%==XX_X set B3=O&set /a BC= %BC%+1& GOTO AFTER
if %B1%%B2%%B3%%B4%==X_XX set B2=O&set /a BC= %BC%+1& GOTO AFTER
if %B1%%B2%%B3%%B4%==_XXX set B1=O&set /a BC= %BC%+1& GOTO AFTER
if %C1%%C2%%C3%%C4%==XXX_ set C4=O&set /a CC= %CC%+1& GOTO AFTER
if %C1%%C2%%C3%%C4%==XX_X set C3=O&set /a CC= %CC%+1& GOTO AFTER
if %C1%%C2%%C3%%C4%==X_XX set C2=O&set /a CC= %CC%+1& GOTO AFTER
if %C1%%C2%%C3%%C4%==_XXX set C1=O&set /a CC= %CC%+1& GOTO AFTER
if %D1%%D2%%D3%%D4%==XXX_ set D4=O&set /a DC= %DC%+1& GOTO AFTER
if %D1%%D2%%D3%%D4%==XX_X set D3=O&set /a DC= %DC%+1& GOTO AFTER
if %D1%%D2%%D3%%D4%==X_XX set D2=O&set /a DC= %DC%+1& GOTO AFTER
if %D1%%D2%%D3%%D4%==_XXX set D1=O&set /a DC= %DC%+1& GOTO AFTER
if %E1%%E2%%E3%%E4%==XXX_ set E4=O&set /a EC= %EC%+1& GOTO AFTER
if %E1%%E2%%E3%%E4%==XX_X set E3=O&set /a EC= %EC%+1& GOTO AFTER
if %E1%%E2%%E3%%E4%==X_XX set E2=O&set /a EC= %EC%+1& GOTO AFTER
if %E1%%E2%%E3%%E4%==_XXX set E1=O&set /a EC= %EC%+1& GOTO AFTER
if %F1%%F2%%F3%%F4%==XXX_ set F4=O&set /a FC= %FC%+1& GOTO AFTER
if %F1%%F2%%F3%%F4%==XX_X set F3=O&set /a FC= %FC%+1& GOTO AFTER
if %F1%%F2%%F3%%F4%==X_XX set F2=O&set /a FC= %FC%+1& GOTO AFTER
if %F1%%F2%%F3%%F4%==_XXX set F1=O&set /a FC= %FC%+1& GOTO AFTER
if %A4%%b4%%c4%%d4%==XXX_ if NOT %d3%==_ set d4=O&Set /a DC= %DC%+1& GOTO AFTER
if %A4%%b4%%c4%%d4%==XX_X if NOT %d3%==_ set c4=O&set /a CC= %CC%+1& GOTO AFTER
if %A4%%b4%%c4%%d4%==X_XX if NOT %d3%==_ set b4=O&set /a BC= %BC%+1& GOTO AFTER
if %A4%%b4%%c4%%d4%==_XXX if NOT %d3%==_ set A4=O&set /a AC= %AC%+1& GOTO AFTER
if %A3%%b3%%c3%%d3%==XXX_ if NOT %d2%==_ set d3=O&set /a DC= %DC%+1& GOTO AFTER
if %A3%%b3%%c3%%d3%==XX_X if NOT %c2%==_ set c3=O&set /a CC= %CC%+1& GOTO AFTER
if %A3%%b3%%c3%%d3%==X_XX if NOT %b2%==_ set b3=O&set /a BC= %BC%+1& GOTO AFTER
if %A3%%b3%%c3%%d3%==_XXX if NOT %a2%==_ set A3=O&set /a AC= %AC%+1& GOTO AFTER
if %A2%%b2%%c2%%d2%==XXX_ if NOT %d1%==_ set d2=O&set /a DC= %DC%+1& GOTO AFTER
if %A2%%b2%%c2%%d2%==XX_X if NOT %c1%==_ set c2=O&set /a CC= %CC%+1& GOTO AFTER
if %A2%%b2%%c2%%d2%==X_XX if NOT %b1%==_ set b2=O&set /a BC= %BC%+1& GOTO AFTER
if %A2%%b2%%c2%%d2%==_XXX if NOT %a1%==_ set A2=O&set /a AC= %AC%+1& GOTO AFTER
if %A1%%b1%%c1%%d1%==XXX_ set d1=O&set /a DC= %DC%+1& GOTO AFTER
if %A1%%b1%%c1%%d1%==XX_X set c1=O&set /a CC= %CC%+1& GOTO AFTER
if %A1%%b1%%c1%%d1%==X_XX set b1=O&set /a BC= %BC%+1& GOTO AFTER
if %A1%%b1%%c1%%d1%==_XXX set A1=O&set /a AC= %AC%+1& GOTO AFTER
if %b4%%c4%%d4%%e4%==XXX_ if NOT %e3%==_ set e3=O&set /a EC= %EC%+1& GOTO AFTER
if %b4%%c4%%d4%%e4%==XX_X if NOT %d3%==_ set d3=O&set /a DC= %DC%+1& GOTO AFTER
if %b4%%c4%%d4%%e4%==X_XX if NOT %c3%==_ set c3=O&set /a CC= %CC%+1& GOTO AFTER
if %b4%%c4%%d4%%e4%==_XXX if NOT %b3%==_ set b3=O&set /a BC= %BC%+1& GOTO AFTER
if %b3%%c3%%d3%%e3%==XXX_ if NOT %e2%==_ set e2=O&set /a EC= %EC%+1& GOTO AFTER
if %b3%%c3%%d3%%e3%==XX_X if NOT %d2%==_ set d2=O&set /a DC= %DC%+1& GOTO AFTER
if %b3%%c3%%d3%%e3%==X_XX if NOT %c2%==_ set c3=O&set /a CC= %CC%+1& GOTO AFTER
if %b3%%c3%%d3%%e3%==_XXX if NOT %b2%==_ set b3=O&set /a BC= %BC%+1& GOTO AFTER
if %b2%%c2%%d2%%e2%==XXX_ if NOT %e1%==_ set e2=O&set /a EC= %EC%+1& GOTO AFTER
if %b2%%c2%%d2%%e2%==XX_X if NOT %d1%==_ set d2=O&set /a DC= %DC%+1& GOTO AFTER
if %b2%%c2%%d2%%e2%==X_XX if NOT %c1%==_ set c2=O&set /a CC= %CC%+1& GOTO AFTER
if %b2%%c2%%d2%%e2%==_XXX if NOT %b1%==_ set b2=O&set /a BC= %BC%+1& GOTO AFTER
if %b1%%c1%%d1%%e1%==XXX_ set e1=O&set /a EC= %EC%+1& GOTO AFTER
if %b1%%c1%%d1%%e1%==XX_X set d1=O&set /a DC= %DC%+1& GOTO AFTER
if %b1%%c1%%d1%%e1%==X_XX set c1=O&set /a CC= %CC%+1& GOTO AFTER
if %b1%%c1%%d1%%e1%==_XXX set b1=O&set /a BC= %BC%+1& GOTO AFTER
if %c4%%d4%%e4%%f4%==XXX_ if NOT %f3%==_ set F4=O&set /a FC= %FC%+1& GOTO AFTER
if %c4%%d4%%e4%%f4%==XX_X if NOT %e3%==_ set E4=O&set /a EC= %EC%+1& GOTO AFTER
if %c4%%d4%%e4%%f4%==X_XX if NOT %d3%==_ set D4=O&set /a DC= %DC%+1& GOTO AFTER
if %c4%%d4%%e4%%f4%==_XXX if NOT %c3%==_ set C4=O&set /a CC= %CC%+1& GOTO AFTER
if %c3%%d3%%e3%%f3%==XXX_ if NOT %f2%==_ set F3=O&set /a FC= %FC%+1& GOTO AFTER
if %c3%%d3%%e3%%f3%==XX_X if NOT %e2%==_ set E3=O&set /a EC= %EC%+1& GOTO AFTER
if %c3%%d3%%e3%%f3%==X_XX if NOT %d2%==_ set D3=O&set /a DC= %DC%+1& GOTO AFTER
if %c3%%d3%%e3%%f3%==_XXX if NOT %c2%==_ set C3=O&set /a CC= %CC%+1& GOTO AFTER
if %c2%%d2%%e2%%f2%==XXX_ if NOT %f1%==_ set F2=O&set /a FC= %FC%+1& GOTO AFTER
if %c2%%d2%%e2%%f2%==XX_X if NOT %e1%==_ set E2=O&set /a EC= %EC%+1& GOTO AFTER
if %c2%%d2%%e2%%f2%==X_XX if NOT %d1%==_ set D2=O&set /a DC= %DC%+1& GOTO AFTER
if %c2%%d2%%e2%%f2%==_XXX if NOT %c1%==_ set C2=O&set /a CC= %CC%+1& GOTO AFTER
if %c1%%d1%%e1%%f1%==XXX_ set F1=O&set /a FC= %FC%+1& GOTO AFTER
if %c1%%d1%%e1%%f1%==XX_X set E1=O&set /a EC= %EC%+1& GOTO AFTER
if %c1%%d1%%e1%%f1%==X_XX set D1=O&set /a DC= %DC%+1& GOTO AFTER
if %c1%%d1%%e1%%f1%==_XXX set C1=O&set /a CC= %CC%+1& GOTO AFTER
if %a1%%b2%%c3%%d4%==XXX_ if NOT %d4%==_ set d4=O&set /a DC= %DC%+ 1& GOTO AFTER
if %a1%%b2%%c3%%d4%==XX_X if NOT %c3%==_ set C3=O&set /a CC= %CC%+ 1& GOTO AFTER
if %a1%%b2%%c3%%d4%==X_XX if NOT %b2%==_ set B2=O&set /a BC= %BC%+ 1& GOTO AFTER
if %a1%%b2%%c3%%d4%==_XXX set A1=O&set /a AC= %AC%+1& GOTO AFTER
if %a4%%b3%%c2%%d1%==XXX_ set D1=O&set /a DC= %DC%+1& GOTO AFTER
if %a4%%b3%%c2%%d1%==XX_X if NOT %c1%==_ set C2=O&set /a CC= %CC%+1& GOTO AFTER
if %a4%%b3%%c2%%d1%==X_XX if NOT %b2%==_ set B3=O&set /a BC= %BC%+1& GOTO AFTER
if %a4%%b3%%c2%%d1%==_XXX if NOT %a3%==_ set A4=O&set /a AC= %AC%+1& GOTO AFTER
if %b1%%C2%%D3%%E4%==XXX_ if NOT %e3%==_ set E4=O&set /a EC= %EC%+1& GOTO AFTER
if %b1%%C2%%D3%%E4%==XX_X if NOT %d2%==_ set D3=O&set /a DC= %DC%+1& GOTO AFTER
if %b1%%C2%%D3%%E4%==X_XX if NOT %c1%==_ set C2=O&set /a CC= %CC%+1& GOTO AFTER
if %b1%%C2%%D3%%E4%==_XXX set B1=O&set /a BC= %BC%+1& GOTO AFTER
if %b4%%C3%%D2%%E1%==XXX_ set E1=O&set /a EC= %EC%+1& GOTO AFTER
if %b4%%C3%%D2%%E1%==XX_X if NOT %d1%==_ set D2=O&set /a DC= %DC%+1& GOTO AFTER
if %b4%%C3%%D2%%E1%==X_XX if NOT %c2%==_ set C3=O&set /a CC= %CC%+1& GOTO AFTER
if %b4%%C3%%D2%%E1%==_XXX if NOT %b3%==_ set B4=O&set /a BC= %BC%+1& GOTO AFTER
if %c1%%d2%%e3%%f4%==XXX_ if NOT %f3%==_ set F4=O&set /a FC= %FC%+1& GOTO AFTER
if %c1%%d2%%e3%%f4%==XX_X if NOT %e2%==_ set E3=O&set /a EC= %EC%+1& GOTO AFTER
if %c1%%d2%%e3%%f4%==X_XX if NOT %d1%==_ set D2=O&set /a DC= %DC%+1& GOTO AFTER
if %c1%%d2%%e3%%f4%==_XXX set C1=O&set /a CC= %CC%+1& GOTO AFTER
if %c4%%d3%%e2%%f1%==XXX_ set F1=O&set /a FC= %FC%+1& GOTO AFTER
if %c4%%d3%%e2%%f1%==XX_X if NOT %e1%==_ set E2=O&set /a EC= %EC%+1& GOTO AFTER
if %c4%%d3%%e2%%f1%==X_XX if NOT %d2%==_ set D3=O&set /a DC= %DC%+1& GOTO AFTER
if %c4%%d3%%e2%%f1%==_XXX if NOT %c3%==_ set C4=O&set /a CC= %CC%+1& GOTO AFTER
exit /b
:attACker
if %A1%%A2%%A3%%A4%==OOO_ if NOT %A3%==_ set A4=O& goto lose
if %A1%%A2%%A3%%A4%==OO_O if NOT %A2%==_ set A3=O& goto lose
if %A1%%A2%%A3%%A4%==O_OO if NOT %A1%==_ set A2=O& goto lose
if %A1%%A2%%A3%%A4%==_OOO set A1=O& goto lose
if %B1%%B2%%B3%%B4%==OOO_ if NOT %B3%==_ set B4=O& goto lose
if %B1%%B2%%B3%%B4%==OO_O if NOT %B2%==_ set B3=O& goto lose
if %B1%%B2%%B3%%B4%==O_OO if NOT %B1%==_ set B2=O& goto lose
if %B1%%B2%%B3%%B4%==_OOO set B1=O& goto lose
if %C1%%C2%%C3%%C4%==OOO_ if NOT %c3%==_ set C4=O& goto lose
if %C1%%C2%%C3%%C4%==OO_O if NOT %c2%==_ set C3=O& goto lose
if %C1%%C2%%C3%%C4%==O_OO if NOT %c1%==_ set C2=O& goto lose
if %C1%%C2%%C3%%C4%==_OOO set C1=O& goto lose
if %D1%%D2%%D3%%D4%==OOO_ if NOT %d3%==_ set D4=O& goto lose
if %D1%%D2%%D3%%D4%==OO_O if NOT %d2%==_ set D3=O& goto lose
if %D1%%D2%%D3%%D4%==O_OO if NOT %d1%==_ set D2=O& goto lose
if %D1%%D2%%D3%%D4%==_OOO set D1=O& goto lose
if %E1%%E2%%E3%%E4%==OOO_ if NOT %e3%==_ set E4=O& goto lose
if %E1%%E2%%E3%%E4%==OO_O if NOT %e2%==_ set E3=O& goto lose
if %E1%%E2%%E3%%E4%==O_OO if NOT %d1%==_ set E2=O& goto lose
if %E1%%E2%%E3%%E4%==_OOO  set E1=O& goto lose
if %F1%%F2%%F3%%F4%==OOO_ if NOT %f3%==_ set F4=O& goto lose
if %F1%%F2%%F3%%F4%==OO_O if NOT %f2%==_ set F3=O& goto lose
if %F1%%F2%%F3%%F4%==O_OO if NOT %f1%==_ set F2=O& goto lose
if %F1%%F2%%F3%%F4%==_OOO set F1=O& goto lose
if %A4%%b4%%c4%%d4%==OOO_ if NOT %d3%==_ set d4=O& goto lose
if %A4%%b4%%c4%%d4%==OO_O if NOT %c3%==_ set c4=O& goto lose
if %A4%%b4%%c4%%d4%==O_OO if NOT %b3%==_ set b4=O& goto lose
if %A4%%b4%%c4%%d4%==_OOO if NOT %a3%==_ set A4=O& goto lose
if %A3%%b3%%c3%%d3%==OOO_ if NOT %d2%==_ set d3=O& goto lose
if %A3%%b3%%c3%%d3%==OO_O if NOT %c2%==_ set c3=O& goto lose
if %A3%%b3%%c3%%d3%==O_OO if NOT %b2%==_ set b3=O& goto lose
if %A3%%b3%%c3%%d3%==_OOO if NOT %a2%==_ set A3=O& goto lose
if %A2%%b2%%c2%%d2%==OOO_ if NOT %d1%==_ set d2=O& goto lose
if %A2%%b2%%c2%%d2%==OO_O if NOT %c1%==_ set c2=O& goto lose
if %A2%%b2%%c2%%d2%==O_OO if NOT %b1%==_ set b2=O& goto lose
if %A2%%b2%%c2%%d2%==_OOO if NOT %a1%==_ set A2=O& goto lose
if %A1%%b1%%c1%%d1%==OOO_ set d1=O& goto lose
if %A1%%b1%%c1%%d1%==OO_O set c1=O& goto lose
if %A1%%b1%%c1%%d1%==O_OO set b1=O& goto lose
if %A1%%b1%%c1%%d1%==_OOO set A1=O& goto lose
if %b4%%c4%%d4%%e4%==OOO_ if NOT %e3%==_ set e4=O& goto lose
if %b4%%c4%%d4%%e4%==OO_O if NOT %d3%==_ set d4=O& goto lose
if %b4%%c4%%d4%%e4%==O_OO if NOT %c3%==_ set c4=O& goto lose
if %b4%%c4%%d4%%e4%==_OOO if NOT %b3%==_ set b4=O& goto lose
if %b3%%c3%%d3%%e3%==OOO_ if NOT %e2%==_ set e3=O& goto lose
if %b3%%c3%%d3%%e3%==OO_O if NOT %d2%==_ set d3=O& goto lose
if %b3%%c3%%d3%%e3%==O_OO if NOT %c2%==_ set c3=O& goto lose
if %b3%%c3%%d3%%e3%==_OOO if NOT %b2%==_ set b3=O& goto lose
if %b2%%c2%%d2%%e2%==OOO_ if NOT %e1%==_ set e2=O& goto lose
if %b2%%c2%%d2%%e2%==OO_O if NOT %d1%==_ set d2=O& goto lose
if %b2%%c2%%d2%%e2%==O_OO if NOT %c1%==_ set c2=O& goto lose
if %b2%%c2%%d2%%e2%==_OOO if NOT %b1%==_ set b2=O& goto lose
if %b1%%c1%%d1%%e1%==OOO_ set e1=O& goto lose
if %b1%%c1%%d1%%e1%==OO_O set d1=O& goto lose
if %b1%%c1%%d1%%e1%==O_OO set c1=O& goto lose
if %b1%%c1%%d1%%e1%==_OOO set b1=O& goto lose
if %c4%%d4%%e4%%f4%==OOO_ if NOT %f3%==_ set F4=O& goto lose
if %c4%%d4%%e4%%f4%==OO_O if NOT %e3%==_ set E4=O& goto lose
if %c4%%d4%%e4%%f4%==O_OO if NOT %d3%==_ set D4=O& goto lose
if %c4%%d4%%e4%%f4%==_OOO if NOT %c3%==_ set C4=O& goto lose
if %c3%%d3%%e3%%f3%==OOO_ if NOT %f2%==_ set F3=O& goto lose
if %c3%%d3%%e3%%f3%==OO_O if NOT %e2%==_ set E3=O& goto lose
if %c3%%d3%%e3%%f3%==O_OO if NOT %d2%==_ set D3=O& goto lose
if %c3%%d3%%e3%%f3%==_OOO if NOT %c2%==_ set C3=O& goto lose
if %c2%%d2%%e2%%f2%==OOO_ if NOT %f1%==_ set F2=O& goto lose
if %c2%%d2%%e2%%f2%==OO_O if NOT %e1%==_ set E2=O& goto lose
if %c2%%d2%%e2%%f2%==O_OO if NOT %d1%==_ set D2=O& goto lose
if %c2%%d2%%e2%%f2%==_OOO if NOT %c1%==_ set C2=O& goto lose
if %c1%%d1%%e1%%f1%==OOO_ set F1=O& goto lose
if %c1%%d1%%e1%%f1%==OO_O set E1=O& goto lose
if %c1%%d1%%e1%%f1%==O_OO set D1=O& goto lose
if %c1%%d1%%e1%%f1%==_OOO set C1=O& goto lose
if %a1%%b2%%c3%%d4%==OOO_ if NOT %d3%==_ set d4=O& goto lose
if %a1%%b2%%c3%%d4%==OO_O if NOT %c2%==_ set C3=O& goto lose
if %a1%%b2%%c3%%d4%==O_OO if NOT %b1%==_ set B2=O& goto lose
if %a1%%b2%%c3%%d4%==_OOO set A1=O& goto lose
if %a4%%b3%%c2%%d1%==OOO_ set D1=O& goto lose
if %a4%%b3%%c2%%d1%==OO_O if NOT %c1%==_ set C2=O& goto lose
if %a4%%b3%%c2%%d1%==O_OO if NOT %b2%==_ set B3=O& goto lose
if %a4%%b3%%c2%%d1%==_OOO if NOT %a3%==_ set A4=O& goto lose
if %b1%%C2%%D3%%E4%==OOO_ if NOT %e3%==_ set E4=O& goto lose
if %b1%%C2%%D3%%E4%==OO_O if NOT %d2%==_ set D3=O& goto lose
if %b1%%C2%%D3%%E4%==O_OO if NOT %c1%==_ set C2=O& goto lose
if %b1%%C2%%D3%%E4%==_OOO set B1=O& goto lose
if %b4%%C3%%D2%%E1%==OOO_ set E1=O& goto lose
if %b4%%C3%%D2%%E1%==OO_O if NOT %d1%==_ set D2=O& goto lose
if %b4%%C3%%D2%%E1%==O_OO if NOT %c2%==_ set C3=O& goto lose
if %b4%%C3%%D2%%E1%==_OOO if NOT %b3%==_ set B4=O& goto lose
if %c1%%d2%%e3%%f4%==OOO_ if NOT %f3%==_ set F4=O& goto lose
if %c1%%d2%%e3%%f4%==OO_O if NOT %e3%==_ set E3=O& goto lose
if %c1%%d2%%e3%%f4%==O_OO if NOT %d1%==_ set D2=O& goto lose
if %c1%%d2%%e3%%f4%==_OOO set C1=O& goto lose
if %c4%%d3%%e2%%f1%==OOO_ set F1=O& goto lose
if %c4%%d3%%e2%%f1%==OO_O if NOT %e1%==_ set E2=O& goto lose
if %c4%%d3%%e2%%f1%==O_OO if NOT %d2%==_ set D3=O& goto lose
if %c4%%d3%%e2%%f1%==_OOO if NOT %c3%==_ set C4=O& goto lose
exit /b
:winlist
call :board
if %A1%%A2%%A3%%A4%==XXXX GOTO WIN
if %B1%%B2%%B3%%B4%==XXXX GOTO WIN
if %C1%%C2%%C3%%C4%==XXXX GOTO WIN
if %D1%%D2%%D3%%D4%==XXXX GOTO WIN
if %E1%%E2%%E3%%E4%==XXXX GOTO WIN
if %F1%%F2%%F3%%F4%==XXXX GOTO WIN
if %A4%%B4%%C4%%D4%==XXXX GOTO WIN
if %A3%%B3%%C3%%D3%==XXXX GOTO WIN
if %A2%%B2%%C2%%D2%==XXXX GOTO WIN
if %A1%%B1%%C1%%D1%==XXXX GOTO WIN
if %B4%%C4%%D4%%E4%==XXXX GOTO WIN
if %B3%%C3%%D3%%E3%==XXXX GOTO WIN
if %B2%%C2%%D2%%E2%==XXXX GOTO WIN
if %B1%%C1%%D1%%E1%==XXXX GOTO WIN
if %C4%%D4%%E4%%F4%==XXXX GOTO WIN
if %C3%%D3%%E3%%F3%==XXXX GOTO WIN
if %C2%%D2%%E2%%F2%==XXXX GOTO WIN
if %C1%%D1%%F1%%E1%==XXXX GOTO WIN
if %A1%%B2%%C3%%D4%==XXXX GOTO WIN
if %A4%%B3%%C2%%D1%==XXXX GOTO WIN
if %B1%%C2%%D3%%E4%==XXXX GOTO WIN
if %B4%%C3%%D2%%E1%==XXXX GOTO WIN
if %C1%%D2%%E3%%F4%==XXXX GOTO WIN
if %C4%%D3%%E2%%F1%==XXXX GOTO WIN
EXIT /B
I like the idea. Had a go at reducing it down a bit, simplified the testing and output. Only thing left to do is make the AI 'smart'

Connect 4: 6884 bytes

Code: Select all

@Echo off & Rem /* Inspired by: https://www.dostips.com/forum/viewtopic.php?f=3&t=3259#p15721 */
:Start rem /* game returns here after win loss or draw */
 CHCP 65001 > nul & Rem Used for BG display
 Pushd "%userprofile%" & (For /F "Delims=" %%C in ('dir BG*.exe /B /S') Do (%%C Cursor 0)) 2> Nul && POPD & Rem /* hides cursor if bg.exe is installed in userprofile */
 CLS & Endlocal & Setlocal DISABLEdelayedexpansion & rem /* Ensure correct environment for macro definition */
::: Win position table. Hor Vert Diag :::\
 Set "W[0]=[1;1][1;2][1;3][1;4]"&rem  :::H
 Set "W[1]=[1;2][1;3][1;4][1;5]"&rem  :::H
 Set "W[2]=[1;3][1;4][1;5][1;6]"&rem  :::H
 Set "W[3]=[2;1][2;2][2;3][2;4]"&rem  :::H
 Set "W[4]=[2;2][2;3][2;4][2;5]"&rem  :::H
 Set "W[5]=[2;3][2;4][2;5][2;6]"&rem  :::H
 Set "W[6]=[3;1][3;2][3;3][3;4]"&rem  :::H
 Set "W[7]=[3;2][3;3][3;4][3;5]"&rem  :::H
 Set "W[8]=[3;3][3;4][3;5][3;6]"&rem  :::H
 Set "W[9]=[4;1][4;2][4;3][4;4]"&rem  :::H
 Set "W[10]=[4;2][4;3][4;4][4;5]"&rem :::H
 Set "W[11]=[4;3][4;4][4;5][4;6]"&rem :::H
 Set "W[12]=[1;1][2;1][3;1][4;1]"&rem :::V
 Set "W[13]=[1;2][2;2][3;2][4;2]"&rem :::V
 Set "W[14]=[1;3][2;3][3;3][4;3]"&rem :::V
 Set "W[15]=[1;4][2;4][3;4][4;4]"&rem :::V
 Set "W[16]=[1;5][2;5][3;5][4;5]"&rem :::V
 Set "W[17]=[1;6][2;6][3;6][4;6]"&rem :::V
 Set "W[18]=[4;1][3;2][2;3][1;4]"&rem :::D
 Set "W[19]=[4;2][3;3][2;4][1;5]"&rem :::D
 Set "W[20]=[4;3][3;4][2;5][1;6]"&rem :::D
 Set "W[21]=[4;6][3;5][2;4][1;3]"&rem :::D
 Set "W[22]=[4;5][3;4][2;3][1;2]"&rem :::D
 Set "W[23]=[1;1][2;2][3;3][4;4]"&rem :::D
::::::::::::::::::::::: Do not modify :::/
(For /F %%a in ('echo prompt $E ^| cmd')do (Set "/E=%%a")
%= Ascii Escape Character. Do Not Modify. =%)
 Set "?Won=(For /F "Tokens=1,2 Delims==" %%G in  ('Set W[ 2^> Nul') Do (For /F "Tokens=1,2,3,4 Delims=[]" %%w in ("%%H")Do (If "!%%w!!%%x!!%%y!!%%z!"=="$$$$" (<Nul Set /P "=%/E%[5;1H%/E%[90m123456%/E%[0m%/E%[%%wH!$:7=4!%/E%[%%xH!$:7=4!%/E%[%%yH!$:7=4!%/E%[%%zH!$:7=4!"&Echo/%/E%[7;1H%/E%[K!$! Won& (If Not "!Mode!"=="A" (Pause > Nul )Else ( Timeout 4 1> Nul ))&Endlocal&Goto :Start)))) & (IF "!AvMoves!"=="" (Echo/%/E%[7;1H%/E%[K%/E%[90mDraw.%/E%[90m& Timeout 5 > Nul &Endlocal &Goto :Start))"
 Set "Move=(Echo/%/E%[7;1H%/E%[K!$! Move&For /F "Delims=" %%G in ('Choice /N /C:123456EN')Do If "%%G" == "N" (Endlocal & Goto :Start)Else if /I "%%G" == "E" (Endlocal & Exit /B 0)Else Call :Test %%G & For %%e in (!Errorlevel!)Do If "%%e" == "0" (Goto :$Move)Else (<Nul Set /P "=%/E%[%%e;%%GH!$!"&Set "%%e;%%G=$"&Set AvMoves=!AvMoves:"%%e;%%G" =!))"
 Set "AiMove=Call :Brains $" & Rem /* Substring modification is used to replace '$' with the active player */
 Set "Menu=(<Nul Set /P"=%/E%[5;1H%/E%[90m123456%/E%[0m%/E%[1;20H%/E%[K%/E%[COLmSelect mode%/E%[0m:%/E%[2;20H%/E%[K[%/E%[COLm1%/E%[0m] Player%/E%[3;20H%/E%[K[%/E%[COLm2%/E%[0m] Player%/E%[4;20H%/E%[K[%/E%[COLmA%/E%[0m] AI battle%/E%[5;20H%/E%[K[%/E%[36mN%/E%[0m] New%/E%[6;20H%/E%[K[%/E%[36mE%/E%[0m] Exit%/E%[0m%/E%[7;20H%/E%[K[%/E%[COLmV%/E%[0m] View Source code%/E%[7;1H%/E%[36m?%/E%[0m")"
 Set "X=%/E%[32;7mx%/E%[0m"&Set "O=%/E%[31;7mo%/E%[0m"&Set "iX=O"&Set "iO=X"
 Set AvMoves="4;1" "4;2" "4;3" "4;4" "4;5" "4;6" "3;1" "3;2" "3;3" "3;4" "3;5" "3;6" "2;1" "2;2" "2;3" "2;4" "2;5" "2;6" "1;1" "1;2" "1;3" "1;4" "1;5" "1;6" &Rem Trailing space required
 Set "ForPlayer=For /F "Tokens=1,2 Delims==" %%G in  ('Set W[ 2^> Nul') Do (For /F "Tokens=1,2,3,4 Delims=[]" %%w in ("%%H")Do (If "!%%w!!%%x!!%%y!!%%z!"=="@" ("
 Set "ONfind=Set "AvMoves=!AvMoves:"%%#;%%d" =!" & Exit /B 0"
 Set "?test=If "!%%$V!"=="" (For /F "Tokens=2 Delims=;" %%d in ("%%$V")Do For /L %%# in (4 -1 1)Do (For /F "Delims=" %%i in ('Set /A "i=%%#+1"')Do if not "%%~i"=="5" (If not "!%%i;%%d!"=="" If "!%%#;%%d!"=="" (<Nul Set /P "=%/E%[%%#;%%dH!e$!"&Set "%%#;%%d=!$!" & %OnFind%))Else (If "!%%#;%%d!"=="" (<Nul Set /P "=%/E%[%%#;%%dH!e$!"&Set "%%#;%%d=!$!" & %OnFind%))))"
 Set "OnFind="
 Setlocal EnableDelayedExpansion & rem /* Establish environment for macro expansion */
 (For %%G in (!AvMoves!)Do <Nul Set /P"=%/E%[%%~GH%/E%[34m◘%/E%[0m")
 %Menu:COL=36% & rem /* display active game menu options */
 Title Connect 4
 (For /F "Delims=" %%G in ('Choice /T 10 /D A /N /C:NA21VE')Do If /I "%%G"=="N" (Endlocal & Goto :Start)Else If /I "%%G"=="E" (Endlocal & Exit /B 0)Else Set "Mode=%%G")
 If "%Mode%"=="V" (Mode 1000 & TYPE "%~F0" & Timeout 10 /NoBreak > Nul & Endlocal & Echo/&Echo/Continue & Pause > Nul & Goto :Start)
 %Menu:COL=90% & rem /* display which game menu options become inactive */
:XMove rem /* [X][O]Move Labels used as turn loop and to control scriptflow for invalid moves. with the aid of substring modification */
 (If "%Mode%" == "A" (TITLE AI Battle & <Nul Set /P "=%/E%[5;20H%/E%[K[%/E%[90mN%/E%[0m] New%/E%[5;1H%/E%[90m123456%/E%[0m%/E%[6;20H%/E%[K[%/E%[90mE%/E%[0m] Exit"& %AIMove:$=X%)Else (<Nul Set /P "=%/E%[5;1H%/E%[32m123456%/E%[0m" & %Move:$=X%)) & %?won:$=X%
:OMove rem /* AI was dumb-ish. lookup table for 'smart' comparison of open moves vs player occupied coordinates has been implemented */
 (If "%Mode%" == "2" (If Not "%Mode%" == "A" <Nul Set /P "=%/E%[5;1H%/E%[31m123456%/E%[0m" & %Move:$=O%) Else %AIMove:$=O%) & %?won:$=O%
Goto :XMove
:Test rem /* returns first avialable Y coordinate for the attempted X coordinate via Errorlevel or 0 for no valid coordinate */
 For /L %%# in (4,-1,1)Do (Echo/"!AvMoves!"| %__AppDir__%findstr.exe /LIC:"%%#;%~1" > Nul 2> Nul && Exit /B %%#)
Exit /B 0
:Brains rem /* AI Calls for loop conditional test block to find an appropriate block / advance coordinate */
 Set "$=%1"& Set "e$=!%1!"& Set "$o=!i%1!"
 Call :ForeThought
 If "%Errorlevel%"=="0" (Exit /B 0)
:FindAIM rem /* test for and fill first valid Y position found at random x axis. repeats until position found */
 (Echo/%/E%[7;1H%/E%[K!%1! Move& For /F "Delims=" %%G in ('Set /A "i=!Random! %%6 + 1"')Do (Call :Test %%G & For %%e in (!Errorlevel!)Do If "%%e" == "0" (Goto :FindAIM)Else (<Nul Set /P "=%/E%[%%e;%%GH!%1!"&Set "%%e;%%G=%1"&Set "AvMoves=!AvMoves:"%%e;%%G" =!"&Exit /B 0)))
 Exit /B 0
:ForeThought rem /* Iterate over W[ win pos array, test for a single empty position in a winning 4 point line and attempt to fill first one found - prioritising Ai's own winning sequence.
rem - cont. - On finding valid 4 coordinate return to move loops. If none, test for 2 unoccupied positions in an AI occupied position set. to advance AI */
%ForPlayer:@=!$!!$!!$!%
   %?test:$V=w% Else %?test:$V=x% Else %?test:$V=y% Else %?test:$V=z%
)))
%ForPlayer:@=!$o!!$o!!$o!%
   %?test:$V=w% Else %?test:$V=x% Else %?test:$V=y% Else %?test:$V=z%
)))
%ForPlayer:@=!$o!!$o!%
   %?test:$V=w% Else %?test:$V=x% Else %?test:$V=y% Else %?test:$V=z%
)))
%ForPlayer:@=!$!!$!%
   %?test:$V=w% Else %?test:$V=x% Else %?test:$V=y% Else %?test:$V=z%
)))
Exit /B 1
Supports 1 or 2 players or watch an 'AI' battle

*Edit: ?Macro's adjusted to invert the color of a connected line on win.
I like the idea. Had a go at reducing it down a bit, simplified the testing and output. Only thing left to do is make the AI 'smart'
- AI has been given a brain. Code updated
AI has been given a brain
- Ai's brain was malformed. surgery complete
Now tests if the square beneath an intended block move is empty prior to making the block.
AI move priority is:
1) Complete any available 4 point line as a winning move
2) Block the first encountered 4 point line to prevent a players winning move
3) attempt to Block the first encountered potential 3 point line to inhibit player board development
4) take the first available move to make a 3 point line of it's own and develop own position
forethought testing function exits with errorlevel 0 when a valid move is found which is used to exit the AI brain function.
Errorlevel 1 is returned if if no move found in which case:
5) take first available random move

- Available Move positions are tracked using the AvMoves variable, with the coordinates of a succesful move removed from AvMoves using substring modification
- Player and random moves are checked against AvMoves in the :Test subroutine, which uses findstr to determine if there is Y;X coordinate available for an attempted X move.
- Y Coordinate is returned via errorlevel, and if no Y available for the given X, errorlevel 0 is returned - which rejects the x coordinate move.
- AvMoves is also used at the start of each game to display the 'board'
- Each occupied y;x coordinate is defined with 'X' for player or 'O' for opponent when a move is taken for use in the :Brains Array tests, with endlocal / setlocal being used to undefine them at the end of each round
- macro's are used throughout the script, predominately out of laziness. Allows reuse of repetitive code in a concise manner, supplying the relevent value the macro iterates over using substring modifiication.

Golfed version with more robust, if slower AI (5557 bytes):

Code: Select all

@Echo off
:Start
 CHCP 65001 > nul & CLS & Mode 40,8
 Pushd "%userprofile%" &(For /F "Delims=" %%C in ('dir BG*.exe /B /S') Do (%%C Cursor 0)) 2> Nul && POPD
 CLS &Endlocal &Setlocal DISABLEdelayedexpansion
 For /F %%a in ('echo prompt $E ^| cmd')do (Set "/E=%%a[")
 Set "?Won=(For /F "Tokens=1,2 Delims==" %%G in  ('Set W[ 2^> Nul') Do (For /F "Tokens=1,2,3,4 Delims=[]" %%w in ("%%H")Do (If "!%%w!!%%x!!%%y!!%%z!"=="$$$$" (<Nul Set /P "=%/E%5;1H%/E%90m123456%/E%0m%/E%%%wH!$:7=4!%/E%%%xH!$:7=4!%/E%%%yH!$:7=4!%/E%%%zH!$:7=4!"&Echo/%/E%7;1H%/E%K!$! Won& (If Not "!Mode!"=="A" (Pause > Nul )Else ( Timeout 4 1> Nul ))&Endlocal&Goto :Start)))) & (IF "!AvMoves!"=="" (Echo/%/E%7;1H%/E%K%/E%90mDraw.%/E%90m& Timeout 5 > Nul &Endlocal &Goto :Start))"
 Set "Move=(Echo/%/E%7;1H%/E%K!$! Move&For /F "Delims=" %%G in ('Choice /N /C:123456EN')Do If "%%G"=="N" (Endlocal & Goto :Start)Else if /I "%%G"=="E" (Endlocal & Exit /B 0)Else Call :Test %%G & For %%e in (!Errorlevel!)Do If "%%e"=="0" (Goto :$Move)Else (<Nul Set /P "=%/E%%%e;%%GH!$!"&Set "%%e;%%G=$"&Set AvMoves=!AvMoves:"%%e;%%G" =!))"
 Set "AiMove=Call :Brains $"
 Set "Menu=(<Nul Set /P"=%/E%5;1H%/E%90m123456%/E%0m%/E%1;20H%/E%K%/E%COLmSelect mode%/E%0m:%/E%2;20H%/E%K[%/E%COLm1%/E%0m] Player%/E%3;20H%/E%K[%/E%COLm2%/E%0m] Player%/E%4;20H%/E%K[%/E%COLmA%/E%0m] AI battle%/E%5;20H%/E%K[%/E%36mN%/E%0m] New%/E%6;20H%/E%K[%/E%36mE%/E%0m] Exit%/E%0m%/E%7;20H%/E%K[%/E%COLmV%/E%0m] View Source code%/E%7;1H%/E%36m?%/E%0m")"
 Set "X=%/E%32;7mx%/E%0m"&Set "O=%/E%31;7mo%/E%0m"&Set "iX=O"&Set "iO=X"
 Set AvMoves="4;1" "4;2" "4;3" "4;4" "4;5" "4;6" "3;1" "3;2" "3;3" "3;4" "3;5" "3;6" "2;1" "2;2" "2;3" "2;4" "2;5" "2;6" "1;1" "1;2" "1;3" "1;4" "1;5" "1;6" &Rem Trailing space required
 Set "IfLine=For /F "Tokens=1,2 Delims==" %%G in  ('Set W[ 2^> Nul') Do (For /F "Tokens=1,2,3,4 Delims=[]" %%w in ("%%H")Do (If "!%%w!!%%x!!%%y!!%%z!"=="@" ("
 Set "ONfind=Set "AvMoves=!AvMoves:"%%#;%%d" =!" & Exit /B 0"
 Set "?Next= (Set /A "_y=%%~#-1,_x=%%~d"&For /L %%n in (0 1 23)Do For /F "Delims=" %%X in (' Echo/"!W[%%n]!" ^| Findstr 2^> Nul /LIC:"!_y!;!_x!" ')Do For /F "Tokens=1,2,3,4 Delims=[]" %%1 in ("!W[%%n]!")Do If "!%%~1!!%%~2!!%%~3!!%%~4!" == "!$o!!$o!!$o!" (Exit /B 1))"
 Set "?AIw=If "!%%$V!"=="" (For /F "Tokens=2 Delims=;" %%d in ("%%$V")Do For /L %%# in (4 -1 1)Do (For /F "Delims=" %%i in ('Set /A "i=%%#+1"')Do if not "%%~i"=="5" (If not "!%%i;%%d!"=="" If "!%%#;%%d!"=="" (<Nul Set /P "=%/E%%%#;%%dH!e$!"&Set "%%#;%%d=!$!" & %OnFind%))Else (If "!%%#;%%d!"=="" (<Nul Set /P "=%/E%%%#;%%dH!e$!"&Set "%%#;%%d=!$!" & %OnFind%))))"
 Set "?is=If "!%%$V!"=="" (For /F "Tokens=2 Delims=;" %%d in ("%%$V")Do For /L %%# in (4 -1 1)Do (For /F "Delims=" %%i in ('Set /A "i=%%#+1"')Do if not "%%~i"=="5" (If not "!%%i;%%d!"=="" If "!%%#;%%d!"=="" (%?Next%&<Nul Set /P "=%/E%%%#;%%dH!e$!"&Set "%%#;%%d=!$!" & %OnFind%))Else (If "!%%#;%%d!"=="" (%?Next%&<Nul Set /P "=%/E%%%#;%%dH!e$!"&Set "%%#;%%d=!$!" & %OnFind%))))"
 Set "List_DEF=Set "#$L=0"&Set "$$L="&For %%n in (1 2)Do if %%n==2 (For %%G in (!$L!)Do (Set "%%~G" > Nul &Set /A "#$L+=1"))Else Set $L="
 Setlocal EnableDelayedExpansion
 %List_DEF:$L=WinLines% "W[0]=[1;1][1;2][1;3][1;4]" "W[1]=[1;2][1;3][1;4][1;5]" "W[2]=[1;3][1;4][1;5][1;6]" "W[3]=[2;1][2;2][2;3][2;4]" "W[4]=[2;2][2;3][2;4][2;5]" "W[5]=[2;3][2;4][2;5][2;6]" "W[6]=[3;1][3;2][3;3][3;4]" "W[7]=[3;2][3;3][3;4][3;5]" "W[8]=[3;3][3;4][3;5][3;6]" "W[9]=[4;1][4;2][4;3][4;4]" "W[10]=[4;2][4;3][4;4][4;5]" "W[11]=[4;3][4;4][4;5][4;6]" "W[12]=[1;1][2;1][3;1][4;1]" "W[13]=[1;2][2;2][3;2][4;2]" "W[14]=[1;3][2;3][3;3][4;3]" "W[15]=[1;4][2;4][3;4][4;4]" "W[16]=[1;5][2;5][3;5][4;5]" "W[17]=[1;6][2;6][3;6][4;6]" "W[18]=[4;1][3;2][2;3][1;4]" "W[19]=[4;2][3;3][2;4][1;5]" "W[20]=[4;3][3;4][2;5][1;6]" "W[21]=[4;6][3;5][2;4][1;3]" "W[22]=[4;5][3;4][2;3][1;2]" "W[23]=[1;1][2;2][3;3][4;4]"
 (For %%G in (!AvMoves!)Do <Nul Set /P"=%/E%%%~GH%/E%34m◘%/E%0m")
 %Menu:COL=36%& Title Connect 4
 (For /F "Delims=" %%G in ('Choice /T 10 /D A /N /C:NA21VE')Do If /I "%%G"=="N" (Endlocal & Goto :Start)Else If /I "%%G"=="E" (Endlocal & Exit /B 0)Else Set "Mode=%%G")
 If "%Mode%"=="V" (notepad.exe "%~F0" & Endlocal & Echo/&Echo/Continue & Pause > Nul & Goto :Start)
 %Menu:COL=90%
:XMove
 (If "%Mode%"=="A" (TITLE AI Battle & <Nul Set /P "=%/E%5;20H%/E%K[%/E%90mN%/E%0m] New%/E%5;1H%/E%90m123456%/E%0m%/E%6;20H%/E%K[%/E%90mE%/E%0m] Exit"& %AIMove:$=X%)Else (<Nul Set /P "=%/E%5;1H%/E%32m123456%/E%0m" & %Move:$=X%)) & %?won:$=X%
:OMove
 (If "%Mode%"=="2" (If Not "%Mode%"=="A" <Nul Set /P "=%/E%5;1H%/E%31m123456%/E%0m" & %Move:$=O%) Else %AIMove:$=O%) & %?won:$=O%
Goto :XMove
:Test
 For /L %%# in (4,-1,1)Do (Echo/"!AvMoves!"| %__AppDir__%findstr.exe /LIC:"%%#;%~1" > Nul 2> Nul && Exit /B %%#)
Exit /B 0
:Brains
 Set "$=%1"& Set "e$=!%1!"& Set "$o=!i%1!"
 Call :ForMove & If "!Errorlevel!"=="0" (Exit /B 0)
:FindAIM
 (Echo/%/E%7;1H%/E%K!%1! Move& For /F "Delims=" %%G in ('Set /A "i=!Random! %%6 + 1"')Do (Call :Test %%G & For %%e in (!Errorlevel!)Do If "%%e" == "0" (Goto :FindAIM)Else (<Nul Set /P "=%/E%%%e;%%GH!%1!"&Set "%%e;%%G=%1"&Set "AvMoves=!AvMoves:"%%e;%%G" =!"&Exit /B 0)))
 Exit /B 0
:ForMove
%IfLine:@=!$!!$!!$!% %?AIw:$V=w% Else %?AIw:$V=x% Else %?AIw:$V=y% Else %?AIw:$V=z%)))
%IfLine:@=!$o!!$o!!$o!% %?is:$V=w% Else %?is:$V=x% Else %?is:$V=y% Else %?is:$V=z% )))
%IfLine:@=!$o!!$o!%     %?is:$V=w% Else %?is:$V=x% Else %?is:$V=y% Else %?is:$V=z% )))
%IfLine:@=!$!!$!%       %?is:$V=w% Else %?is:$V=x% Else %?is:$V=y% Else %?is:$V=z% )))
Exit /B 1

T3RRY
Posts: 96
Joined: 06 May 2020 10:14

Re: Batch Games

#19 Post by T3RRY » 01 Nov 2020 09:31

Decided to try my hand at a pure batch Tetris [ no powershell or external exe's at this point ].
Game uses Vt Escape control character - so unfortunately windows 10 only

I was somewhat lazy with the piece rotation routine- I adapted some routines for flipping / mirroring 'images' from one of my previous projects in order to simulate 90 Degree rotation. I'm sure it could be done more efficiently though.

Display elements [border, control legend and pieces] are defined to their respective coordinates with a prefix of } and output to a file to be displayed via the type command - enabling smooth, flicker-free animation

Collision detection is achieved by detemining if all new y;x coordinates for an attempted move are undefined - If true, the move is allowed.
Once a piece is Set in place - triggered by a downward move encountering a non empty coordinate during an attempted move, each cell coordinate for the current piece is defined with the display value for the piece. When a line is matched, for each line above the matched line, values from each cell are shifted down by one until the matched line is reached. A tempory variable is used to prevent the cells being iterated over from having their values overriden before the iteration is complete.

Code: Select all

@Echo off
 Setlocal EnableExtensions DISABLEdelayedexpansion
 wmic OS get OSArchitecture,caption | FIND "10" >nul || (ECHO/Windows 10 required for ascii escape codes & Endlocal & Exit /B)
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 Title Tetris by T3RRY & rem commenced 30/10/2020
rem ::: 30/10/2020 Piece creation, basic collision detection, piece movement implemented.
rem ::: 31/10/2020 New piece and Game over trigger tests added.
rem ::: 31/10/2020 Color, Piece rotation added
rem ::: 01/11/2020 Function to test for a completed line added.
rem ::: 01/11/2020  Scoring system added
:::::::: [ TO BE ACTIONED ] :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
rem ::: Getkeys controller version with variable delay for speed increase based on score
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
rem ---------------------------------------------------- /* ASCII escape code definition */
 for /F "delims=#" %%a in ('"prompt #$E# & for %%a in (1) do rem"') do set "\E=%%a"
rem ------------------------------------------------ /* ensure } reference var undefined */
 (For /F "Tokens=1,2 Delims==" %%G in ('Set "}"')Do Set "%%G=") 2> nul
rem ------------------------------------------------------------------ /* define macro's */
 Set "nPiece[1]=Set /A "x1=6,y1=1,x2=6,y2=2,x3=6,y3=3,x4=6,y4=4""
 Set "nPiece[2]=Set /A "x1=6,y1=1,x2=7,y2=1,x3=6,y3=2,x4=7,y4=2""
 Set "nPiece[3]=Set /A "x1=6,y1=1,x2=7,y2=1,x3=7,y3=2,x4=7,y4=3""
 Set "nPiece[4]=Set /A "x1=6,y1=1,x2=6,y2=2,x3=6,y3=3,x4=7,y4=1""
 Set "nPiece[5]=Set /A "x1=6,y1=1,x2=6,y2=2,x3=7,y3=2,x4=7,y4=3""
 Set "nPiece[6]=Set /A "x1=7,y1=1,x2=7,y2=2,x3=6,y3=2,x4=6,y4=3""
 Set "nPiece[7]=Set /A "x1=6,y1=1,x2=6,y2=2,x3=7,y3=2,x4=6,y4=3""
 Set "MoveLeft=Set "valid=0"&Set /A "_x1=!x1!-1,_x2=!x2!-1,_x3=!x3!-1,_x4=!x4!-1" & (For %%v in ("!y1!;!_x1!" "!y2!;!_x2!" "!y3!;!_x3!" "!y4!;!_x4!")Do (IF "!}%%~v!" == "" (Set /A "Valid=!Valid! + 1"))) & If "!Valid!" == "4" (Set /A "x1-=1,x2-=1,x3-=1,x4-=1")"
 Set "MoveRight=Set "valid=0"&Set /A "_x1=!x1!+1,_x2=!x2!+1,_x3=!x3!+1,_x4=!x4!+1" & (For %%v in ("!y1!;!_x1!" "!y2!;!_x2!" "!y3!;!_x3!" "!y4!;!_x4!")Do (IF "!}%%~v!" == "" (Set /A "Valid=!Valid! + 1"))) & If "!Valid!" == "4" (Set /A "x1+=1,x2+=1,x3+=1,x4+=1")"
 Set "MoveDown=Set "valid=0"&Set /A "_y1=!y1!+1,_y2=!y2!+1,_y3=!y3!+1,_y4=!y4!+1" & (For %%v in ("!_y1!;!x1!" "!_y2!;!x2!" "!_y3!;!x3!" "!_y4!;!x4!")Do (IF "!}%%~v!" == "" (Set /A "Valid=!Valid! + 1"))) & (If "!Valid!" == "4" (Set /A "y1+=1,y2+=1,y3+=1,y4+=1")Else (Set /A "Score+=10"&Set "}!y1!;!x1!=%\E%[!y1!;!x1!H%\E%[3!pce!mX%\E%[0m"& Set "}!y2!;!x2!=%\E%[!y2!;!x2!H%\E%[3!pce!mX%\E%[0m"& Set "}!y3!;!x3!=%\E%[!y3!;!x3!H%\E%[3!pce!mX%\E%[0m"& Set "}!y4!;!x4!=%\E%[!y4!;!x4!H%\E%[3!pce!mX%\E%[0m"& >"%TEMP%\tetris.~tmp" (For /F "Tokens=2* Delims==" %%G in ('Set }')Do Echo/%%G) & If "!y1!" == "1" (Goto :Gameover)Else ( Call :isMatch & Goto :newpiece )))"
 Set "ShowPiece=<Nul Set /P "=%\E%[3!pce!m%\E%[!y1!;!x1!HX%\E%[!y2!;!x2!HX%\E%[!y3!;!x3!HX%\E%[!y4!;!x4!HX%\E%[0m""
 Set "HideLast=<Nul Set /P "=%\E%[!ly1!;!lx1!H %\E%[!ly2!;!lx2!H %\E%[!ly3!;!lx3!H %\E%[!ly4!;!lx4!H %\E%[0m""
rem ---------------------------------------------------------- /* Define Control Display */
 Set "}1;20=%\E%[1;20H%\E%[90mScore: !Score!"
 Set "}3;20=%\E%[3;20H%\E%[33mControls:"
 Set "}4;20=%\E%[4;20HA - move Left"
 Set "}5;20=%\E%[5;20HS - move Down"
 Set "}6;20=%\E%[6;20HD - move Right"
 Set "}7;20=%\E%[7;20HR - Rotate"
 Set "}8;20=%\E%[8;20HV - Drop Piece"
 Set "}9;20=%\E%[9;20H%\E%[32mE - Exit%\E%[0m"
rem -------------------- /* Establish environment for macro usage and code block actions */
 Setlocal EnableDelayedExpansion
 mode 60,42
rem ----------------------------------------------------------------- /* hide the cursor */
 <nul Set /P "=%\E%[?25l"
rem --------------------------------------------------------------- /* define the border */
 For %%s in (1 12)Do For /L %%n in (1 1 41) Do (
  Set "}%%n;%%s=%\E%[%%n;%%sH%\E%[90m.%\E%[0m"
  If %%n==41 For /L %%b in (2 1 11)Do (
   Set "}%%n;%%b=%\E%[%%n;%%bH%\E%[90m.%\E%[0m"
  )
 )
 >"%TEMP%\tetris.~tmp" (For /F "Tokens=2* Delims==" %%G in ('Set "}"')Do Echo/%%G)
:newpiece
 CLS
 Type "%TEMP%\tetris.~tmp"
 Set /A pce=%random% %%7 + 1
 !nPiece[%pce%]!
 %ShowPiece%
:loop
rem ----------------------------- /* get pieces last y;x vals to blank out with hidelast */
 For %%c in (y x)Do For %%i in (1 2 3 4)Do Set "l%%c%%i=!%%c%%i!"
rem ----------------------------------------------------------------------- /* game pace */
 Set /A tick+=1
 If "!tick!" == "4" (
  Set "tick=0"
  %movedown%
 )
rem ----------------------------------------------------------------- /* game controller */
 For /F "delims=" %%G in ('choice /N /T 1 /C:prevasd /D S') Do (
  If "%%G" == "E" (TITLE Quit Y\N?&For /F "Delims=" %%C in ('Choice /N /C:YN')Do if %%C==Y (Title & Goto :quit)Else (Title Tetris by T3RRY))
  If "%%G" == "A" %Moveleft%
  If "%%G" == "S" %Movedown%
  If "%%G" == "D" %Moveright%
  If "%%G" == "P" ( Title Paused & Pause > nul & Title Tetris by T3RRY )
  If "%%G" == "V" (For /L %%s in (1 1 39)Do %MoveDown%)
rem ------------------------------------------------------------ /* start rotation logic */
rem --- [ Horizontal flip followed by mirror to simulate 90 degree rotation. ]
  If "%%G" == "R" (
rem ----------------------------------------------------------------- /* flip horizontal */
   Set /A midX=500,midY=500
   For %%A in ("!y1!;!x1!" "!y2!;!x2!" "!y3!;!x3!" "!y4!;!x4!") Do (
    For /F "Tokens=1,2 Delims=;" %%X in ("%%~A") Do (
     Set /A "oY=%%~X"
     Set /A "oX=%%~Y"
    )
    If !oY! LSS !midY! Set /A "midY=!oY!"
    If !oX! LSS !midX! Set /A "midX=!oX!"
   )
   Set "pixel=0"
   For %%B in ("!y1!;!x1!" "!y2!;!x2!" "!y3!;!x3!" "!y4!;!x4!") Do (
    Set /A pixel+=1
    For /F "Tokens=1,2 Delims=;" %%r in ("%%~B") Do (
     Set /A "ny!pixel!=(%%~s-midX)+!midY!,nx!pixel!=(%%~r-!midY!)+!midX!"
   ))
rem -------------------------------------------------------------------------- /* mirror */
  Set "pixel=0"
  Set /A lmidX=500,umidX=0
  For %%C in (!nx1! !nx2! !nx3! !nx4!) Do (
   If %%C LSS !lmidX! (Set /A "lmidX=%%C")
   If %%C GTR !umidX! (Set /A "umidX=%%C")
  )
  Set /A "Mid.X=( !lmidX! + !umidX! ) / 2"
  For %%X in (!nx1! !nx2! !nx3! !nx4!) Do (
   Set /A "pixel=!pixel! + 1"
   Set /A "nx!pixel!=%%X + 1"
   IF %%X LSS !Mid.X! (Set /A "nx!pixel!= %%X + ((!Mid.X!-%%X) * 2) + 1")
   IF %%X GTR !Mid.X! (Set /A "nx!pixel!= %%X - ((%%X-!Mid.X!) * 2) + 1")
  )
rem ------------------------------------------- /* collision detection for rotated coords */
   Set "valid=0"
   For /L %%i in (1 1 4)Do (
    for %%c in ("!ny%%i!;!nx%%i!")Do If "!}%%~c!" == "" (
     Set /A "valid=!valid!+1"
  ))
   If "!valid!" == "4" (
    For %%v in (x y)Do For /L %%i in (1 1 4)Do (
      Set "%%v%%i=!n%%v%%i!"
 )))
rem --------------------------------------------------------------- /* end rotation logic */
rem ------------------------------------------------------------ /* display current state */
  TYPE "%TEMP%\tetris.~tmp"
  %HideLast%
  %ShowPiece%
)
Goto :loop
rem ----------------------------- /* test for completed line when a piece is set in place */
:isMatch
 Set "match=0"
 Set "ymin=42"
 Set "ymax=0"
 For %%n in (!y1! !y2! !y3! !y4!)Do (
  if %%n gtr !ymax! Set "ymax=%%n"
  if %%n lss !ymin! Set "ymin=%%n"
 )
rem ------------- /* test completion of line for each y coord for last piece set in place */
 For /L %%i in (!ymin! 1 !ymax!)Do (
  Set "#of10=0"
  For /L %%c in (2 1 11)Do If Not "!}%%i;%%c!" == "" Set /A "#of10=!#of10!+1"
  If "!#of10!" == "10" (
   Set /A "match=!match!+1"
   Set /A "Score+=(150 * !match!)"
   Set /A "lineabove=%%i-1"
   For /L %%n in (0 1 !lineabove!) Do (
    Set /A "offset=%%n+1"
rem -------------------------- /* transfer updated coord values after iteration complete */
    For %%o in (!offset!)Do For /L %%x in (2 1 11) Do If not "!}%%n;%%x!" == "" (
     Set "n}%%o;%%x=!}%%n;%%x:[%%n;=[%%o;!"
    ) Else (
     Set "n}%%o;%%x="
   ))
   For /L %%Y in (1 1 %%i) Do For /L %%X in (2 1 11) Do Set "}%%Y;%%X=!n}%%Y;%%X!"
   CLS
 ))
rem ----------------------------- /* Update display values for each cell to display file */
 >"%TEMP%\tetris.~tmp" (For /F "Tokens=2* Delims==" %%G in ('Set "}"')Do Echo/%%G)
Exit /B 0
:gameover
 Echo/| CHOICE /N 2> nul & rem BEL
 Echo/%\E%[2;20H%\E%[31mGame Over.%\E%[31m
 Pause > Nul
:quit
rem -------------------------------------- /* restore the cursor ; End of script cleanup */
 <nul Set /P "=%\E%[?25h"
 Del /Q	"%TEMP%\tetris.~tmp" 2> nul
 Endlocal
 Endlocal
 cls
 Title
Goto :Eof
Edit:
Getkeys.exe version now available for download
https://drive.google.com/file/d/1iLm9Rs ... sp=sharing
Watch:
https://www.youtube.com/watch?v=Vwo00t7HH2o

Controls for getkey version:
arrow keys for left right down
space = rotate
escape = quit
enter = pause
PageDown = Drop Piece
Attachments
Tetris.txt
(8.62 KiB) Downloaded 17 times

Aacini
Expert
Posts: 1675
Joined: 06 Dec 2011 22:15
Location: México City, México

Re: Batch Games

#20 Post by Aacini » 08 Nov 2020 09:48

Perhaps you could be interested in my Tetris game in a pure Batch file that uses no additional or auxiliary programs. There is also a version of Tetris in color that uses a PowerShell engine to Read arrow keys and show color text in an efficient way.

Antonio

Image

T3RRY
Posts: 96
Joined: 06 May 2020 10:14

Re: Batch Games

#21 Post by T3RRY » 08 Nov 2020 16:29

Aacini wrote:
08 Nov 2020 09:48
Perhaps you could be interested in my Tetris game in a pure Batch file that uses no additional or auxiliary programs. There is also a version of Tetris in color that uses a PowerShell engine to Read arrow keys and show color text in an efficient way.

Antonio

Hi Antonio, had already seen your versions - the idea of a more efficient pure batch controller is tempting. The PowerShell engine is definitely worth trying out or offering as an alternative.

Making Tetris was a thought experiment for me in how I might approach it using VT codes. As such the methodology I've used is somewhat different to other versions of Tetris I've seen out there.

ShadowThief
Expert
Posts: 992
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: Batch Games

#22 Post by ShadowThief » 08 Nov 2020 16:45

Once upon a time, I took a bunch of games written in BASIC and ported them to batch: https://github.com/sintrode/batch_minigames

Treasure.bat is there because there was a topic on there about code for calculating square roots that I wanted to try out.

Post Reply