[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[游戏娱乐] 批处理三子棋游戏

  1. @echo off
  2. setlocal enabledelayedexpansion
  3. mode con lines=25
  4. :start
  5. cls
  6. set str=a1a2a3b1b2b3c1c2c3
  7. set slt1=0
  8. for %%i in (a b c) do (
  9. set m%%i=
  10. for %%j in (1 2 3) do (
  11.   set m%%j=
  12.   set m%%i%%j=
  13.   set n%%i%%j=
  14. )
  15. )
  16. set mlr=
  17. set mrl=
  18. set mmlr=a1b2c3
  19. set mmrl=c1b2a3
  20. set win=
  21. for %%i in (a,b,c) do (
  22. for %%j in (1,2,3) do (
  23.   set %%i%%j=  
  24. )
  25. )
  26. echo   ┏━┳━┳━┓
  27. echo   ┃1 ┃2 ┃3 ┃                     
  28. echo   ┣━╋━╋━┫
  29. echo   ┃4 ┃5 ┃6 ┃                       
  30. echo   ┣━╋━╋━┫
  31. echo   ┃7 ┃8 ┃9 ┃                       
  32. echo   ┗━┻━┻━┛
  33. echo 谁先走?(c代表电脑,h代表人)
  34. set /p slt1=
  35. set human=
  36. set cpu=
  37. if %slt1% equ c set human=○&set cpu=●&goto 2
  38. if %slt1% equ C set human=○&set cpu=●&goto 2
  39. set human=●&set cpu=○
  40. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  41. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  42. :begin
  43. :1
  44. echo 请您走棋!(输入数字1~9)
  45. set /p slt2=
  46. if !slt2! equ 1 set slt2=a1
  47. if !slt2! equ 2 set slt2=b1
  48. if !slt2! equ 3 set slt2=c1
  49. if !slt2! equ 4 set slt2=a2
  50. if !slt2! equ 5 set slt2=b2
  51. if !slt2! equ 6 set slt2=c2
  52. if !slt2! equ 7 set slt2=a3
  53. if !slt2! equ 8 set slt2=b3
  54. if !slt2! equ 9 set slt2=c3
  55. if "!n%slt2%!" neq "" echo 此处已经有子!&goto 1
  56. set str=!str:%slt2%=!
  57. set mmrl=!mmrl:%slt2%=!
  58. set mmlr=!mmlr:%slt2%=!
  59. set %slt2%=%human%
  60. set m%slt2%=h
  61. set n%slt2%=h
  62. cls
  63. echo   ┏━┳━┳━┓
  64. echo   ┃%a1%┃%b1%┃%c1%┃                     
  65. echo   ┣━╋━╋━┫
  66. echo   ┃%a2%┃%b2%┃%c2%┃                       
  67. echo   ┣━╋━╋━┫
  68. echo   ┃%a3%┃%b3%┃%c3%┃                       
  69. echo   ┗━┻━┻━┛
  70. call :judge
  71. if !win! equ h echo 你居然赢了,太让我惊讶了!&pause&goto end
  72. if !win! equ c echo 嘿嘿,不好意思我赢了!&pause&goto end
  73. if "!str!" equ "" echo 平局!&pause&goto end
  74. :2
  75. echo 等待电脑走棋
  76. call :ai
  77. for /l %%i in (1,1,15) do set/p r=^><nul&ping /n 0 127.1>nul
  78. set  slt3=!max!
  79. set str=!str:%slt3%=!
  80. set mmrl=!mmrl:%slt3%=!
  81. set mmlr=!mmlr:%slt3%=!
  82. cls
  83. set %slt3%=%cpu%
  84. set m%slt3%=c
  85. set n%slt3%=c
  86. echo   ┏━┳━┳━┓
  87. echo   ┃%a1%┃%b1%┃%c1%┃                     
  88. echo   ┣━╋━╋━┫
  89. echo   ┃%a2%┃%b2%┃%c2%┃                       
  90. echo   ┣━╋━╋━┫
  91. echo   ┃%a3%┃%b3%┃%c3%┃                       
  92. echo   ┗━┻━┻━┛
  93. call :judge
  94. if !win! equ h echo 你居然赢了,太让我惊讶了!&pause&goto end
  95. if !win! equ c echo 嘿嘿,不好意思我赢了!&pause&goto end
  96. if "!str!" equ "" echo 平局!&pause&goto end
  97. goto begin
  98. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  99. ::  :judge这一段是判断胜负的
  100. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  101. :judge
  102. for %%i in (a,b,c) do (
  103. for %%j in (1,2,3) do (
  104.   set m%%i=!m%%i!!m%%i%%j!
  105.   set m%%j=!m%%j!!m%%i%%j!
  106. )
  107. )
  108. set mlr=!mlr!!ma1!!mb2!!mc3!
  109. set mrl=!mrl!!ma3!!mb2!!mc1!
  110. for %%i in (a,b,c) do (
  111. if !m%%i! equ hhh set win=h
  112. if !m%%i! equ ccc set win=c
  113. )
  114. for /l %%j in (1,1,3) do (
  115. if !m%%j! equ hhh set win=h
  116. if !m%%j! equ ccc set win=c
  117. )
  118. if !mlr! equ hhh set win=h
  119. if !mrl! equ hhh set win=h
  120. if !mlr! equ ccc set win=c
  121. if !mrl! equ ccc set win=c
  122. for %%i in (a,b,c) do (
  123. for %%j in (1,2,3) do (
  124.   set m%%i%%j=
  125. )
  126. )
  127. goto :eof
  128. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  129. :: :ai这一段是电脑下棋的思路
  130. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  131. :ai
  132. set k=0
  133. for /l %%i in (0,2,16) do (
  134. set/a k+=1
  135. set t!k!=!str:~%%i,2!
  136. if not defined t!k! goto next
  137. )
  138. :next
  139. set/a k=!k!-1
  140. for /l %%i in (1,1,!k!) do (
  141. set score%%i=0
  142. )
  143. for /l %%j in (1,1,!k!) do (
  144. set left%%j=!t%%j:~0,1!
  145. set right%%j=!t%%j:~1,1!
  146.         set bb%%j=!left%%j!!right%%j!
  147. if !mlr! equ hh if !bb%%j! equ !mmlr! set score%%j=4
  148. if !mrl! equ hh if !bb%%j! equ !mmrl! set score%%j=4
  149. if !mlr! equ cc if !bb%%j! equ !mmlr! set score%%j=5
  150. if !mrl! equ cc if !bb%%j! equ !mmrl! set score%%j=5
  151. for %%n in (a b c) do (
  152.   if !left%%j! equ %%n (
  153.    if !left%%j! equ b if !right%%j! equ 2 set score%%j=3
  154.    if !m%%n! equ hh if !score%%j! lss 4 set score%%j=4
  155.    if !m%%n! equ cc set score%%j=5
  156.   )
  157. )
  158.         for %%m in (1 2 3) do (
  159.   if !right%%j! equ %%m (
  160.    if !m%%m! equ hh if !score%%j! lss 4 set score%%j=4
  161.    if !m%%m! equ cc set score%%j=5
  162.   )
  163.         )
  164. )
  165. set max=!t1!
  166. set/a tempk=!k!+1
  167. for /l %%i in (1,1,!tempk!) do (
  168. set qq=%%i+1
  169. for /l %%j in (!qq!,1,!k!) do (
  170.   if !score%%i! equ 5 set max=!t%%j!&goto 3
  171.   if !score%%i! lss !score%%j! set max=!t%%j!
  172. )
  173. )
  174. :3
  175. goto :eof
  176. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  177. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  178. :end
  179. cls
  180. echo 重玩吗?(是/y,否/n)
  181. set /p sss=
  182. if !sss! equ y goto start
  183. if !sss! equ Y goto start
复制代码
1

评分人数

提个建议:

在正式下棋阶段,仍然把数字显示出来,这样,就给人提供了很多方便!!

TOP

真牛啊,能编出这样的游戏

TOP

要是我先走棋,保证局局平

TOP

返回列表