Poddy Chess
#1
Hi all,

Having been inspired by the various postings about QBASIC chess in this forum, I will be attempting to write a simple program in QBasic as well. So far only the chessboard and chess pieces are displayed. Will be working on the Chess AI soon to get the program functional. Will be posting updates to the code as I go along. Suggestions and feedback very welcome.

Cheers,
Adrian


(MODIFIED BY ADMINISTRATOR - PLACED IN A CODE BOX FOR EASIER ACCESS)

Code:
DEFINT A-Z
DIM BC(8, 8) ' BOARD SQUARE COLOR
DIM SHARED BOARD(8, 8)
SCREEN 12
COLOR 0, 1
CLS
COLOR 7
LOCATE 2, 56
PRINT "Poddy Chess 1.0"
'DEFINE PIECES FOR DRAWING
ROOK$ = "R26U5H2L5U7E3R4U10L6D3L4U3L6D3L4U3L6D10R4F3D7L5G2D5"
KNIGHT$ = "R26U5H2U4E2U9H6L9G10D4F2R4E3R4G8L4G2D5"
BISHOP$ = "R26U5H2L8E6U9H2G8H2E8H2L6G6D9F6L8G2D5"
QUEEN$ = "R26U5H2L6E9U11G4H6G4H4G6H4D11F9L6G2D5"
KING$ = "R26U5H2L5E7U6H4L5G3U5R2U2L2U2L2D2L2D2R2D5H3L5G4D6F7L5G2D5"
PAWN$ = "R26U5H2L6U7E3U6H3L10G3D6F3D7L6G2D5"
'ASSIGN CHESSBOARD SQUARE COLORS AND DRAW CHESSBOARD
DATA 0,1,0,1,0,1,0,1
DATA 1,0,1,0,1,0,1,0
DATA 0,1,0,1,0,1,0,1
DATA 1,0,1,0,1,0,1,0
DATA 0,1,0,1,0,1,0,1
DATA 1,0,1,0,1,0,1,0
DATA 0,1,0,1,0,1,0,1
DATA 1,0,1,0,1,0,1,0
FOR X = 1 TO 8
    FOR Y = 1 TO 8
        READ BC(X, Y)
        IF BC(X, Y) = 0 THEN C = 7 ELSE C = 2
        LINE (X * 40, Y * 40)-(X * 40 + 40, Y * 40 + 40), C, BF
    NEXT Y
NEXT X
'ASSIGN CHESS PIECE VALUES AND DRAW PIECES
DATA -500,-290,-300,-900,-5000,-300,-290,-500
DATA -100,-100,-100,-100,-100,-100,-100,-100
DATA 0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0
DATA 100,100,100,100,100,100,100,100
DATA 500,290,300,900,5000,300,290,500
FOR Y = 8 TO 1 STEP -1 'ROW
    FOR X = 1 TO 8 'COLUMN
        READ Z
        BOARD(X, Y) = Z
        IF Z = 0 THEN 10 'SKIP EMPTY SQUARES
        PRESET (X * 40 + 6, (9 - Y) * 40 + 34)
        IF Z < 0 THEN DRAW "C0" ELSE DRAW "C15"
        ZZ = ABS(Z)
        SELECT CASE ZZ
            CASE 500
                PIECE$ = ROOK$
            CASE 290
                PIECE$ = KNIGHT$
            CASE 300
                PIECE$ = BISHOP$
            CASE 900
                PIECE$ = QUEEN$
            CASE 5000
                PIECE$ = KING$
            CASE 100
                PIECE$ = PAWN$
        END SELECT
        DRAW PIECE$ 'DRAW OUTLINE
        DRAW "BE2" 'MOVE PEN INSIDE
        IF Z < 0 THEN DRAW "P0,0" ELSE DRAW "P15,15" 'FILL WITH COLOR
        IF Z > 0 THEN DRAW "BG2": DRAW "C0": DRAW PIECE$ 'DRAW BORDER FOR WHITE PIECES
    10 NEXT X
NEXT Y
'display commands
COLOR 7
LOCATE 4, 52: PRINT "(N)ew game"
LOCATE 5, 52: PRINT "(F)lip Board"
LOCATE 6, 52: PRINT "(L)oad Position"
LOCATE 7, 52: PRINT "(Q)uit program"
MAIN:
COLOR 7
LOCATE 26, 6: INPUT "Your Move or Command "; COMD$
C$ = UCASE$(COMD$)
SLEEP
END

SCREENSHOT ADDED BY ADIMINISTRATOR

I like to program in BASIC
With code that is simple and slick
I learnt it in school
And it is still cool
So it is my number one pick
Reply
#2
Adrian,

Now that is a cool start for a chess game. I think Anthony will like it as well.

One of my most favorite graphic statement in QBASIC is "DRAW". It is the most un-utilized statement today in my opinion. The DRAW statement has a great history behind it, and it is a powerful feature. I even thought about revising it at on time in QB64 to do more powerful things, but that will be a long while before I get back into helping on making QB64 better.

I have however used the concept behind the DRAW statement in many applications I created in the past, as it is a great compression technique. I even had plans on creating a JavaScript framework using the fundamentals of the DRAW statement, to help make drawing on the HTML5 Canvas much easier and faster. The framework would interpret a string similar to those used in the DRAW statement, and translate each part into an JavaScript-Canvas drawing statement. I do have plans on creating this framework sometime soon, because I would like to use it on my new home page I am working for my main site (http://www.TheJoyfulProgrammer.com).


Walter Whitman
The Joyful Programmer
a.k.a: Waltersmind
Please visit my website at: [url]http://www.TheJoyfulProgrammer.com[/url]
Please subscribe to my YouTube Channel at: [url]https://www.youtube.com/c/thejoyfulprogrammer[/url]
Please visit me at FaceBook: [url]https://www.facebook.com/thejoyfulprogrammer[/url]
Please follow me at Twitter: [url]https://twitter.com/TheJoyfulProg[/url]
Please follow me at Google+: [url]https://plus.google.com/+Thejoyfulprogrammer/posts[/url]
Please Visit me on Pinterest: [url]https://www.pinterest.com/waltersmind/[/url]
Please Visit me on LinkedIn: [url]https://www.linkedin.com/pub/walter-whitman/18/8b4/832[/url]
Dedicated to empowering computer programming hobbyists, tinkerers, amateurs, and enthusiasts.
profile for Walter Whitman at Stack Overflow, Q&A for professional and enthusiast programmers


Reply
#3
Walter,

Thanks for editing my post and putting my code in the code box.
Looking forward to see your new home page.

Adrian
I like to program in BASIC
With code that is simple and slick
I learnt it in school
And it is still cool
So it is my number one pick
Reply
#4
Adrian,

You are very welcome. My goal here is not to change what people post, but to help promote a members project either by placing code in a code box, adding images, or even YouTube videos if any are available. I am working on other means to promote the projects shared by the members of this forum, but it will be awhile before those will become available.

I am working hard on building my home page, and what I first thought was going to be something that I could quickly put up, has become a large project in its self. Every time I turn around, I am thinking of new things to add to it (function wise), so it will take me a lot longer than I originally had thought to go live with it.

Though I am working on the home page in the background, I am very happy to share what I have so far with everyone else. Not only do like to hear what people have to say about it, but I also like to get input on the good and bad things about it. This helps me make better design decisions.

Before I share the link to the beta version of my home page (for http://www.TheJoyfulProgrammer.com not this forum), I do want to explain a few things before I do. First, The home page only supports IE ver 9+, the latest versions of FireFox, Google Chrome, and Opera, and does not support mobile phones, earlier versions of the mention browsers, or any other browser out there, since there are too many to try to test, and the four I mentioned are the most popular ones out there.

There isn't very much on the home page, and some of what you see will change, but there is a lot of coolness to it right now (at least for me). I do know that the social media stuff at the top of the page will be moved to their own sub page that can be seen when you click on the social media buttons at the bottom of the browser page (The menu is in a fixed position). When you click on the buttons at the bottom, it will pop up a smaller page that will contain all the social media stuff in those. Mouse over the buttons to see some interesting message bubbles. I really love how the bubbles zoom in to size when you mouse over the buttons.

One final note, all the images at the time of this writing, except for the social media icons and what ever images are used in the Google Ads, everything else is either created with CSS or created on the fly with the HTML5 Canvas element.

You can see the beta page (page in progress) here: http://www.thejoyfulprogrammer.com/____main_page_ver1/

I am currently working on a custom scrollbar framework that I am building from scratch that I will sharing with the rest of the world when I get it done. The greatest cool feature about my scrollbar framework is that a developer would not need to write one bit of JavaScript code to get it to work, unless they want to draw the different parts using JavaScript. All the developer has to do is add a class name to the element they want to use my custom scrollbar system on, and my system does the rest. No initializing JavaScript code like you see in other frameworks, nor does the developer need to have any JavaScript knowledge to use my system. So, if you have a <DIV> element that you want to add a custom scrollbar to, all you do is this: "<DIV class='Any_Other_Class_Here tjp_scrollbar'>Div Content Here.</DIV>". Since you can have multiple classes for an element, all you have to add is the class name "tjp_scrollbar", and my system will add its default scrollbar to the element. Once I have it done, I will create a special page just for it to not only share the framework, but also show how to use it. I am very excited about it.

Let me know what you think.


Walter Whitman
The Joyful Programmer
a.k.a: Waltersmind
Please visit my website at: [url]http://www.TheJoyfulProgrammer.com[/url]
Please subscribe to my YouTube Channel at: [url]https://www.youtube.com/c/thejoyfulprogrammer[/url]
Please visit me at FaceBook: [url]https://www.facebook.com/thejoyfulprogrammer[/url]
Please follow me at Twitter: [url]https://twitter.com/TheJoyfulProg[/url]
Please follow me at Google+: [url]https://plus.google.com/+Thejoyfulprogrammer/posts[/url]
Please Visit me on Pinterest: [url]https://www.pinterest.com/waltersmind/[/url]
Please Visit me on LinkedIn: [url]https://www.linkedin.com/pub/walter-whitman/18/8b4/832[/url]
Dedicated to empowering computer programming hobbyists, tinkerers, amateurs, and enthusiasts.
profile for Walter Whitman at Stack Overflow, Q&A for professional and enthusiast programmers


Reply
#5
Nice looking Chess Program Start Adrian Smile

I am looking forward to you getting it Actually Running even if it's just the Basic Moves for the Pieces without the Chess Rules Etc. will be good...Please make as Many Comments as you can on how the Program Runs!

And for later the Fide Chess Rules
https://www.fide.com/component/handbook/...ew=article


Anthony.
Reply
#6
Just a small bit of progress..... White can input moves which are checked for legality before they are played. A simple generic opening is coded for Black, which needs checking for threats etc.

Code:
DEFINT A-Z
DIM BC(8, 8) ' BOARD SQUARE COLOR
DIM SHARED BOARD(8, 8)

SCREEN 12
COLOR 0, 1
CLS
COLOR 7
PRINT: PRINT "       A    B    C    D    E    F    G    H              Poddy Chess 1.0"
LOCATE 4, 3: PRINT "8": LOCATE 7, 3: PRINT "7": LOCATE 9, 3: PRINT "6": LOCATE 12, 3: PRINT "5"
LOCATE 14, 3: PRINT "4": LOCATE 17, 3: PRINT "3": LOCATE 19, 3: PRINT "2": LOCATE 22, 3: PRINT "1"

'DEFINE PIECES FOR DRAWING
ROOK$ = "R26U5H2L5U7E3R4U10L6D3L4U3L6D3L4U3L6D10R4F3D7L5G2D5"
KNIGHT$ = "R26U5H2U4E2U9H6L9G10D4F2R4E3R4G8L4G2D5"
BISHOP$ = "R26U5H2L8E6U9H2G8H2E8H2L6G6D9F6L8G2D5"
QUEEN$ = "R26U5H2L6E9U11G4H6G4H4G6H4D11F9L6G2D5"
KING$ = "R26U5H2L5E7U6H4L5G3U5R2U2L2U2L2D2L2D2R2D5H3L5G4D6F7L5G2D5"
PAWN$ = "R26U5H2L6U7E3U6H3L10G3D6F3D7L6G2D5"

'ASSIGN CHESSBOARD SQUARE COLORS AND DRAW CHESSBOARD
DATA 0,1,0,1,0,1,0,1
DATA 1,0,1,0,1,0,1,0
DATA 0,1,0,1,0,1,0,1
DATA 1,0,1,0,1,0,1,0
DATA 0,1,0,1,0,1,0,1
DATA 1,0,1,0,1,0,1,0
DATA 0,1,0,1,0,1,0,1
DATA 1,0,1,0,1,0,1,0

FOR X = 1 TO 8
    FOR Y = 1 TO 8
        READ BC(X, Y)
        IF BC(X, Y) = 0 THEN C = 7 ELSE C = 2
        LINE (X * 40, Y * 40)-(X * 40 + 40, Y * 40 + 40), C, BF
    NEXT Y
NEXT X

'ASSIGN CHESS PIECE VALUES AND DRAW PIECES
DATA -500,-290,-300,-900,-5000,-300,-290,-500
DATA -100,-100,-100,-100,-100,-100,-100,-100
DATA 0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0
DATA 100,100,100,100,100,100,100,100
DATA 500,290,300,900,5000,300,290,500

FOR Y = 8 TO 1 STEP -1 'ROW
    FOR X = 1 TO 8 'COLUMN
        READ Z
        IF Z = 0 THEN 10 'SKIP EMPTY SQUARES
        BOARD(X, Y) = Z
        GOSUB DRAWPIECE
    10 NEXT X
NEXT Y

MOVENO = 1

'display commands
COLOR 7
LOCATE 4, 52: PRINT "Instructions:"
LOCATE 5, 52: PRINT "Computer plays Black"
LOCATE 6, 52: PRINT "Input moves in E2E4 format"
LOCATE 7, 52: PRINT "Castling in E1G1 format"
LOCATE 8, 52: PRINT "Type 'QUIT' to exit program"

MAIN:
LOCATE 26, 6: PRINT "White's move "
20 COLOR 7: LOCATE 26, 19: PRINT "            ": LOCATE 26, 19: INPUT COMD$ 'WHITE TO MOVE
C$ = UCASE$(COMD$)
IF C$ = "QUIT" THEN END
IF LEN(C$) = 4 THEN GOSUB CHECKLEGAL ELSE GOTO 20
'MOVE PIECE
BOARD(X2, Y2) = BOARD(X1, Y1)
BOARD(X1, Y1) = 0
X = X2: Y = Y2: GOSUB DRAWPIECE
X = X1: Y = 9 - Y1: GOSUB DRAWEMPTYSQUARE

'PLAY BLACK'S MOVE
GOSUB GENERATEMOVE
COLOR 7: LOCATE 27, 19: PRINT "            ": LOCATE 27, 6: PRINT "Black's move "; D$
DD$ = UCASE$(D$)
25 'CONVERT TO NUMERICAL COORDINATES
X1 = ASC(MID$(DD$, 1, 1)) - 64
Y1 = VAL(MID$(DD$, 2, 1))
X2 = ASC(MID$(DD$, 3, 1)) - 64
Y2 = VAL(MID$(DD$, 4, 1))
'MOVE PIECE
BOARD(X2, Y2) = BOARD(X1, Y1)
BOARD(X1, Y1) = 0
X = X2: Y = Y2: GOSUB DRAWPIECE
X = X1: Y = 9 - Y1: GOSUB DRAWEMPTYSQUARE
IF DD$ = "E8G8" THEN DD$ = "H8F8": GOTO 25 'KING'S SIDE CASTLING
IF DD$ = "E8C8" THEN DD$ = "A8D8": GOTO 25 'QUEEN'S SIDE CASTLING

MOVENO = MOVENO + 1
GOTO 20 'BACK TO WHITE'S MOVE

SLEEP
END

CHECKLEGAL: 'CHECK WHETHER WHITE'S MOVE IS LEGAL
X1 = ASC(MID$(C$, 1, 1)) - 64 'CONVERT TO NUMERICAL COORDINATES
Y1 = VAL(MID$(C$, 2, 1))
X2 = ASC(MID$(C$, 3, 1)) - 64
Y2 = VAL(MID$(C$, 4, 1))
IF X1 < 1 OR X1 > 8 THEN 20 'OUT OF BOUNDS
IF Y1 < 1 OR Y1 > 8 THEN 20
IF X2 < 1 OR X2 > 8 THEN 20
IF Y2 < 1 OR Y2 > 8 THEN 20
IF BOARD(X1, Y1) < 1 THEN 20 'FROM SQUARE IS EMPTY /BLACK PIECE
IF X1 = X2 AND Y1 = Y2 THEN 20 'SAME SQUARE
IF SGN(BOARD(X1, Y1)) = SGN(BOARD(X2, Y2)) THEN 20 'CAPTURING SAME COLOR PIECE
SELECT CASE BOARD(X1, Y1)
    CASE 500 'ROOK
        Legal = 0
        IF Y1 = Y2 THEN 'check rank
            Legal = 1
            FOR I = X1 TO X2 STEP SGN(X2 - X1)
                IF I <> X1 AND I <> X2 AND BOARD(I, Y2) <> 0 THEN GOTO 20
            NEXT I
        END IF
        IF X1 = X2 THEN 'check file
            Legal = 1
            FOR J = Y1 TO Y2 STEP SGN(Y2 - Y1)
                IF J <> Y1 AND J <> Y2 AND BOARD(X1, J) <> 0 THEN GOTO 20
            NEXT J
        END IF
        IF Legal = 0 THEN GOTO 20
    CASE 290 'KNIGHT
        Legal = 0
        FOR I = -1 TO 1 STEP 2
            FOR J = -2 TO 2 STEP 4
                IF X1 + I = X2 AND Y1 + J = Y2 THEN Legal = 1
            NEXT J
        NEXT I
        FOR I = -2 TO 2 STEP 4
            FOR J = -1 TO 1 STEP 2
                IF X1 + I = X2 AND Y1 + J = Y2 THEN Legal = 1
            NEXT J
        NEXT I
        IF Legal = 0 THEN GOTO 20
    CASE 300 'BISHOP
        IF ABS(X1 - X2) <> ABS(Y1 - Y2) THEN 20 'NOT ON SAME DIAGONAL
        Legal = 1
        FOR I = X1 TO X2 STEP SGN(X2 - X1)
            FOR J = Y1 TO Y2 STEP SGN(Y2 - Y1)
                IF ABS(I - X1) = ABS(J - Y1) AND I <> X1 AND I <> X2 AND BOARD(I, J) <> 0 THEN GOTO 20
            NEXT J
        NEXT I
        IF Legal = 0 THEN GOTO 20
    CASE 900 'QUEEN
        IF ABS(X1 - X2) = ABS(Y1 - Y2) THEN 'CHECK BISHOP MOVES
            Legal = 1
            FOR I = X1 TO X2 STEP SGN(X2 - X1)
                FOR J = Y1 TO Y2 STEP SGN(Y2 - Y1)
                    IF ABS(I - X1) = ABS(J - Y1) AND I <> X1 AND I <> X2 AND BOARD(I, J) <> 0 THEN GOTO 20
                NEXT J
            NEXT I
        END IF
        IF X1 = X2 OR Y1 = Y2 THEN 'CHECK ROOK MOVES
            Legal = 0
            IF Y1 = Y2 THEN 'check rank
                Legal = 1
                FOR I = X1 TO X2 STEP SGN(X2 - X1)
                    IF I <> X1 AND I <> X2 AND BOARD(I, Y2) <> 0 THEN GOTO 20
                NEXT I
            END IF
            IF X1 = X2 THEN 'check file
                Legal = 1
                FOR J = Y1 TO Y2 STEP SGN(Y2 - Y1)
                    IF J <> Y1 AND J <> Y2 AND BOARD(X1, J) <> 0 THEN GOTO 20
                NEXT J
            END IF
        END IF
        IF Legal = 0 THEN GOTO 20
    CASE 5000 'KING
        Legal = 0
        IF X1 + 1 = X2 AND Y1 + 1 = Y2 THEN Legal = 1
        IF X1 + 1 = X2 AND Y1 = Y2 THEN Legal = 1
        IF X1 + 1 = X2 AND Y1 - 1 = Y2 THEN Legal = 1
        IF X1 = X2 AND Y1 - 1 = Y2 THEN Legal = 1
        IF X1 - 1 = X2 AND Y1 - 1 = Y2 THEN Legal = 1
        IF X1 - 1 = X2 AND Y1 = Y2 THEN Legal = 1
        IF X1 - 1 = X2 AND Y1 + 1 = Y2 THEN Legal = 1
        IF X1 = X2 AND Y1 + 1 = Y2 THEN Legal = 1
        IF X1 = 5 AND Y1 = 1 AND X2 = 7 AND Y2 = 1 AND BOARD(6, 1) = 0 AND BOARD(7, 1) = 0 AND BOARD(8, 1) = 500 THEN 'KING'S SIDE CASTLING
            Legal = 1
            BOARD(8, 1) = 0: BOARD(6, 1) = 500
            X = 8: Y = 8: GOSUB DRAWEMPTYSQUARE
            X = 6: Y = 1: GOSUB DRAWPIECE
        END IF
        IF X1 = 5 AND Y1 = 1 AND X2 = 3 AND Y2 = 1 AND BOARD(4, 1) = 0 AND BOARD(3, 1) = 0 AND BOARD(2, 1) = 0 AND BOARD(1, 1) = 500 THEN 'QUEEN'S SIDE CASTLING
            Legal = 1
            BOARD(1, 1) = 0: BOARD(4, 1) = 500
            X = 1: Y = 8: GOSUB DRAWEMPTYSQUARE
            X = 4: Y = 1: GOSUB DRAWPIECE
        END IF
        IF Legal = 0 THEN GOTO 20
        WKX = X2: WKY = Y2 'UPDATE WHITE KING COORDINATES
    CASE 100 'PAWN
        Legal = 0: EP = 0
        IF X1 = X2 AND Y1 = 2 AND Y2 = 4 AND BOARD(X1, 3) = 0 THEN Legal = 1
        IF X1 = X2 AND Y1 + 1 = Y2 THEN Legal = 1
        IF ABS(X1 - X2) = 1 AND Y2 - Y1 = 1 AND SGN(BOARD(X2, Y2)) < 0 THEN Legal = 1 'CAPTURES BLACK PIECE
        IF Y1 = 5 AND BOARD(X2, 5) = -100 AND ABS(X1 - X2) = 1 THEN BOARD(X2, 5) = 0: X = X2: Y = 4: GOSUB DRAWEMPTYSQUARE: Legal = 1 'EN PASSANT
        IF Legal = 1 AND Y2 = 8 THEN GOSUB PROMOTEPAWN
        IF Legal = 0 THEN GOTO 20
END SELECT
RETURN

PROMOTEPAWN:
INPUT "PROMOTE TO Q/R/B/N "; PR$
SELECT CASE UCASE$(PR$)
    CASE "R"
        BOARD(X1, Y1) = 500
    CASE "B"
        BOARD(X1, Y1) = 300
    CASE "N"
        BOARD(X1, Y1) = 290
    CASE ELSE 'PROMOTE TO QUEEN
        BOARD(X1, Y1) = 900
END SELECT
RETURN

DRAWPIECE:
Z = BOARD(X, Y)
PRESET (X * 40 + 6, (9 - Y) * 40 + 34)
IF BOARD(X, Y) < 0 THEN DRAW "C0" ELSE DRAW "C15"
ZZ = ABS(BOARD(X, Y))
SELECT CASE ZZ
    CASE 500
        PIECE$ = ROOK$
    CASE 290
        PIECE$ = KNIGHT$
    CASE 300
        PIECE$ = BISHOP$
    CASE 900
        PIECE$ = QUEEN$
    CASE 5000
        PIECE$ = KING$
    CASE 100
        PIECE$ = PAWN$
END SELECT
DRAW PIECE$ 'DRAW OUTLINE
DRAW "BE2" 'MOVE PEN INSIDE
IF Z < 0 THEN DRAW "P0,0" ELSE DRAW "P15,15" 'FILL WITH COLOR
IF Z > 0 THEN DRAW "BG2": DRAW "C0": DRAW PIECE$ 'DRAW BORDER FOR WHITE PIECES
RETURN

DRAWEMPTYSQUARE:
IF BC(X, Y) = 0 THEN C = 7 ELSE C = 2
LINE (X * 40, Y * 40)-(X * 40 + 40, Y * 40 + 40), C, BF
RETURN

ENPRISE: 'CHECK WHETHER BLACK PIECE IS EN PRISE (ATTACKED) AND/OR PROTECTED?
'PCX,PCY = PIECE COORDINATES TO BE CHECKED FOR EN PRISE
'CHECK FOR ATTACK BY KNIGHT
ATTACKED = 0
PROTECTED = 0
FOR I = 1 TO 8 'LOCATE KNIGHTS
    FOR J = 1 TO 8
        IF BOARD(I, J) = 290 THEN 'WHITE KNIGHT FOUND, CHECK FOR ATTACK
            IF ABS(PCX - I) = 2 AND ABS(PCY - J) = 1 THEN ATTACKED = 1: ASX = I: ASY = J
            IF ABS(PCX - I) = 1 AND ABS(PCY - J) = 2 THEN ATTACKED = 1: ASX = I: ASY = J
        END IF
        IF BOARD(I, J) = -290 THEN 'BLACK KNIGHT FOUND, CHECK FOR PROTECTION
            IF ABS(PCX - I) = 2 AND ABS(PCY - J) = 1 THEN PROTECTED = 1
            IF ABS(PCX - I) = 1 AND ABS(PCY - J) = 2 THEN PROTECTED = 1
        END IF
    NEXT J
NEXT I
'CHECK FOR ATTACK AND PROTECTION BY OTHER PIECES
'CHECK FILES
FOR J = PCY TO 8
    Z = BOARD(PCX, J)
    IF Z <> 0 AND Z <> -5000 AND Z < 500 THEN EXIT FOR
    IF Z = 500 THEN ATTACKED = 1 ': PRINT "ATTACKED BY ROOK AT "; PCX, J
    IF Z = 900 THEN ATTACKED = 1 ': PRINT "ATTACKED BY QUEEN AT "; PCX, J
NEXT J
FOR J = PCY TO 1 STEP -1
    Z = BOARD(PCX, J)
    IF Z <> 0 AND Z <> -5000 AND Z < 500 THEN EXIT FOR
    IF Z = 500 THEN ATTACKED = 1 ': PRINT "ATTACKED BY ROOK AT "; PCX, J
    IF Z = 900 THEN ATTACKED = 1 ': PRINT "ATTACKED BY QUEEN AT "; PCX, J
NEXT J
FOR J = PCY TO 8
    Z = BOARD(PCX, J)
    IF Z <> 0 AND Z <> -5000 AND Z > -500 THEN EXIT FOR
    IF Z = -500 THEN PROTECTED = 1
    IF Z = -900 THEN PROTECTED = 1
NEXT J
FOR J = PCY TO 1 STEP -1
    Z = BOARD(PCX, J)
    IF Z <> 0 AND Z <> -5000 AND Z > -500 THEN EXIT FOR
    IF Z = -500 THEN PROTECTED = 1
    IF Z = -900 THEN PROTECTED = 1
NEXT J
'CHECK RANKS
FOR I = PCX TO 8
    Z = BOARD(I, PCY)
    IF Z <> 0 AND Z <> -5000 AND Z < 500 THEN EXIT FOR
    IF Z = 500 THEN ATTACKED = 1 ': PRINT "ATTACKED BY ROOK AT "; I, PCY
    IF Z = 900 THEN ATTACKED = 1 ': PRINT "ATTACKED BY QUEEN AT "; I, PCY
NEXT I
FOR I = PCX TO 1 STEP -1
    Z = BOARD(I, PCY)
    IF Z <> 0 AND Z <> -5000 AND Z < 500 THEN EXIT FOR
    IF Z = 500 THEN ATTACKED = 1 ': PRINT "ATTACKED BY ROOK AT "; I, PCY
    IF Z = 900 THEN ATTACKED = 1 ': PRINT "ATTACKED BY QUEEN AT "; I, PCY
NEXT I
FOR I = PCX TO 8
    Z = BOARD(I, PCY)
    IF Z <> 0 AND Z <> -5000 AND Z > -500 THEN EXIT FOR
    IF Z = -500 THEN PROTECTED = 1
    IF Z = -900 THEN PROTECTED = 1
NEXT I
FOR I = PCX TO 1 STEP -1
    Z = BOARD(I, PCY)
    IF Z <> 0 AND Z <> -5000 AND Z > -500 THEN EXIT FOR
    IF Z = -500 THEN PROTECTED = 1
    IF Z = -900 THEN PROTECTED = 1
NEXT I
'CHECK DIAGONALS
40 I = PCX: J = PCY
50 I = I + 1: J = J + 1
IF I > 8 OR J > 8 THEN 60
Z = BOARD(I, J)
IF Z = 0 THEN 50
IF Z < 300 OR Z = 500 OR Z = 5000 THEN 60 'OBSTRUCTION, EXIT LOOP
IF Z = 300 THEN ATTACKED = 1 ': PRINT "ATTACKED BY BISHOP AT "; I, J
IF Z = 900 THEN ATTACKED = 1 ': PRINT "ATTACKED BY QUEEN AT "; I, J
60 I = PCX: J = PCY 'CHECK NEXT DIAGONAL
70 I = I + 1: J = J - 1
IF I > 8 OR J < 1 THEN 80
Z = BOARD(I, J)
IF Z = 0 THEN 70
IF Z < 300 OR Z = 500 OR Z = 5000 THEN 80
IF Z = 300 THEN ATTACKED = 1 ': PRINT "ATTACKED BY BISHOP AT "; I, J
IF Z = 900 THEN ATTACKED = 1 ': PRINT "ATTACKED BY QUEEN AT "; I, J
80 I = PCX: J = PCY
90 I = I - 1: J = J + 1
IF I < 1 OR J > 8 THEN 100
Z = BOARD(I, J)
IF Z = 0 THEN 90
IF Z < 300 OR Z = 500 OR Z = 5000 THEN 100
IF Z = 300 THEN ATTACKED = 1 ': PRINT "ATTACKED BY BISHOP AT "; I, J
IF Z = 900 THEN ATTACKED = 1 ': PRINT "ATTACKED BY QUEEN AT "; I, J
100 I = PCX: J = PCY
110 I = I - 1: J = J - 1
IF I < 1 OR J < 1 THEN 120
Z = BOARD(I, J)
IF Z = 0 THEN 110
IF Z < 300 OR Z = 500 OR Z = 5000 THEN 120
IF Z = 300 THEN ATTACKED = 1 ': PRINT "ATTACKED BY BISHOP AT "; I, J
IF Z = 900 THEN ATTACKED = 1 ': PRINT "ATTACKED BY QUEEN AT "; I, J
120 I = PCX: J = PCY 'CHECK FOR PROTECTION
130 I = I + 1: J = J + 1
IF I > 8 OR J > 8 THEN 140
Z = BOARD(I, J)
IF Z = 0 THEN 130
IF Z > -300 OR Z = -500 OR Z = 5000 THEN 140 'OBSTRUCTION, EXIT LOOP
IF Z = -300 THEN PROTECTED = 1
IF Z = -900 THEN PROTECTED = 1
140 I = PCX: J = PCY 'CHECK NEXT DIAGONAL
150 I = I + 1: J = J - 1
IF I > 8 OR J < 1 THEN 160
Z = BOARD(I, J)
IF Z = 0 THEN 150
IF Z < 300 OR Z = 500 OR Z = 5000 THEN 160
IF Z = -300 THEN PROTECTED = 1
IF Z = -900 THEN PROTECTED = 1
160 I = PCX: J = PCY
170 I = I - 1: J = J + 1
IF I < 1 OR J > 8 THEN 180
Z = BOARD(I, J)
IF Z = 0 THEN 170
IF Z < 300 OR Z = 500 OR Z = 5000 THEN 180
IF Z = -300 THEN PROTECTED = 1
IF Z = -900 THEN PROTECTED = 1
180 I = PCX: J = PCY
190 I = I - 1: J = J - 1
IF I < 1 OR J < 1 THEN 300
Z = BOARD(I, J)
IF Z = 0 THEN 190
IF Z < 300 OR Z = 500 OR Z = 5000 THEN 300
IF Z = -300 THEN PROTECTED = 1
IF Z = -900 THEN PROTECTED = 1
300 'CHECK PAWNS
IF PCY > 1 AND PCX > 1 AND BOARD(PCX - 1, PCY - 1) = 100 THEN ATTACKED = 1 ': PRINT "ATTACKED BY PAWN AT "; PCX - 1, PCY - 1
IF PCY > 1 AND PCX < 8 AND BOARD(PCX + 1, PCY - 1) = 100 THEN ATTACKED = 1 ': PRINT "ATTACKED BY PAWN AT "; PCX + 1, PCY - 1
IF PCY < 8 AND PCX < 8 THEN
    IF BOARD(PCX + 1, PCY + 1) = -100 THEN PROTECTED = 1
END IF
IF PCY < 8 AND PCX > 1 THEN
    IF BOARD(PCX - 1, PCY + 1) = -100 THEN PROTECTED = 1
END IF
RETURN

GENERATEMOVE:
'OPENING
'TRY MOVING CENTRAL PAWNS 2 SQUARES
IF BOARD(4, 7) = -100 AND BOARD(4, 6) = 0 AND BOARD(4, 5) = 0 THEN
    PCX = 4: PCY = 5: GOSUB ENPRISE
    IF ATTACKED = 0 THEN D$ = "D7D5": RETURN
END IF
IF BOARD(5, 7) = -100 AND BOARD(5, 6) = 0 AND BOARD(5, 5) = 0 THEN
    PCX = 5: PCY = 5: GOSUB ENPRISE
    IF ATTACKED = 0 THEN D$ = "E7E5": RETURN
END IF
'TRY DEVELOPING KNIGHTS
IF BOARD(2, 8) = -290 AND BOARD(3, 6) = 0 THEN D$ = "B8C6": RETURN
IF BOARD(7, 8) = -290 AND BOARD(6, 6) = 0 THEN D$ = "G8F6": RETURN
IF BOARD(7, 8) = -290 AND BOARD(5, 7) = 0 THEN D$ = "G8E7": RETURN
IF BOARD(2, 8) = -290 AND BOARD(4, 7) = 0 THEN D$ = "B8D7": RETURN
'TRY DEVELOPING BISHOPS
IF BOARD(6, 8) = -300 THEN
    IF BOARD(3, 5) = 0 AND BOARD(4, 6) = 0 AND BOARD(5, 7) = 0 THEN
        PCX = 3: PCY = 5: GOSUB ENPRISE
        IF ATTACKED = 0 THEN D$ = "F8C5": RETURN
    END IF
    IF BOARD(5, 7) = 0 THEN
        PCX = 5: PCY = 7: GOSUB ENPRISE
        IF ATTACKED = 0 THEN D$ = "F8E7": RETURN
    END IF
    IF BOARD(2, 4) = 0 AND BOARD(3, 5) = 0 AND BOARD(4, 6) = 0 AND BOARD(5, 7) = 0 THEN
        PCX = 2: PCY = 4: GOSUB ENPRISE
        IF ATTACKED = 0 THEN D$ = "F8B4": RETURN
    END IF
    IF BOARD(4, 6) = 0 AND BOARD(5, 7) = 0 THEN
        PCX = 4: PCY = 6: GOSUB ENPRISE
        IF ATTACKED = 0 THEN D$ = "F8D6": RETURN
    END IF
    IF BOARD(7, 7) = 0 THEN
        PCX = 7: PCY = 7: GOSUB ENPRISE
        IF ATTACKED = 0 THEN D$ = "F8G7": RETURN
    END IF
END IF
IF BOARD(3, 8) = -300 THEN
    IF BOARD(6, 5) = 0 AND BOARD(4, 7) = 0 AND BOARD(5, 6) = 0 THEN
        PCX = 6: PCY = 5: GOSUB ENPRISE
        IF ATTACKED = 0 THEN D$ = "C8F5": RETURN
    END IF
    IF BOARD(4, 7) = 0 THEN
        PCX = 4: PCY = 7: GOSUB ENPRISE
        IF ATTACKED = 0 THEN D$ = "C8D7": RETURN
    END IF
    IF BOARD(7, 4) = 0 AND BOARD(4, 7) = 0 AND BOARD(5, 6) = 0 AND BOARD(6, 5) = 0 THEN
        PCX = 7: PCY = 4: GOSUB ENPRISE
        IF ATTACKED = 0 THEN D$ = "C8G4": RETURN
    END IF
    IF BOARD(5, 6) = 0 AND BOARD(4, 7) = 0 THEN
        PCX = 5: PCY = 6: GOSUB ENPRISE
        IF ATTACKED = 0 THEN D$ = "C8E6": RETURN
    END IF
    IF BOARD(2, 7) = 0 THEN
        PCX = 2: PCY = 7: GOSUB ENPRISE
        IF ATTACKED = 0 THEN D$ = "C8B7": RETURN
    END IF
END IF
'TRY MOVING CENTRAL PAWNS 1 SQUARE
IF BOARD(4, 7) = -100 AND BOARD(4, 6) = 0 THEN
    PCX = 4: PCY = 6: GOSUB ENPRISE
    IF ATTACKED = 0 THEN D$ = "D7D6": RETURN
END IF
IF BOARD(5, 7) = -100 AND BOARD(5, 6) = 0 THEN
    PCX = 5: PCY = 6: GOSUB ENPRISE
    IF ATTACKED = 0 THEN D$ = "E7E6": RETURN
END IF
'TRY CASTLING
IF BOARD(5, 8) = -5000 AND BOARD(6, 8) = 0 AND BOARD(7, 8) = 0 AND BOARD(8, 8) = -500 THEN
    PCX = 7: PCY = 8: GOSUB ENPRISE
    IF ATTACKED = 0 THEN D$ = "E8G8": RETURN
END IF
IF BOARD(5, 8) = -5000 AND BOARD(4, 8) = 0 AND BOARD(3, 8) = 0 AND BOARD(3, 8) = 0 AND BOARD(1, 8) = -500 THEN
    PCX = 3: PCY = 8: GOSUB ENPRISE
    IF ATTACKED = 0 THEN D$ = "E8C8": RETURN
END IF
'MIDDLEGAME
PRINT "STAGE: MIDDLEGAME": SLEEP: END
'ENDGAME
RETURN
I like to program in BASIC
With code that is simple and slick
I learnt it in school
And it is still cool
So it is my number one pick
Reply
#7
Adrian,

Very nice!

What does "MIDDLEGAME" mean? I took a bishop with a pawn, and that is the message it gave me.


Walter Whitman
The Joyful Programmer
a.k.a: Waltersmind
Please visit my website at: [url]http://www.TheJoyfulProgrammer.com[/url]
Please subscribe to my YouTube Channel at: [url]https://www.youtube.com/c/thejoyfulprogrammer[/url]
Please visit me at FaceBook: [url]https://www.facebook.com/thejoyfulprogrammer[/url]
Please follow me at Twitter: [url]https://twitter.com/TheJoyfulProg[/url]
Please follow me at Google+: [url]https://plus.google.com/+Thejoyfulprogrammer/posts[/url]
Please Visit me on Pinterest: [url]https://www.pinterest.com/waltersmind/[/url]
Dedicated to empowering computer programming hobbyists, tinkerers, amateurs, and enthusiasts.
profile for Walter Whitman at Stack Overflow, Q&A for professional and enthusiast programmers


Reply
#8
Walter,

It means that it has run out of AI!

I need to start working on the next portion of it, which is what the computer should do when Black's pieces are threatened in the opening (e.g. your threat of capturing the bishop with pawn), followed by how it should play the middlegame and endgame.

The Middlegame message is what I used to terminate the program at this point, and to remind myself what needs to be done next.

Cheers,
Adrian
I like to program in BASIC
With code that is simple and slick
I learnt it in school
And it is still cool
So it is my number one pick
Reply
#9
gosh....i've not done anything with this project for two years! time to get off my lazy butt! thanks bplus and TempodiBasic for reigniting my interest in computer chess programming!
I like to program in BASIC
With code that is simple and slick
I learnt it in school
And it is still cool
So it is my number one pick
Reply
#10
I quite like the idea of a totally mouse-driven program, so am looking at the GUI similar to Lucas Chess. Still no AI to speak of other than to check for legal moves.


Attached Files Thumbnail(s)

I like to program in BASIC
With code that is simple and slick
I learnt it in school
And it is still cool
So it is my number one pick
Reply
#11
Board looks good are you in a graphics screen?
B += x
Reply
#12
hi bplus,

thanks. yes, SCREEN _NEWIMAGE(1100, 800, 256)
I like to program in BASIC
With code that is simple and slick
I learnt it in school
And it is still cool
So it is my number one pick
Reply