T3RRYT3RR0R

Tic Tac Toe

Jan 11th, 2021 (edited)
725
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. :start ::: [ * Author: T3RRY * ] Creation Date - 12/01/2021 ::: WINDOWS 10 only
  2. @Echo off & mode 50,11
  3.  For /F %%a in ('echo prompt $E ^| cmd')do Set "\E=%%a"
  4. Set LF=^
  5.  
  6. %= ! linefeed var. Do not remove or modify this line or above 2 lines ! =%
  7.  CLS & Set "Grid=<nul Set /P "=%\E%[2;13H%\E%[37mDraw       %\E%[34mWin        %\E%[33mLose%\E%[5;1H!Spacer!%\E%[?25l%\E%[0m%\E%[35m%\E%[0m%\E%[35m[%\E%[90m!c7:7=%\E%[7m7!%\E%[0m%\E%[35m][%\E%[90m!c8:8=%\E%[7m8!%\E%[0m%\E%[35m][%\E%[90m!c9:9=%\E%[7m9!%\E%[0m%\E%[35m]!LF!!Spacer![%\E%[90m!c4:4=%\E%[7m4!%\E%[0m%\E%[35m][%\E%[90m!c5:5=%\E%[7m5!%\E%[0m%\E%[35m][%\E%[90m!c6:6=%\E%[7m6!%\E%[0m%\E%[35m]!LF!!Spacer![%\E%[90m!c1:1=%\E%[7m1!%\E%[0m%\E%[35m][%\E%[90m!c2:2=%\E%[7m2!%\E%[0m%\E%[35m][%\E%[90m!c3:3=%\E%[7m3!%\E%[0m%\E%[35m]%\E%[0m""
  8.  Set "Reset=( Title #. Game over. ) & Timeout /t 3 /Nobreak > nul & Endlocal & Goto :start"
  9.  Set "?.Cells=For %%V in ("!c1!!c4!!c7!" "!c2!!c5!!c8!" "!c3!!c6!!c9!" "!c1!!c2!!c3!" "!c4!!c5!!c6!" "!c7!!c8!!c9!" "!c3!!c5!!c7!" "!c1!!c5!!c9!")Do "
  10.  Setlocal EnableExtensions EnableDelayedExpansion
  11.  If not "%~2" == "" (Set "P1=%~1"& Set "P2=%~2"&Set "P1=!P1:~-1!" &Set "P2=!P2:~-1!")Else (Set "P1=X"& Set "P2=O")
  12.  Set "Cho= 123456789"& Set "turn=9"& For /L %%n in (1 1 9)Do Set "c%%n=%%n"
  13.  For /L %%n in (1 1 20)Do Set "Spacer= !Spacer!"
  14.  For /F "Delims=" %%v in ('set /A "!random! %%2 + 1"')Do Goto p%%v
  15. :p1
  16.  %GRID% & TITLE Enter a number - Available: %Cho% or [E]xit
  17.  For /F "Delims=" %%G in ('Choice /N /C:%Cho: =%e')Do (
  18.   Set "c%%G=!P1!"& Set "Cho=!Cho:%%G=!"& Set /A turn-=1
  19.   If %%G == E Exit /b 0)
  20.  %GRID:90=32% & Call :Delay 2> nul
  21. :p2
  22.  TITLE Tic Tac Toe & %?.Cells% If "%%~V" == "!p1!!p1!!p1!" Goto :Win
  23.  Set "move="&Set "line="& %?.Cells% For %%c in (!P1! !P2!)Do (
  24.   Set "line=%%~V"
  25.   For /L %%n in (1 1 9)Do ( :# Test ideal move; Priority - Take win ; block player
  26.    Set "line=!line:%%n%%c%%c=!"
  27.    If not "!line!" == "" Set "line=!line:%%c%%n%%c=!"
  28.    If not "!line!" == "" Set "line=!line:%%c%%c%%n=!"
  29.    If "!line!" == "" (Set "move=%%n")))
  30.  Call :AI "!P2!" && %GRID:90=31% & Call :Delay 2> nul
  31.  %?.Cells% If "%%~V" == "!p2!!p2!!p2!" Goto :Lose
  32.  If !turn! LEQ 0 ( %GRID:90=37% & %Reset:#=Draw% )Else Goto p1
  33. :AI [ Enact best available move option win; block player win; centre; random ]
  34.  If not "%move%" == "" (
  35.   Set "c%move%=%~1" & Set "Cho=!Cho:%move%=!" & Set /A "turn-=1"
  36.   Exit /B 0)
  37.  Set "tCho=!Cho:5=!"& If Not "!tCho!" == "!Cho!" (
  38.   Set "c5=%~1" & Set "Cho=!Cho:5=!" & Set /A "turn-=1"
  39.   Exit /B 0)
  40.  For /F "Delims=" %%v in ('set /A "!random! %%!turn! + 1" 2^> nul ')Do (
  41.   For %%i in ("!Cho:~%%v,1!")Do If not "!Cho:~%%v,1!" == " " If "!c%%~i!" == "%%~i" (
  42.    Set "c%%~i=%~1" & Set "Cho=!Cho:%%~i=!" & Set /A "turn-=1"
  43.    Exit /B 0))
  44.  If !turn! EQU 0 (Exit /B 0)Else Goto :AI
  45. :Win
  46.  %Grid:90=34% & %Reset:#=You Won%
  47. :Lose
  48.  %Grid:90=33% & %Reset:#=You Lost%
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×