21
21

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

.batで迷宮入り

Last updated at Posted at 2015-03-03

 ネットワーク関連、ファイル管理関連その他で活躍するbatファイル先生で、少し遊んでみようと思います。

 迷宮入りなどと言っておきながら、中身はただの迷路です。

 正方形の迷路で、だんだん大きくなっていきます(77~4747)。操作はWASDのみ。マップ全部が表示されるわけではなく常に7*7の範囲しか表示しないため、だんだん気が狂いそうになります。
 まだまだ発展の余地のあるプログラムですが、バッチファイルでこんな酔狂をやってみるのも結構楽しいです。皆さんもぜひ!(現在は麻雀AI作りで四苦八苦。無理。)

迷路.bat
@echo off
setlocal enabledelayedexpansion
title 迷路
:top
set lv=0
cls
echo 迷路
echo.
echo  1.Start
echo  0.Exit
choice /c 10 /n
if %errorlevel% == 2 exit

:start
if %lv% == 10 goto clear
set /a lv+=1
set /a num=lv*4+7
set /a startx=2,starty=2,goalx=num-1,goaly=num-1
set nowx=2
set nowy=2
mode con:cols=20 lines=12
set loop1=0

:setfield1
cls 
echo 構築中(%loop1%/%num%)
if %loop1% == %num% set loop1=0&goto edit1
set /a loop1+=1
set loop2=0

:setfield2
set /a loop2+=1
set cell[%loop1%][%loop2%]=■
set /a loop1judge=loop1%%2
set /a loop2judge=loop2%%2
if %loop2% geq 2 if %loop2% lss %num% if %loop1judge% == 0 set cell[%loop1%][%loop2%]= 
if %loop1% geq 2 if %loop1% lss %num% if %loop2judge% == 0 set cell[%loop1%][%loop2%]= 
if %loop2% == %num% goto setfield1
goto setfield2

:edit1
set /a loop1+=1
set /a x=loop1*2+1
if %x% == %num% goto echo1
set loop2=0
:edit2
set /a loop2+=1
set /a y=loop2*2+1
if %y% == %num% goto edit1
set /a vector=%random%*4/32767+1
if %vector% == 4 if %x% geq 5 set /a vector=%random%*3/32767+1
if %vector% == 1 set /a subjectx=x,subjecty=y-1
if %vector% == 2 set /a subjectx=x+1,subjecty=y
if %vector% == 3 set /a subjectx=x,subjecty=y+1
if %vector% == 4 set /a subjectx=x-1,subjecty=y
set cell[%subjectx%][%subjecty%]=■
goto edit2

:echo1
set cell[%startx%][%starty%]=S
set cell[%goalx%][%goaly%]=G
set nowcell=cell[%nowx%][%nowy%]
set /a echocellx=nowx-3
set /a echocelly=nowy-3
set /a echolimit=num-6
if %echocellx% leq 0 set echocellx=1
if %echocelly% leq 0 set echocelly=1
if %echocellx% gtr %echolimit%  set echocellx=%echolimit%
if %echocelly% gtr %echolimit%  set echocelly=%echolimit%
set /a loop1=echocellx-1
set /a echomaxx=echocellx+6
set /a echomaxy=echocelly+6

set %nowcell%=○

:echo2
set /a loop1+=1
set cell%loop1%=
for /l %%i in (%echocelly%,1,%echomaxy%) do set cell%loop1%=!cell%loop1%!!cell[%loop1%][%%i]!
set cell%loop1%=|!cell%loop1%!|
if %echomaxx% == %loop1% goto echo3
goto echo2

:echo3
cls
echo  Lv:%lv%(%num%*%num%)
echo  ―――――――
for /l %%i in (%echocellx%,1,%echomaxx%) do echo !cell%%i!
echo  ―――――――
choice /c wdsa /n >nul
set action=%errorlevel%
if %action% == 1 set /a movex=nowx-1,movey=nowy
if %action% == 2 set /a movex=nowx,movey=nowy+1
if %action% == 3 set /a movex=nowx+1,movey=nowy
if %action% == 4 set /a movex=nowx,movey=nowy-1
if !cell[%movex%][%movey%]! == ■ goto echo3
if %action% == 1 set /a movex-=1
if %action% == 2 set /a movey+=1
if %action% == 3 set /a movex+=1
if %action% == 4 set /a movey-=1
set %nowcell%= 
set nowx=%movex%
set nowy=%movey%
if [%nowx%][%nowy%] == [%goalx%][%goaly%] goto goal
goto echo1

:goal
cls
echo goal^!^!
timeout /t 1 /nobreak >nul
echo.
echo go to next stage!
pause >nul
goto start

:clear
cls
echo clear^!^!
echo.
echo お疲れ様でした!
pause >nul
goto top

以上です。不具合・感想などありましたら、是非コメントにて。

21
21
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
21
21

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?