Advertisement
skyfire9999

Tictactoe by MacFromOK

Jun 14th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 11.50 KB | None | 0 0
  1. REM By MacFromOK.  Cool tech site! [url]http://forums.techguy.org/[/url]
  2. @ECHO OFF
  3. :BEGIN  
  4.  REM Skill level
  5.   set sl=
  6.   cls
  7.   echo                       Tic Tac Toe by Mac                            (Q to quit)
  8.   echo.
  9.   echo.
  10.   echo        Pick your skill level (press a number)
  11.   echo.
  12.   echo               (1) Children under 6
  13.   echo               (2) Average Mental Case
  14.   echo               (3) Oversized Ego  
  15.   CHOICE /c:123q /n > nul
  16.   if errorlevel 4 goto end
  17.   if errorlevel 3 set sl=3
  18.   if errorlevel 3 goto layout
  19.   if errorlevel 2 set sl=2
  20.   if errorlevel 2 goto layout
  21.   set sl=1
  22.  
  23. :LAYOUT
  24.  REM Player turn ("x" or "o")
  25.   set pt=
  26.  REM Game winner ("x" or "o")
  27.   set gw=
  28.  REM No moves
  29.   set nm=
  30.  REM Set to one blank space after equal sign (check with cursor end)
  31.   set t1=
  32.   set t2=
  33.   set t3=
  34.   set t4=
  35.   set t5=
  36.   set t6=
  37.   set t7=
  38.   set t8=
  39.   set t9=
  40.  
  41. :UPDATE
  42.   cls
  43.   echo   (S to set skill level)       Tic Tac Toe by Mac                   (Q to quit)
  44.   echo.
  45.   echo                               You are the X player.
  46.   echo                    Press the number where you want to put an X.    
  47.   echo.
  48.   echo   Skill level %sl%                       7 8 9
  49.   echo                                       4 5 6
  50.   echo                                       1 2 3
  51.   echo.
  52.   echo                                       :   :
  53.   echo                                     %t1% : %t2% : %t3%
  54.   echo                                   ....:...:....
  55.   echo                                     %t4% : %t5% : %t6%
  56.   echo                                   ....:...:....
  57.   echo                                     %t7% : %t8% : %t9%
  58.   echo                                       :   :
  59.   if "%gw%"=="x" goto winx2
  60.   if "%gw%"=="o" goto wino2
  61.   if "%nm%"=="0" goto nomoves
  62.  
  63. :PLAYER
  64.   set pt=x
  65.  REM Layout is for keypad. Change CHOICE to "/c:123456789sq  /n > nul"
  66.  REM for numbers to start at top left (also change user layout above).
  67.   CHOICE /c:789456123sq /n > nul
  68.   if errorlevel 11 goto end
  69.   if errorlevel 10 goto begin
  70.   if errorlevel 9 goto 9
  71.   if errorlevel 8 goto 8
  72.   if errorlevel 7 goto 7
  73.   if errorlevel 6 goto 6
  74.   if errorlevel 5 goto 5
  75.   if errorlevel 4 goto 4
  76.   if errorlevel 3 goto 3
  77.   if errorlevel 2 goto 2
  78.   goto 1
  79.  
  80. :1  
  81.  REM Check if "x" or "o" already in square.
  82.   if "%t1%"=="x" goto player
  83.   if "%t1%"=="o" goto player
  84.   set t1=x
  85.   goto check
  86. :2  
  87.   if "%t2%"=="x" goto player
  88.   if "%t2%"=="o" goto player
  89.   set t2=x
  90.   goto check
  91. :3  
  92.   if "%t3%"=="x" goto player
  93.   if "%t3%"=="o" goto player
  94.   set t3=x
  95.   goto check
  96. :4  
  97.   if "%t4%"=="x" goto player
  98.   if "%t4%"=="o" goto player
  99.   set t4=x
  100.   goto check
  101. :5  
  102.   if "%t5%"=="x" goto player
  103.   if "%t5%"=="o" goto player
  104.   set t5=x
  105.   goto check
  106. :6  
  107.   if "%t6%"=="x" goto player
  108.   if "%t6%"=="o" goto player
  109.   set t6=x
  110.   goto check
  111. :7  
  112.   if "%t7%"=="x" goto player
  113.   if "%t7%"=="o" goto player
  114.   set t7=x
  115.   goto check
  116. :8  
  117.   if "%t8%"=="x" goto player
  118.   if "%t8%"=="o" goto player
  119.   set t8=x
  120.   goto check
  121. :9  
  122.   if "%t9%"=="x" goto player
  123.   if "%t9%"=="o" goto player
  124.   set t9=x
  125.   goto check
  126.  
  127. :COMPUTER
  128.   set pt=o
  129.   if "%sl%"=="1" goto skill1  
  130. REM (win corner to corner)
  131.   if "%t1%"=="o" if "%t3%"=="o" if not "%t2%"=="x" if not "%t2%"=="o" goto c2
  132.   if "%t1%"=="o" if "%t9%"=="o" if not "%t5%"=="x" if not "%t5%"=="o" goto c5
  133.   if "%t1%"=="o" if "%t7%"=="o" if not "%t4%"=="x" if not "%t4%"=="o" goto c4  
  134.   if "%t3%"=="o" if "%t7%"=="o" if not "%t5%"=="x" if not "%t5%"=="o" goto c5
  135.   if "%t3%"=="o" if "%t9%"=="o" if not "%t6%"=="x" if not "%t6%"=="o" goto c6
  136.   if "%t9%"=="o" if "%t7%"=="o" if not "%t8%"=="x" if not "%t8%"=="o" goto c8
  137. REM (win outside middle to outside middle)
  138.   if "%t2%"=="o" if "%t8%"=="o" if not "%t5%"=="x" if not "%t5%"=="o" goto c5
  139.   if "%t4%"=="o" if "%t6%"=="o" if not "%t5%"=="x" if not "%t5%"=="o" goto c5
  140. REM (win all others)
  141.   if "%t1%"=="o" if "%t2%"=="o" if not "%t3%"=="x" if not "%t3%"=="o" goto c3
  142.   if "%t1%"=="o" if "%t5%"=="o" if not "%t9%"=="x" if not "%t9%"=="o" goto c9
  143.   if "%t1%"=="o" if "%t4%"=="o" if not "%t7%"=="x" if not "%t7%"=="o" goto c7
  144.   if "%t2%"=="o" if "%t5%"=="o" if not "%t8%"=="x" if not "%t8%"=="o" goto c8
  145.   if "%t3%"=="o" if "%t2%"=="o" if not "%t1%"=="x" if not "%t1%"=="o" goto c1
  146.   if "%t3%"=="o" if "%t5%"=="o" if not "%t7%"=="x" if not "%t7%"=="o" goto c7
  147.   if "%t3%"=="o" if "%t6%"=="o" if not "%t9%"=="x" if not "%t9%"=="o" goto c9
  148.   if "%t4%"=="o" if "%t5%"=="o" if not "%t6%"=="x" if not "%t6%"=="o" goto c6
  149.   if "%t6%"=="o" if "%t5%"=="o" if not "%t4%"=="x" if not "%t4%"=="o" goto c4
  150.   if "%t7%"=="o" if "%t4%"=="o" if not "%t1%"=="x" if not "%t1%"=="o" goto c1
  151.   if "%t7%"=="o" if "%t5%"=="o" if not "%t3%"=="x" if not "%t3%"=="o" goto c3
  152.   if "%t7%"=="o" if "%t8%"=="o" if not "%t9%"=="x" if not "%t9%"=="o" goto c9
  153.   if "%t8%"=="o" if "%t5%"=="o" if not "%t2%"=="x" if not "%t2%"=="o" goto c2
  154.   if "%t9%"=="o" if "%t8%"=="o" if not "%t7%"=="x" if not "%t7%"=="o" goto c7
  155.   if "%t9%"=="o" if "%t5%"=="o" if not "%t1%"=="x" if not "%t1%"=="o" goto c1
  156.   if "%t9%"=="o" if "%t6%"=="o" if not "%t3%"=="x" if not "%t3%"=="o" goto c3
  157. REM (block general attempts) -----------------------------------------------
  158.   if "%t1%"=="x" if "%t2%"=="x" if not "%t3%"=="x" if not "%t3%"=="o" goto c3
  159.   if "%t1%"=="x" if "%t5%"=="x" if not "%t9%"=="x" if not "%t9%"=="o" goto c9
  160.   if "%t1%"=="x" if "%t4%"=="x" if not "%t7%"=="x" if not "%t7%"=="o" goto c7
  161.   if "%t2%"=="x" if "%t5%"=="x" if not "%t8%"=="x" if not "%t8%"=="o" goto c8
  162.   if "%t3%"=="x" if "%t2%"=="x" if not "%t1%"=="x" if not "%t1%"=="o" goto c1
  163.   if "%t3%"=="x" if "%t5%"=="x" if not "%t7%"=="x" if not "%t7%"=="o" goto c7
  164.   if "%t3%"=="x" if "%t6%"=="x" if not "%t9%"=="x" if not "%t9%"=="o" goto c9
  165.   if "%t4%"=="x" if "%t5%"=="x" if not "%t6%"=="x" if not "%t6%"=="o" goto c6
  166.   if "%t6%"=="x" if "%t5%"=="x" if not "%t4%"=="x" if not "%t4%"=="o" goto c4
  167.   if "%t7%"=="x" if "%t4%"=="x" if not "%t1%"=="x" if not "%t1%"=="o" goto c1
  168.   if "%t7%"=="x" if "%t5%"=="x" if not "%t3%"=="x" if not "%t3%"=="o" goto c3
  169.   if "%t7%"=="x" if "%t8%"=="x" if not "%t9%"=="x" if not "%t9%"=="o" goto c9
  170.   if "%t8%"=="x" if "%t5%"=="x" if not "%t2%"=="x" if not "%t2%"=="o" goto c2
  171.   if "%t9%"=="x" if "%t8%"=="x" if not "%t7%"=="x" if not "%t7%"=="o" goto c7
  172.   if "%t9%"=="x" if "%t5%"=="x" if not "%t1%"=="x" if not "%t1%"=="o" goto c1
  173.   if "%t9%"=="x" if "%t6%"=="x" if not "%t3%"=="x" if not "%t3%"=="o" goto c3
  174. REM (block obvious corner to corner)
  175.   if "%t1%"=="x" if "%t3%"=="x" if not "%t2%"=="x" if not "%t2%"=="o" goto c2
  176.   if "%t1%"=="x" if "%t9%"=="x" if not "%t5%"=="x" if not "%t5%"=="o" goto c5
  177.   if "%t1%"=="x" if "%t7%"=="x" if not "%t4%"=="x" if not "%t4%"=="o" goto c4  
  178.   if "%t3%"=="x" if "%t7%"=="x" if not "%t5%"=="x" if not "%t5%"=="o" goto c5
  179.   if "%t3%"=="x" if "%t9%"=="x" if not "%t6%"=="x" if not "%t6%"=="o" goto c6
  180.   if "%t9%"=="x" if "%t7%"=="x" if not "%t8%"=="x" if not "%t8%"=="o" goto c8
  181.   if "%sl%"=="2" goto skill2
  182. REM (block sneaky corner to corner 2-4, 2-6, etc.)
  183.   if "%t2%"=="x" if "%t4%"=="x" if not "%t1%"=="x" if not "%t1%"=="o" goto c1
  184.   if "%t2%"=="x" if "%t6%"=="x" if not "%t3%"=="x" if not "%t3%"=="o" goto c3
  185.   if "%t8%"=="x" if "%t4%"=="x" if not "%t7%"=="x" if not "%t7%"=="o" goto c7  
  186.   if "%t8%"=="x" if "%t6%"=="x" if not "%t9%"=="x" if not "%t9%"=="o" goto c9
  187. REM (block offset corner trap 1-8, 1-6, etc.)
  188.   if "%t1%"=="x" if "%t6%"=="x" if not "%t8%"=="x" if not "%t8%"=="o" goto c8
  189.   if "%t1%"=="x" if "%t8%"=="x" if not "%t6%"=="x" if not "%t6%"=="o" goto c6
  190.   if "%t3%"=="x" if "%t8%"=="x" if not "%t4%"=="x" if not "%t4%"=="o" goto c4
  191.   if "%t3%"=="x" if "%t4%"=="x" if not "%t8%"=="x" if not "%t8%"=="o" goto c8
  192.   if "%t9%"=="x" if "%t4%"=="x" if not "%t2%"=="x" if not "%t2%"=="o" goto c2
  193.   if "%t9%"=="x" if "%t2%"=="x" if not "%t4%"=="x" if not "%t4%"=="o" goto c4
  194.   if "%t7%"=="x" if "%t2%"=="x" if not "%t6%"=="x" if not "%t6%"=="o" goto c6
  195.   if "%t7%"=="x" if "%t6%"=="x" if not "%t2%"=="x" if not "%t2%"=="o" goto c2
  196.  
  197. :SKILL2
  198. REM (block outside middle to outside middle)
  199.   if "%t2%"=="x" if "%t8%"=="x" if not "%t5%"=="x" if not "%t5%"=="o" goto c5
  200.   if "%t4%"=="x" if "%t6%"=="x" if not "%t5%"=="x" if not "%t5%"=="o" goto c5
  201. REM (block 3 corner trap)
  202.   if "%t1%"=="x" if "%t9%"=="x" if not "%t2%"=="x" if not "%t2%"=="o" goto c2
  203.   if "%t3%"=="x" if "%t7%"=="x" if not "%t2%"=="x" if not "%t2%"=="o" goto c2
  204.   if "%t1%"=="x" if "%t9%"=="x" if not "%t4%"=="x" if not "%t4%"=="o" goto c4
  205.   if "%t3%"=="x" if "%t7%"=="x" if not "%t4%"=="x" if not "%t4%"=="o" goto c4
  206.   if "%t1%"=="x" if "%t9%"=="x" if not "%t6%"=="x" if not "%t6%"=="o" goto c6
  207.   if "%t3%"=="x" if "%t7%"=="x" if not "%t6%"=="x" if not "%t6%"=="o" goto c6
  208.   if "%t1%"=="x" if "%t9%"=="x" if not "%t8%"=="x" if not "%t8%"=="o" goto c8
  209.   if "%t3%"=="x" if "%t7%"=="x" if not "%t8%"=="x" if not "%t8%"=="o" goto c8
  210. :SKILL1
  211. REM (just take a turn)
  212.   if not "%t5%"=="x" if not "%t5%"=="o" goto c5
  213.   if not "%t1%"=="x" if not "%t1%"=="o" goto c1
  214.   if not "%t3%"=="x" if not "%t3%"=="o" goto c3
  215.   if not "%t7%"=="x" if not "%t7%"=="o" goto c7
  216.   if not "%t9%"=="x" if not "%t9%"=="o" goto c9
  217.   if not "%t2%"=="x" if not "%t2%"=="o" goto c2
  218.   if not "%t4%"=="x" if not "%t4%"=="o" goto c4
  219.   if not "%t6%"=="x" if not "%t6%"=="o" goto c6
  220.   if not "%t8%"=="x" if not "%t8%"=="o" goto c8
  221.   set nm=0
  222.   goto update
  223.  
  224. :C1  
  225.   set t1=o
  226.   goto check
  227. :C2  
  228.   set t2=o
  229.   goto check
  230. :C3  
  231.   set t3=o
  232.   goto check
  233. :C4  
  234.   set t4=o
  235.   goto check
  236. :C5  
  237.   set t5=o
  238.   goto check
  239. :C6  
  240.   set t6=o
  241.   goto check
  242. :C7  
  243.   set t7=o
  244.   goto check
  245. :C8  
  246.   set t8=o
  247.   goto check
  248. :C9  
  249.   set t9=o
  250.   goto check
  251.  
  252. :CHECK
  253.   if "%t1%"=="x" if "%t2%"=="x" if "%t3%"=="x" goto winx
  254.   if "%t4%"=="x" if "%t5%"=="x" if "%t6%"=="x" goto winx
  255.   if "%t7%"=="x" if "%t8%"=="x" if "%t9%"=="x" goto winx
  256.   if "%t1%"=="x" if "%t4%"=="x" if "%t7%"=="x" goto winx
  257.   if "%t2%"=="x" if "%t5%"=="x" if "%t8%"=="x" goto winx
  258.   if "%t3%"=="x" if "%t6%"=="x" if "%t9%"=="x" goto winx
  259.   if "%t1%"=="x" if "%t5%"=="x" if "%t9%"=="x" goto winx
  260.   if "%t3%"=="x" if "%t5%"=="x" if "%t7%"=="x" goto winx
  261.   if "%t1%"=="o" if "%t2%"=="o" if "%t3%"=="o" goto wino
  262.   if "%t4%"=="o" if "%t5%"=="o" if "%t6%"=="o" goto wino
  263.   if "%t7%"=="o" if "%t8%"=="o" if "%t9%"=="o" goto wino
  264.   if "%t1%"=="o" if "%t4%"=="o" if "%t7%"=="o" goto wino
  265.   if "%t2%"=="o" if "%t5%"=="o" if "%t8%"=="o" goto wino
  266.   if "%t3%"=="o" if "%t6%"=="o" if "%t9%"=="o" goto wino
  267.   if "%t1%"=="o" if "%t5%"=="o" if "%t9%"=="o" goto wino
  268.   if "%t3%"=="o" if "%t5%"=="o" if "%t7%"=="o" goto wino
  269.   if "%pt%"=="x" goto computer
  270.   if "%pt%"=="o" goto update
  271.  
  272. :WINX
  273.   set gw=x
  274.   goto update
  275. :WINX2
  276.   echo   You win!
  277.   echo   Play again (Y,N)?
  278.   CHOICE /c:ynsq /n > nul
  279.   if errorlevel 4 goto end
  280.   if errorlevel 3 goto begin
  281.   if errorlevel 2 goto end
  282.   goto layout
  283.  
  284. :WINO
  285.   set gw=o
  286.   goto update
  287. :WINO2
  288.   echo   Sorry, You lose.
  289.   echo   Play again (Y,N)?
  290.   CHOICE /c:ynsq /n > nul
  291.   if errorlevel 4 goto end
  292.   if errorlevel 3 goto begin
  293.   if errorlevel 2 goto end
  294.   goto layout
  295.  
  296. :NOMOVES
  297.   echo   There are no more moves left!
  298.   echo   Play again (Y,N)?
  299.   CHOICE /c:ynsq /n > nul
  300.   if errorlevel 4 goto end
  301.   if errorlevel 3 goto begin
  302.   if errorlevel 2 goto end
  303.   goto layout
  304.  
  305. :END
  306.   cls
  307.   echo Tic Tac Toe by Mac
  308.   echo.
  309.  REM Clear all variables (no spaces after equal sign).
  310.   set gw=
  311.   set nm=
  312.   set sl=
  313.   set pt=
  314.   set t1=
  315.   set t2=
  316.   set t3=
  317.   set t4=
  318.   set t5=
  319.   set t6=
  320.   set t7=
  321.   set t8=
  322.   set t9=
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement