T3RRYT3RR0R

Tic Tac Toe

Jan 11th, 2021 (edited)
1,350
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 2.81 KB | None | 0 0
  1. ::: [ * Author: T3RRY * ] Creation Date - 12/01/2021 ::: WINDOWS 10 only
  2. @Echo off & mode 50,11
  3.  
  4.  For /F %%a in ('echo prompt $E ^| cmd')do Set "\E=%%a"
  5.  Set LF=^
  6.  
  7. %= ! linefeed var. Do not remove or modify this line or above 2 lines ! =%
  8.  
  9.  IF "!!" == "" ( Echo DelayedExpansion should not be enabled yet&Pause & Goto:EOF )
  10.  
  11.  Set Grid=^<nul Set /P =%\E%[2;13H%\E%[37mDraw       %\E%[34mWin        %\E%[33mLose%\E%[5;1H^
  12.  !Spacer!%\E%[?25l%\E%[35m[%\E%[32m!c7:7=%\E%[90m7!%\E%[35m][%\E%[32m!c8:8=%\E%[90m8!%\E%[35m][%\E%[32m!c9:9=%\E%[90m9!%\E%[35m]!LF!^
  13.  !Spacer![%\E%[32m!c4:4=%\E%[90m4!%\E%[35m][%\E%[32m!c5:5=%\E%[90m5!%\E%[35m][%\E%[32m!c6:6=%\E%[90m6!%\E%[35m]!LF!^
  14.  !Spacer![%\E%[32m!c1:1=%\E%[90m1!%\E%[35m][%\E%[32m!c2:2=%\E%[90m2!%\E%[35m][%\E%[32m!c3:3=%\E%[90m3!%\E%[35m]%\E%[0m
  15.  
  16.  Set "Reset=( Title #. Game over. ) & Timeout /t 3 /Nobreak > nul & Endlocal & Goto :start"
  17.  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 "
  18.  
  19. :start
  20.  CLS
  21.  Setlocal EnableExtensions EnableDelayedExpansion
  22.  
  23.  %!! priority =%
  24.  Set "Cho= 5 1 3 7 9 2 4 6 8"
  25.  Set "turn=9"
  26.  For /L %%n in (1 1 9)Do Set "c%%n=%%n"
  27.  Set "Spacer="
  28.  For /L %%n in (0 1 18)Do Set "Spacer= !Spacer!"
  29.  For /F "Delims=" %%v in ('set /A "!random! %%2 + 1"')Do Goto:p%%v
  30.  
  31. :p1
  32.  %GRID% & TITLE Enter a number - Available: %Cho% or [E]xit
  33.  For /F "Delims=" %%G in ('Choice /N /C:%Cho: =%e')Do (
  34.   Set "c%%G=X"& Set "Cho=!Cho: %%G=!"& Set /A turn-=1
  35.   If /I "%%G" == "E" (
  36.    Endlocal
  37.    Exit /b 0))
  38.  TITLE Tic Tac Toe & %?.Cells% If "%%~V" == "XXX" Goto :Win
  39.  
  40. :p2
  41.  %GRID:32=31%
  42.  Set "move="&Set "line="& %?.Cells% For %%c in (X O)Do (
  43.   Set "line=%%~V"
  44.   For /L %%n in (1 1 9)Do ( %= Test ideal move; Priority - Take win ; block player =%
  45.    Set "line=!line:%%n%%c%%c=!"
  46.    If not "!line!" == "" Set "line=!line:%%c%%n%%c=!"
  47.    If not "!line!" == "" Set "line=!line:%%c%%c%%n=!"
  48.    If "!line!" == "" (Set "move=%%n")))
  49.  
  50.  Call :AI &&  %?.Cells% If "%%~V" == "OOO" Goto :Lose
  51.  For /l %%. in (1 1 150000)Do rem
  52.  If !turn! LEQ 0 (
  53.   %GRID:32=37%
  54.   Timeout /T 2 > nul
  55.   %Reset:#=Draw%
  56.   )Else Goto p1
  57.  
  58. :AI %= Enact best available move option - win; block player win; centre; corners; mid-outers =%
  59.     %!! filled by AI; GT# is Game turn Number =%
  60.  If not "%move%" == "" (
  61.   Set "c%move%=O" & Set "Cho=!Cho: %move%=!" & Set /A "turn-=1"
  62.   Exit /B 0)
  63.  
  64.  For %%i in (%Cho%)DO (
  65.   Set "tCho=!Cho:%%i=!"
  66.   If Not "!tCho!" == "!Cho!" (
  67.    Set "c%%i=O" & Set "Cho=!Cho: %%i=!" & Set /A "turn-=1"
  68.    Exit /B 0))
  69.  
  70.  If !turn! EQU 0 Exit /B 0
  71.  
  72. :Win
  73.  %Grid:32=34%
  74.  Timeout /T 2 > nul
  75.  %Reset:#=You Won%
  76. :Lose
  77.  %Grid:32=33%
  78.  Timeout /T 2 > nul
  79.  %Reset:#=You Lost%
Add Comment
Please, Sign In to add comment