Advanced Tic-Tac-Toe - Player V CPU - Mr Liam - Sep 23, 2012
You, I made it.
I had much trouble, but it's quite fun to play. ^^
Code @echo off
title TTT
setlocal enabledelayedexpansion
set f=1
echo.
if %f%==1 timeout 1 /nobreak >nul
echo /--\
if %f%==1 timeout 1 /nobreak >nul
echo ^| ^|
if %f%==1 timeout 1 /nobreak >nul
echo ^| ^|
if %f%==1 timeout 1 /nobreak >nul
echo ^| ^|
if %f%==1 timeout 1 /nobreak >nul
echo \--/
if %f%==1 timeout 1 /nobreak >nul
set f=0 >nul
set xwins=0
set owins=0
set t=O
: start
set 1=1
set 2=2
set 3=3
set 4=4
set 5=5
set 6=6
set 7=7
set 8=8
set 9=9
cls
: board
cls
echo.
echo /--\
echo ^| !7! !8! !9! ^| X: %xwins%
echo ^| !4! !5! !6! ^|
echo ^| !1! !2! !3! ^| O: %owins%
echo \--/
set f=0 >nul
echo.
if !1!==X if !4!==X if !7!==X goto xwin
if !1!==O if !4!==O if !7!==O goto owin
if !2!==X if !5!==X if !8!==X goto xwin
if !2!==O if !5!==O if !8!==O goto owin
if !3!==X if !6!==X if !9!==X goto xwin
if !3!==O if !6!==O if !9!==O goto owin
::Coded by Liam Allan :D
if !1!==X if !2!==X if !3!==X goto xwin
if !1!==O if !2!==O if !3!==O goto owin
if !4!==X if !5!==X if !6!==X goto xwin
if !4!==O if !5!==O if !6!==O goto owin
if !7!==X if !8!==X if !9!==X goto xwin
if !7!==O if !8!==O if !9!==O goto owin
if !1!==X if !5!==X if !9!==X goto xwin
if !1!==O if !5!==O if !9!==O goto owin
if !3!==X if !5!==X if !7!==X goto xwin
if !3!==O if !5!==O if !7!==O goto owin
if not !1!==1 if not !2!==2 if not !3!==3 if not !4!==4 if not !5!==5 if not !6!==6 if not !7!==7 if not !8!==8 if not !9!==9 goto nowin
echo %t%, your go! Choose a number..
if %t%==O goto some1
: playerag
CHOICE /C 123456789 >nul
if !%errorlevel%!==X goto playerag
if !%errorlevel%!==O goto playerag
set !%errorlevel%!=X
if %t%==X (set t=O) else (set t=X)
::Coded by Liam Allan :D
goto board
: some1
timeout 1 /nobreak >nul
set go=0
::Coded by Liam Allan :D
: smart
if %go%==0 if !3!==X if !9!==X if !6!==6 set 6=O&set go=1
if %go%==0 if !1!==O if !4!==O if !7!==7 set 7=O&set go=1
if %go%==0 if !2!==O if !5!==O if !8!==8 set 8=O&set go=1
if %go%==0 if !3!==O if !6!==O if !9!==9 set 9=O&set go=1
if %go%==0 if !1!==O if !2!==O if !3!==3 set 3=O&set go=1
if %go%==0 if !4!==O if !5!==O if !6!==6 set 6=O&set go=1
if %go%==0 if !7!==O if !8!==O if !9!==9 set 9=O&set go=1
if %go%==0 if !7!==O if !4!==O if !1!==1 set 1=O&set go=1
if %go%==0 if !8!==O if !5!==O if !2!==2 set 2=O&set go=1
if %go%==0 if !9!==O if !6!==O if !3!==3 set 3=O&set go=1
if %go%==0 if !9!==O if !8!==O if !7!==7 set 7=O&set go=1
if %go%==0 if !6!==O if !5!==O if !4!==4 set 4=O&set go=1
if %go%==0 if !3!==O if !2!==O if !1!==1 set 1=O&set go=1
if %go%==0 if !1!==O if !5!==O if !9!==9 set 9=O&set go=1
if %go%==0 if !3!==O if !5!==O if !7!==7 set 7=O&set go=1
if %go%==0 if !7!==O if !5!==O if !3!==3 set 3=O&set go=1
if %go%==0 if !9!==O if !5!==O if !1!==1 set 1=O&set go=1
::Coded by Liam Allan :D
if %go%==0 if !1!==O if !9!==O if !5!==5 set 5=O&set go=1
if %go%==0 if !3!==O if !7!==O if !5!==5 set 5=O&set go=1
if %go%==0 if !1!==O if !3!==O if !2!==2 set 2=O&set go=1
if %go%==0 if !1!==O if !7!==O if !4!==4 set 4=O&set go=1
if %go%==0 if !7!==O if !9!==O if !8!==8 set 8=O&set go=1
if %go%==0 if !9!==O if !3!==O if !6!==6 set 6=O&set go=1
if %go%==0 if !2!==O if !8!==O if !5!==5 set 5=O&set go=1
if %go%==0 if !4!==O if !6!==O if !5!==5 set 5=O&set go=1
if %go%==0 if !1!==X if !4!==X if !7!==7 set 7=O&set go=1
if %go%==0 if !2!==X if !5!==X if !8!==8 set 8=O&set go=1
if %go%==0 if !3!==X if !6!==X if !9!==9 set 9=O&set go=1
if %go%==0 if !1!==X if !2!==X if !3!==3 set 3=O&set go=1
if %go%==0 if !4!==X if !5!==X if !6!==6 set 6=O&set go=1
if %go%==0 if !7!==X if !8!==X if !9!==9 set 9=O&set go=1
if %go%==0 if !7!==X if !4!==X if !1!==1 set 1=O&set go=1
if %go%==0 if !8!==X if !5!==X if !2!==2 set 2=O&set go=1
if %go%==0 if !9!==X if !6!==X if !3!==3 set 3=O&set go=1
if %go%==0 if !9!==X if !8!==X if !7!==7 set 7=O&set go=1
if %go%==0 if !6!==X if !5!==X if !4!==4 set 4=O&set go=1
if %go%==0 if !3!==X if !2!==X if !1!==1 set 1=O&set go=1
if %go%==0 if !1!==X if !5!==X if !9!==9 set 9=O&set go=1
if %go%==0 if !3!==X if !5!==X if !7!==7 set 7=O&set go=1
if %go%==0 if !7!==X if !5!==X if !3!==3 set 3=O&set go=1
if %go%==0 if !9!==X if !5!==X if !1!==1 set 1=O&set go=1
::Coded by Liam Allan :D
if %go%==0 if !1!==X if !9!==X if !5!==5 set 5=O&set go=1
if %go%==0 if !3!==X if !7!==X if !5!==5 set 5=O&set go=1
if %go%==0 if !1!==X if !3!==X if !2!==2 set 2=O&set go=1
if %go%==0 if !1!==X if !7!==X if !4!==4 set 4=O&set go=1
if %go%==0 if !7!==X if !9!==X if !8!==8 set 8=O&set go=1
if %go%==0 if !9!==X if !3!==X if !6!==6 set 6=O&set go=1
if %go%==0 if !2!==X if !8!==X if !5!==5 set 5=O&set go=1
if %go%==0 if !4!==X if !6!==X if !5!==5 set 5=O&set go=1
if %go%==1 goto finch
: again
set /a ran=%random%%%9
if %ran%==0 if %go%==0 if not !1!==X if not !1!==O set 1=O&set go=1
if %ran%==1 if %go%==0 if not !2!==X if not !2!==O set 2=O&set go=1
if %ran%==2 if %go%==0 if not !3!==X if not !3!==O set 3=O&set go=1
if %ran%==3 if %go%==0 if not !4!==X if not !4!==O set 4=O&set go=1
if %ran%==4 if %go%==0 if not !5!==X if not !5!==O set 5=O&set go=1
if %ran%==5 if %go%==0 if not !6!==X if not !6!==O set 6=O&set go=1
if %ran%==6 if %go%==0 if not !7!==X if not !7!==O set 7=O&set go=1
::Coded by Liam Allan :D
if %ran%==7 if %go%==0 if not !8!==X if not !8!==O set 8=O&set go=1
if %ran%==8 if %go%==0 if not !9!==X if not !9!==O set 9=O&set go=1
: finch
if %go%==0 goto again
if %t%==X (set t=O) else (set t=X)
goto board
: nowin
echo No one has won.
if %t%==X (set t=O) else (set t=X)
pause >nul
goto start
: xwin
::Coded by Liam Allan :D
echo X wins!
set t=O
set /a xwins=%xwins%+1
pause >nul
goto start
: owin
echo O wins!
set t=X
set /a owins=%owins%+1
pause >nul
goto start
Edit of code 1: Made it even more smarter by not trying to make you loose, and tries to win too.
Edit of code 2: Why not add some type of design?
Edit of code 3: Some fixes.
Edit of code 4: More fixes.
Edit of code 5: Fixed over-writing the Xs/Os
Edit of code 6: Found a flaw where it wouldn't check if 3=x & 9=x at the same time.
Edit of code 7: Found another flaw, where O wouldn't set on 6 when 3=x & 9=x at the same time.
Enjoy. ^^
* - G T X - Sep 23, 2012
Code ::Coded by Liam Allan :D
::Coded by Liam Allan :D
::Coded by Liam Allan :D
::Coded by Liam Allan :D
::Coded by Liam Allan :D
::Coded by Liam Allan :D
...is all I saw LOL
JK, but nice work, gonna test it out :)
Edit: Found a bug - you can press the same number repeatedly and the code skips right to the computer's turn. You should include a check to see if the option the user selects is already occupied by an O or an X. You can also overwrite the computer's O's lol... >.<
* - SoulByte - Sep 23, 2012
Nice work. Would be fun to make some large® game with AI.
So many if's in your code. o_O
* - Mr Liam - Sep 23, 2012
(Sep 23, 2012 09:02 AM)SoulByte Wrote: Nice work. Would be fun to make some large® game with AI.
So many if's in your code. o_O
Aha, I know. But anything to make it work! :D
* - G T X - Sep 23, 2012
You can still overwrite the opponent's letters. And the design... (EDIT) well the forums automatically remove the spaces and dashes :\ Nice and simple though, I like.
* - Mr Liam - Sep 23, 2012
(Sep 23, 2012 10:02 AM)G T X Wrote: You can still overwrite the opponent's letters. And the design... well it should be fixed. It needs to have more spaces to look right.
Code if %f%==1 timeout 1 /nobreak >nul
echo /--\
if %f%==1 timeout 1 /nobreak >nul
echo ^| ^|
if %f%==1 timeout 1 /nobreak >nul
echo ^| ^|
if %f%==1 timeout 1 /nobreak >nul
echo ^| ^|
if %f%==1 timeout 1 /nobreak >nul
echo \--/
if %f%==1 timeout 1 /nobreak >nul
set f=0 >nul
[code]
And also the main playing screen:
[code]
: board
cls
echo.
echo /--\
echo ^| !7! !8! !9! ^|
echo ^| !4! !5! !6! ^|
echo ^| !1! !2! !3! ^|
echo \--/
set f=0 >nul
echo.
Ah! It does have more spaces. Looks like HackForums have taken them out! Sorry 'bout that.
* - THUG x WRECK - Sep 23, 2012
Fuck, if only I knew who coded this game.
* - Quantum Batch - Sep 23, 2012
It works ok but if O takes a place I can easily take it back :/. Other than that this is a fun game to play.
* - Mr Liam - Sep 23, 2012
(Sep 23, 2012 10:08 AM)Quantum Batch Wrote: It works ok but if O takes a place I can easily take it back :/. Other than that this is a fun game to play.
Just fixed it, take a look now. :P :D
* - G T X - Sep 23, 2012
(Sep 23, 2012 10:10 AM)Liam Allan Wrote: Just fixed it, take a look now. :P :D
You fixed the O's now what about the X's - you can still overwrite those. It basically skips your turn if you choose a spot you've already marked.
* - Mr Liam - Sep 23, 2012
(Sep 23, 2012 10:14 AM)G T X Wrote: You fixed the O's now what about the X's - you can still overwrite those. It basically skips your turn if you choose a spot you've already marked.
Sorry about that.
Fixed, check edit of code 5. :D
* - Isometrical - Sep 23, 2012
It says "@echo off" twice in your code tags, is that supposed to be there?
Other than that cool game. :D
* - Mr Liam - Sep 23, 2012
(Sep 23, 2012 10:17 AM)Isometrical Wrote: It says "@echo off" twice in your code tags, is that supposed to be there?
Other than that cool game. :D
It's gone in the latest edit, but good spot.
* - SIM-1073426 - Sep 23, 2012
Eh, it seems like I can't even participate in the match because the X doesn't show.
* - G T X - Sep 23, 2012
Now I can't even use my X's lol... >.< It just skips my turn completely. The computer wins every game :P How about testing it before editing again?
|