I have most of the code done but there are some errors in it

May 25, 2012 at 07:57:34
Specs: Windows 7
Making a chess batch file

Here is the code:

@echo off
title Chess
setlocal enabledelayedexpansion
for /l %%A IN (1,1,64) Do (set d%%A=--)
For /l %%B IN (9,1,16) Do (set d%%B=BP)
For /l %%C IN (49,1,56) Do (set d%%C=WP)
set d1=BR
set d8=BR
set d2=BN
set d7=BN
set d3=BB
set d6=BB
set d4=BK
set d5=BQ
set d57=WR
set d64=WR
set d58=WN
set d63=WN
set d59=WB
set d62=WB
set d60=WK
set d61=WQ
set Turn=White
set OppTurn=Black
:Board
cls
echo x 1 2 3 4 5 6 7 8
echo y _______________________
echo 1 ^|%d1%^|%d2%^|%d3%^|%d4%^|%d5%^|%d6%^|%d7%^|%d8%^|
echo 2 ^|%d9%^|%d10%^|%d11%^|%d12%^|%d13%^|%d14%^|%d15%^|%d16%^|
echo 3 ^|%d17%^|%d18%^|%d19%^|%d20%^|%d21%^|%d22%^|%d23%^|%d24%^|
echo 4 ^|%d25%^|%d26%^|%d27%^|%d28%^|%d29%^|%d30%^|%d31%^|%d32%^|
echo 5 ^|%d33%^|%d34%^|%d35%^|%d36%^|%d37%^|%d38%^|%d39%^|%d40%^|
echo 6 ^|%d41%^|%d42%^|%d43%^|%d44%^|%d45%^|%d46%^|%d47%^|%d48%^|
echo 7 ^|%d49%^|%d50%^|%d51%^|%d52%^|%d53%^|%d54%^|%d55%^|%d56%^|
echo 8 ^|%d57%^|%d58%^|%d59%^|%d60%^|%d61%^|%d62%^|%d63%^|%d64%^|
echo _______________________
echo.
echo %Turn%'s Turn:
set /p xy=Location(X,Y):
set /p dest=Destination(X,Y):
for /f "tokens=1,2 delims=," %%D IN ("%xy%") Do (
set X=%%D
set Y=%%E
)
if %X%==1 (set sub=7)
if %X%==2 (set sub=6)
if %X%==3 (set sub=5)
if %X%==4 (set sub=4)
if %X%==5 (set sub=3)
if %X%==6 (set sub=2)
if %X%==7 (set sub=1)
if %x%==8 (set sub=0)
set /a POS=%Y% * 8 - %sub%
for /f "tokens=1,2 delims=," %%F IN ("%dest%") Do (
set DX=%%F
set DY=%%G
)
if %DX%==1 (set sub=7)
if %DX%==2 (set sub=6)
if %DX%==3 (set sub=5)
if %DX%==4 (set sub=4)
if %DX%==5 (set sub=3)
if %DX%==6 (set sub=2)
if %DX%==7 (set sub=1)
if %Dx%==8 (set sub=0)
set /a destination=%DY% * 8 - %sub%
if !d%POS%!==BR goto Rook
if !d%POS%!==WR goto Rook
if !d%POS%!==BN goto Knight
if !d%POS%!==WN goto Knight
if !d%POS%!==BB goto Bishop
if !d%POS%!==WB goto Bishop
if !d%POS%!==BK goto King
if !d%POS%!==WK goto King
if !d%POS%!==BQ goto Queen
if !d%POS%!==WQ goto Queen
if !d%POS%!==BP goto Pawn
if !d%POS%!==WP goto Pawn
if !d%POS%!==-- (
echo THIS SQUARE IS BLANK
pause
goto Board
)
echo An Error Has Occured:
echo.
echo This Square Contains An Unknown Character
pause
exit
:Pawn
set /a epos=%POS% + 16
set /a epos2=%POS% + 8
if %Turn%==Black (
if %Y%==2 (
if !d%epos2%!==-- (
if !d%epos%!==-- (
if %destination%==%epos% goto Checked
)
)
)
)
set /a epos=%POS% - 16
set /a epos2=%POS% - 8
if %Turn%==White (
if %Y%==7 (
if !d%epos2%!==-- (
if !d%epos%!==-- (
if %destination%==%epos% goto Checked
)
)
)
)
set /a epos=%POS% + 7
set /a epos2=%POS% + 9
set /a epos3=%POS% + 1
if %Turn%==Black (
if not !d%epos%!==-- (
if %destination%==%epos% goto Checked
)
if not !d%epos2%!==-- (
if %destination%==%epos2% goto Checked
)
if not !d%epos3%!==-- (
if %destination%==%epos3% goto Checked
)
)
set /a epos=%POS% - 7
set /a epos2=%POS% - 9
set /a epos3=%POS% - 1
if %Turn%==White (
if not !d%epos%!==-- (
if %destination%==%epos% goto Checked
)
if not !d%epos2%!==-- (
if %destination%==%epos2% goto Checked
)
if not !d%epos3%!==-- (
if %destination%==%epos3% goto Checked
)
)
goto ERROR
:Rook

if %X%==%DX% (
if %Y% GTR %DY% (
set Count=-8
set /a epos=%POS% - 8
)else(
set /a epos=%POS% + 8
set Count=8
)
)
If %Y%==%DY% (
if %X% GTR %DX% (
set Count=-1
set /a epos=%POS% - 1
)else(
set /a epos=%POS% + 1
set Count=1
)
)
If not %Y%==%DY% (
if Not %X%==%DX% (
goto ERROR
)
)
for /l %%I IN (%epos%,%Count%,%destination%) Do (
if %destination%==%%I goto Checked
if not !d%%I!==-- goto ERROR
goto Checked

:Knight

Set /a epos=%POS% + 17
set /a epos2=%POS% + 15
Set /a epos3=%POS% + 10
set /a epos4=%POS% - 6
set /a epos5=%POS% - 15
set /a epos6=%POS% - 17
set /a epos7=%POS% + 6
set /a epos8=%POS% - 10

if %destination%==%epos% goto Checked
if %destination%==%epos2% goto Checked
if %destination%==%epos3% goto Checked
if %destination%==%epos4% goto Checked
if %destination%==%epos5% goto Checked
if %destination%==%epos6% goto Checked
if %destination%==%epos7% goto Checked
if %destination%==%epos8% goto Checked
goto ERROR

:Bishop
@echo on
if %X%==%DX% goto ERROR
if %Y%==%DY% goto ERROR
::~ I'm Not Sure What To Put Here::-----------------------------------------------------------------------------------------------------------------------
goto Checked
:King

Set /a epos=%POS% - 8
Set /a epos2=%POS% - 7
Set /a epos3=%POS% + 1
Set /a epos4=%POS% + 9
Set /a epos5=%POS% + 8
Set /a epos6=%POS% + 7
Set /a epos7=%POS% - 1
Set /a epos8=%POS% - 9
if %destination%==%epos% goto Checked
if %destination%==%epos2% goto Checked
if %destination%==%epos3% goto Checked
if %destination%==%epos4% goto Checked
if %destination%==%epos5% goto Checked
if %destination%==%epos6% goto Checked
if %destination%==%epos7% goto Checked
if %destination%==%epos8% goto Checked
goto ERROR

:Queen

if %Y%==%DY% goto Rook
if %X%==%DX% goto Rook
goto Bishop
:Checked
IF %Turn%==White (
If !d%destination%!==WP goto ERROR
If !d%destination%!==WR goto ERROR
If !d%destination%!==WN goto ERROR
If !d%destination%!==WB goto ERROR
If !d%destination%!==WK goto ERROR
If !d%destination%!==WQ goto ERROR
If !d%destination%!==BK goto WIN
)
IF %Turn%==Black (
If !d%destination%!==BP goto ERROR
If !d%destination%!==BR goto ERROR
If !d%destination%!==BN goto ERROR
If !d%destination%!==BB goto ERROR
If !d%destination%!==BK goto ERROR
If !d%destination%!==BQ goto ERROR
If !d%destination%!==WK goto WIN
)
set d%destination%=!d%POS%!
if %Turn%==White (
if %DY%==1 (
if !d%POS%!==WP (
set d%destination%=WQ
)
)
)
if %Turn%==Black (
if %DY%==8 (
if !d%POS%!==BP (
set d%destination%=BQ
)
)
)
set d%POS%=--
if %Turn%==White (
set Turn=Black
goto Board
)
if %Turn%==Black (
set Turn=White
goto Board
)
:ERROR
echo Error
pause
goto Board


See More: I have most of the code done but there are some errors in it

Report •


#1
May 25, 2012 at 08:30:09
The Bishop doesn't work very good and there a few errors in some of the other ones. Please help me fix these errors

Report •

#2
May 25, 2012 at 11:25:19
I have been taking a look at it, its a long code, I have been having issues with the pawns as well.

mike


Report •

#3
May 28, 2012 at 06:17:58
Try testing it

Report •

Related Solutions


Ask Question