Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Adding mouse to chess program, but I encounter a few problems, it says X has not been declared(before),now proedure....?
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Amodeus




PostPosted: Sat Oct 20, 2007 8:49 pm   Post subject: Adding mouse to chess program, but I encounter a few problems, it says X has not been declared(before),now proedure....?

Hey,

I'm new here, so please don't flame me. My friends and I are making a chess game;

code:
% %Plays some music throughout the game
% process playstuff
%     loop
%         Music.PlayFile ("Nouvelle Rouvenor Hero.mp3")
%     end loop
% end playstuff
%
% fork playstuff


%Creates variables for grid
var grid : array 1 .. sizepic (0, 195, 300, 395) of int

var xline1, xline2, yline1, yline2 : int




%Line values for grid table
xline1 := 0
xline2 := 0
yline1 := 195
yline2 := 195

procedure drawxtable %saves the grid lines going bottom-up
    loop
        drawline (xline1, 195, xline2, 395, black)

        xline1 := xline1 + 20
        xline2 := xline2 + 20
        exit when xline2 > 300
    end loop
end drawxtable

procedure drawytable %saves the grid lines going left-right
    loop
        drawline (0, yline1, 300, yline2, black)

        yline1 := yline1 + 20
        yline2 := yline2 + 20
        exit when yline2 > 395
    end loop
end drawytable

%draws the table
drawbox (0, 195, 300, 395, black)

drawxtable
drawytable

%saves the picture of the empty grid lines
takepic (0, 195, 300, 395, grid)

%draws the cannon fodder
drawbox (5, 200, 15, 210, black)
drawbox (25, 200, 35, 210, black)
drawbox (45, 200, 55, 210, black)
drawoval (70, 205, 5, 5, black)
drawstar (85, 200, 95, 210, black)
drawmapleleaf (155, 200, 145, 210, black)
drawfilloval (110, 205, 5, 5, black)
drawfillstar (125, 200, 135, 210, black)


%draws those heartless bastards who want to tear your arm off and beat you to death with it
drawbox (5, 360, 15, 370, black)
drawbox (25, 360, 35, 370, black)
drawbox (45, 360, 55, 370, black)
drawstar (45, 380, 55, 390, black)
drawoval (30, 385, 5, 5, black)

%Creates variables for all the pieces, blank/blankz being blank spaces used in animation
var boxorz1, boxorz2, boxorz3, sirkul1, rook1, bishop1, queen1, kingboxorz, gpawn, gpawn2, gpawn3, gknight1, grook1, blank, blankz : int

var spacenum, bishnum1, qnum1 : int
var gspacenum : int

%Takes a picture of each piece and blank space at the beginning of the game

boxorz1 := Pic.New (5, 200, 15, 210)
boxorz2 := Pic.New (25, 200, 35, 210)
boxorz3 := Pic.New (45, 200, 55, 210)
sirkul1 := Pic.New (65, 200, 75, 210)
rook1 := Pic.New (85, 200, 95, 210)
bishop1 := Pic.New (105, 200, 115, 210)
queen1 := Pic.New (125, 200, 135, 210)
kingboxorz := Pic.New (145, 200, 155, 210)
gpawn := Pic.New (5, 360, 15, 370)
gpawn2 := Pic.New (25, 360, 35, 370)
gpawn3 := Pic.New (45, 360, 55, 370)
gknight1 := Pic.New (25, 380, 35, 390)
grook1 := Pic.New (45, 380, 55, 390)
blank := Pic.New (0, 0, 10, 10)
blankz := Pic.New (0, 0, maxx, 195)

%The axis' required for moving pieces around the board.
var pawnxaxis1, pawnyaxis1, pawnxaxis2, pawnyaxis2, pawnxaxis3, pawnyaxis3, kxaxis1, kyaxis1, rxaxis1, ryaxis1, bishxaxis1, bishyaxis1, qxaxis1, qyaxis1, kingxaxis, kingyaxis : int
pawnxaxis1 := 5
pawnyaxis1 := 200
pawnxaxis2 := 25
pawnyaxis2 := 200
pawnxaxis3 := 45
pawnyaxis3 := 200
kxaxis1 := 65
kyaxis1 := 200
rxaxis1 := 85
ryaxis1 := 200
bishxaxis1 := 105
bishyaxis1 := 200
qxaxis1 := 125
qyaxis1 := 200
kingxaxis := 145
kingyaxis := 200
%Axis' for enemy pieces
var gpxaxis1, gpyaxis1, gpxaxis2, gpyaxis2, gpxaxis3, gpyaxis3, gkxaxis1, gkyaxis1, grxaxis1, gryaxis1 : int
gpxaxis1 := 5
gpyaxis1 := 360
gpxaxis2 := 25
gpyaxis2 := 360
gpxaxis3 := 45
gpyaxis3 := 360
gkxaxis1 := 25
gkyaxis1 := 380
grxaxis1 := 45
gryaxis1 := 380

%procedure that redraws all pieces at their current location, used in animation
procedure redraw
    Pic.Draw (boxorz1, pawnxaxis1, pawnyaxis1, picMerge)
    Pic.Draw (boxorz2, pawnxaxis2, pawnyaxis2, picMerge)
    Pic.Draw (boxorz3, pawnxaxis3, pawnyaxis3, picMerge)
    Pic.Draw (sirkul1, kxaxis1, kyaxis1, picMerge)
    Pic.Draw (rook1, rxaxis1, ryaxis1, picMerge)
    Pic.Draw (bishop1, bishxaxis1, bishyaxis1, picMerge)
    Pic.Draw (kingboxorz, kingxaxis, kingyaxis, picMerge)
    Pic.Draw (queen1, qxaxis1, qyaxis1, picMerge)
    Pic.Draw (gpawn, gpxaxis1, gpyaxis1, picMerge)
    Pic.Draw (gpawn2, gpxaxis2, gpyaxis2, picMerge)
    Pic.Draw (gpawn3, gpxaxis3, gpyaxis3, picMerge)
    Pic.Draw (gknight1, gkxaxis1, gkyaxis1, picMerge)
    Pic.Draw (grook1, grxaxis1, gryaxis1, picMerge)
end redraw

%Procedures for moving the pieces. they are labelled according to the piece that they will move.
procedure pawnmove
    for count : 1 .. 20

        Pic.Draw (boxorz1, pawnxaxis1, pawnyaxis1, picMerge)     %draws the box
        delay (50)
        Pic.Draw (blank, pawnxaxis1, pawnyaxis1, picCopy)     %draws the blank spot over the drawn box
        pawnyaxis1 := pawnyaxis1 + 1     %makes the next box 1 pixel over

    end for
    Pic.Draw (boxorz1, pawnxaxis1, pawnyaxis1, picMerge)     %draws the finished box
    drawpic (0, 195, grid, picMerge)     %redraws grid over blank spots

end pawnmove

procedure pawnmove2
    for count : 1 .. 20
        Pic.Draw (boxorz2, pawnxaxis2, pawnyaxis2, picMerge)     %draws the box
        delay (50)
        Pic.Draw (blank, pawnxaxis2, pawnyaxis2, picCopy)     %draws the blank spot over the drawn box
        pawnyaxis2 := pawnyaxis2 + 1     %makes the next box 1 pixel over

    end for
    Pic.Draw (boxorz2, pawnxaxis2, pawnyaxis2, picMerge)     %draws the finished box
    drawpic (0, 195, grid, picMerge)     %redraws grid over blank spots

end pawnmove2

procedure pawnmove3

    for count : 1 .. 20
        Pic.Draw (boxorz3, pawnxaxis3, pawnyaxis3, picMerge)     %draws the box
        delay (50)
        Pic.Draw (blank, pawnxaxis3, pawnyaxis3, picCopy)     %draws the blank spot over the drawn box
        pawnyaxis3 := pawnyaxis3 + 1     %makes the next box 1 pixel over

    end for
    Pic.Draw (boxorz3, pawnxaxis3, pawnyaxis3, picMerge)     %draws the finished box
    drawpic (0, 195, grid, picMerge)     %redraws grid over blank spots

end pawnmove3

%PROCEDURES FOR DOUBLE PAWN MOVES, lower team

procedure doublepawnmove
    for count : 1 .. 40

        Pic.Draw (boxorz1, pawnxaxis1, pawnyaxis1, picMerge)     %draws the box
        delay (50)
        Pic.Draw (blank, pawnxaxis1, pawnyaxis1, picCopy)     %draws the blank spot over the drawn box
        pawnyaxis1 := pawnyaxis1 + 1     %makes the next box 1 pixel over

    end for
    Pic.Draw (boxorz1, pawnxaxis1, pawnyaxis1, picMerge)     %draws the finished box
    drawpic (0, 195, grid, picMerge)     %redraws grid over blank spots

end doublepawnmove

procedure doublepawnmove2
    for count : 1 .. 40
        Pic.Draw (boxorz2, pawnxaxis2, pawnyaxis2, picMerge)     %draws the box
        delay (50)
        Pic.Draw (blank, pawnxaxis2, pawnyaxis2, picCopy)     %draws the blank spot over the drawn box
        pawnyaxis2 := pawnyaxis2 + 1     %makes the next box 1 pixel over

    end for
    Pic.Draw (boxorz2, pawnxaxis2, pawnyaxis2, picMerge)     %draws the finished box
    drawpic (0, 195, grid, picMerge)     %redraws grid over blank spots

end doublepawnmove2

procedure doublepawnmove3

    for count : 1 .. 40
        Pic.Draw (boxorz3, pawnxaxis3, pawnyaxis3, picMerge)     %draws the box
        delay (50)
        Pic.Draw (blank, pawnxaxis3, pawnyaxis3, picCopy)     %draws the blank spot over the drawn box
        pawnyaxis3 := pawnyaxis3 + 1     %makes the next box 1 pixel over

    end for
    Pic.Draw (boxorz3, pawnxaxis3, pawnyaxis3, picMerge)     %draws the finished box
    drawpic (0, 195, grid, picMerge)     %redraws grid over blank spots

end doublepawnmove3

%Procedures for moving knight
procedure upleft
    for count : 1 .. 40 %First part of knight move, makes it go up 2 squares
        Pic.Draw (sirkul1, kxaxis1, kyaxis1, picMerge) %draws the circle at the original location
        delay (50)
        Pic.Draw (blank, kxaxis1, kyaxis1, picCopy) %draws a white box over the circle, effectively erasing it
        kyaxis1 := kyaxis1 + 1 %adds 1 pixel to the circle's y-axis so it is redrawn 1 pixel up next time
    end for
    for count : 1 .. 20 %Second part of knight move, makes it go left 1 square after going up 2 squares
        Pic.Draw (sirkul1, kxaxis1, kyaxis1, picMerge) %draws circle again
        delay (50)
        Pic.Draw (blank, kxaxis1, kyaxis1, picCopy) %draws white box to erase
        kxaxis1 := kxaxis1 - 1 %Takes away 1 pixel from circle's x-axis so it is redrawn 1 pixel to the left next time
    end for
    Pic.Draw (sirkul1, kxaxis1, kyaxis1, picMerge)
    drawpic (0, 195, grid, picMerge)
end upleft

procedure upright
    for count : 1 .. 40 %exact same as before
        Pic.Draw (sirkul1, kxaxis1, kyaxis1, picMerge)
        delay (50)
        Pic.Draw (blank, kxaxis1, kyaxis1, picCopy)
        kyaxis1 := kyaxis1 + 1
    end for
    for count : 1 .. 20
        Pic.Draw (sirkul1, kxaxis1, kyaxis1, picMerge)
        delay (50)
        Pic.Draw (blank, kxaxis1, kyaxis1, picCopy)
        kxaxis1 := kxaxis1 + 1 %This time, adds a pixel to the circle's x-axis so it is drawn 1 pixel to the right
    end for
    Pic.Draw (sirkul1, kxaxis1, kyaxis1, picMerge) %draws finished circle again
    drawpic (0, 195, grid, picMerge)  %draws grid again to eliminate broken lines
end upright

procedure downright
    for count : 1 .. 40
        Pic.Draw (sirkul1, kxaxis1, kyaxis1, picMerge)
        delay (50)
        Pic.Draw (blank, kxaxis1, kyaxis1, picCopy)
        kyaxis1 := kyaxis1 - 1
    end for
    for count : 1 .. 20
        Pic.Draw (sirkul1, kxaxis1, kyaxis1, picMerge)
        delay (50)
        Pic.Draw (blank, kxaxis1, kyaxis1, picCopy)
        kxaxis1 := kxaxis1 + 1
    end for
    Pic.Draw (sirkul1, kxaxis1, kyaxis1, picMerge)
    drawpic (0, 195, grid, picMerge)
end downright

procedure downleft
    for count : 1 .. 40
        Pic.Draw (sirkul1, kxaxis1, kyaxis1, picMerge)
        delay (50)
        Pic.Draw (blank, kxaxis1, kyaxis1, picCopy)
        kyaxis1 := kyaxis1 - 1
    end for
    for count : 1 .. 20
        Pic.Draw (sirkul1, kxaxis1, kyaxis1, picMerge)
        delay (50)
        Pic.Draw (blank, kxaxis1, kyaxis1, picCopy)
        kxaxis1 := kxaxis1 - 1
    end for
    Pic.Draw (sirkul1, kxaxis1, kyaxis1, picMerge)
    drawpic (0, 195, grid, picMerge)
end downleft

procedure leftup
    for count : 1 .. 40
        Pic.Draw (sirkul1, kxaxis1, kyaxis1, picMerge)
        delay (50)
        Pic.Draw (blank, kxaxis1, kyaxis1, picCopy)
        kxaxis1 := kxaxis1 - 1
    end for
    for count : 1 .. 20
        Pic.Draw (sirkul1, kxaxis1, kyaxis1, picMerge)
        delay (50)
        Pic.Draw (blank, kxaxis1, kyaxis1, picCopy)
        kyaxis1 := kyaxis1 + 1
    end for
    Pic.Draw (sirkul1, kxaxis1, kyaxis1, picMerge)
    drawpic (0, 195, grid, picMerge)
end leftup

procedure leftdown
    for count : 1 .. 40
        Pic.Draw (sirkul1, kxaxis1, kyaxis1, picMerge)
        delay (50)
        Pic.Draw (blank, kxaxis1, kyaxis1, picCopy)
        kxaxis1 := kxaxis1 - 1
    end for
    for count : 1 .. 20
        Pic.Draw (sirkul1, kxaxis1, kyaxis1, picMerge)
        delay (50)
        Pic.Draw (blank, kxaxis1, kyaxis1, picCopy)
        kyaxis1 := kyaxis1 - 1
    end for
    Pic.Draw (sirkul1, kxaxis1, kyaxis1, picMerge)
    drawpic (0, 195, grid, picMerge)
end leftdown

procedure rightup
    for count : 1 .. 40
        Pic.Draw (sirkul1, kxaxis1, kyaxis1, picMerge)
        delay (50)
        Pic.Draw (blank, kxaxis1, kyaxis1, picCopy)
        kxaxis1 := kxaxis1 + 1
    end for
    for count : 1 .. 20
        Pic.Draw (sirkul1, kxaxis1, kyaxis1, picMerge)
        delay (50)
        Pic.Draw (blank, kxaxis1, kyaxis1, picCopy)
        kyaxis1 := kyaxis1 + 1
    end for
    Pic.Draw (sirkul1, kxaxis1, kyaxis1, picMerge)
    drawpic (0, 195, grid, picMerge)

end rightup

procedure rightdown
    for count : 1 .. 40
        Pic.Draw (sirkul1, kxaxis1, kxaxis1, picMerge)
        delay (50)
        Pic.Draw (blank, kxaxis1, kyaxis1, picCopy)
        kxaxis1 := kxaxis1 + 1
    end for
    for count : 1 .. 20
        Pic.Draw (sirkul1, kxaxis1, kyaxis1, picMerge)
        delay (50)
        Pic.Draw (blank, kxaxis1, kyaxis1, picCopy)
        kyaxis1 := kyaxis1 + 1
    end for
    Pic.Draw (sirkul1, kxaxis1, kyaxis1, picMerge)
    drawpic (0, 195, grid, picMerge)
end rightdown


%Procedures for moving the rook


procedure rookupmove1
    for count : 1 .. spacenum
        Pic.Draw (rook1, rxaxis1, ryaxis1, picMerge)
        delay (50)
        Pic.Draw (blank, rxaxis1, ryaxis1, picCopy)
        ryaxis1 := ryaxis1 + 1
    end for
    Pic.Draw (rook1, rxaxis1, ryaxis1, picMerge)
    drawpic (0, 195, grid, picMerge)

end rookupmove1

procedure rookdownmove1
    for count : 1 .. spacenum
        Pic.Draw (rook1, rxaxis1, ryaxis1, picMerge)
        delay (50)
        Pic.Draw (blank, rxaxis1, ryaxis1, picCopy)
        ryaxis1 := ryaxis1 - 1
    end for
    Pic.Draw (rook1, rxaxis1, ryaxis1, picMerge)
    drawpic (0, 195, grid, picMerge)
end rookdownmove1

procedure rookleftmove1
    for count : 1 .. spacenum
        Pic.Draw (rook1, rxaxis1, ryaxis1, picMerge)
        delay (50)
        Pic.Draw (blank, rxaxis1, ryaxis1, picCopy)
        rxaxis1 := rxaxis1 - 1
    end for
    Pic.Draw (rook1, rxaxis1, ryaxis1, picMerge)
    drawpic (0, 195, grid, picMerge)
end rookleftmove1

procedure rookrightmove1
    for count : 1 .. spacenum
        Pic.Draw (rook1, rxaxis1, ryaxis1, picMerge)
        delay (50)
        Pic.Draw (blank, rxaxis1, ryaxis1, picCopy)
        rxaxis1 := rxaxis1 + 1
    end for
    Pic.Draw (rook1, rxaxis1, ryaxis1, picMerge)
    drawpic (0, 195, grid, picMerge)
end rookrightmove1

%Procedures for moving the bishop

procedure bishopupleft
    for count : 1 .. bishnum1
        Pic.Draw (bishop1, bishxaxis1, bishyaxis1, picMerge)
        delay (50)
        Pic.Draw (blank, bishxaxis1, bishyaxis1, picCopy)
        bishxaxis1 := bishxaxis1 - 1
        bishyaxis1 := bishyaxis1 + 1
    end for
    Pic.Draw (bishop1, bishxaxis1, bishyaxis1, picMerge)
    drawpic (0, 195, grid, picMerge)
end bishopupleft

procedure bishopupright
    for count : 1 .. bishnum1
        Pic.Draw (bishop1, bishxaxis1, bishyaxis1, picMerge)
        delay (50)
        Pic.Draw (blank, bishxaxis1, bishyaxis1, picCopy)
        bishxaxis1 := bishxaxis1 + 1
        bishyaxis1 := bishyaxis1 + 1
    end for
    Pic.Draw (bishop1, bishxaxis1, bishyaxis1, picMerge)
    drawpic (0, 195, grid, picMerge)
end bishopupright

procedure bishopdownleft
    for count : 1 .. bishnum1
        Pic.Draw (bishop1, bishxaxis1, bishyaxis1, picMerge)
        delay (50)
        Pic.Draw (blank, bishxaxis1, bishyaxis1, picCopy)
        bishxaxis1 := bishxaxis1 - 1
        bishyaxis1 := bishyaxis1 - 1
    end for
    Pic.Draw (bishop1, bishxaxis1, bishyaxis1, picMerge)
    drawpic (0, 195, grid, picMerge)
end bishopdownleft

procedure bishopdownright
    for count : 1 .. bishnum1
        Pic.Draw (bishop1, bishxaxis1, bishyaxis1, picMerge)
        delay (50)
        Pic.Draw (blank, bishxaxis1, bishyaxis1, picCopy)
        bishxaxis1 := bishxaxis1 + 1
        bishyaxis1 := bishyaxis1 - 1
    end for
    Pic.Draw (bishop1, bishxaxis1, bishyaxis1, picMerge)
    drawpic (0, 195, grid, picMerge)
end bishopdownright

%Procedures for moving TEH QU33N

procedure qupleft
    for count : 1 .. qnum1
        Pic.Draw (queen1, qxaxis1, qyaxis1, picMerge)
        delay (50)
        Pic.Draw (blank, qxaxis1, qyaxis1, picCopy)
        qxaxis1 := qxaxis1 - 1
        qyaxis1 := qyaxis1 + 1
    end for
    Pic.Draw (queen1, qxaxis1, qyaxis1, picMerge)
    drawpic (0, 195, grid, picMerge)
end qupleft

procedure qup
    for count : 1 .. qnum1
        Pic.Draw (queen1, qxaxis1, qyaxis1, picMerge)
        delay (50)
        Pic.Draw (blank, qxaxis1, qyaxis1, picCopy)
        qyaxis1 := qyaxis1 + 1
    end for
    Pic.Draw (queen1, qxaxis1, qyaxis1, picMerge)
    drawpic (0, 195, grid, picMerge)
end qup

procedure qupright
    for count : 1 .. qnum1
        Pic.Draw (queen1, qxaxis1, qyaxis1, picMerge)
        delay (50)
        Pic.Draw (blank, qxaxis1, qyaxis1, picCopy)
        qxaxis1 := qxaxis1 + 1
        qyaxis1 := qyaxis1 + 1
    end for
    Pic.Draw (queen1, qxaxis1, qyaxis1, picMerge)
    drawpic (0, 195, grid, picMerge)
end qupright

procedure qdownleft
    for count : 1 .. qnum1
        Pic.Draw (queen1, qxaxis1, qyaxis1, picMerge)
        delay (50)
        Pic.Draw (blank, qxaxis1, qyaxis1, picCopy)
        qxaxis1 := qxaxis1 - 1
        qyaxis1 := qyaxis1 - 1
    end for
    Pic.Draw (queen1, qxaxis1, qyaxis1, picMerge)
    drawpic (0, 195, grid, picMerge)
end qdownleft

procedure qdown
    for count : 1 .. qnum1
        Pic.Draw (queen1, qxaxis1, qyaxis1, picMerge)
        delay (50)
        Pic.Draw (blank, qxaxis1, qyaxis1, picCopy)
        qyaxis1 := qyaxis1 - 1
    end for
    Pic.Draw (queen1, qxaxis1, qyaxis1, picMerge)
    drawpic (0, 195, grid, picMerge)
end qdown

procedure qdownright
    for count : 1 .. qnum1
        Pic.Draw (queen1, qxaxis1, qyaxis1, picMerge)
        delay (50)
        Pic.Draw (blank, qxaxis1, qyaxis1, picCopy)
        qxaxis1 := qxaxis1 + 1
        qyaxis1 := qyaxis1 - 1
    end for
    Pic.Draw (queen1, qxaxis1, qyaxis1, picMerge)
    drawpic (0, 195, grid, picMerge)
end qdownright

procedure qright
    for count : 1 .. qnum1
        Pic.Draw (queen1, qxaxis1, qyaxis1, picMerge)
        delay (50)
        Pic.Draw (blank, qxaxis1, qyaxis1, picCopy)
        qxaxis1 := qxaxis1 + 1
    end for
    Pic.Draw (queen1, qxaxis1, qyaxis1, picMerge)
    drawpic (0, 195, grid, picMerge)
end qright

procedure qleft
    for count : 1 .. qnum1
        Pic.Draw (queen1, qxaxis1, qyaxis1, picMerge)
        delay (50)
        Pic.Draw (blank, qxaxis1, qyaxis1, picCopy)
        qxaxis1 := qxaxis1 - 1
    end for
    Pic.Draw (queen1, qxaxis1, qyaxis1, picMerge)
    drawpic (0, 195, grid, picMerge)
end qleft

%Procedures for moving king

procedure kup
    for count : 1 .. 20
        Pic.Draw (kingboxorz, kingxaxis, kingyaxis, picMerge)
        delay (50)
        Pic.Draw (blank, kingxaxis, kingyaxis, picCopy)
        kingyaxis := kingyaxis + 1
    end for
    Pic.Draw (kingboxorz, kingxaxis, kingyaxis, picMerge)
    drawpic (0, 195, grid, picMerge)
end kup

procedure kdown
    for count : 1 .. 20
        Pic.Draw (kingboxorz, kingxaxis, kingyaxis, picMerge)
        delay (50)
        Pic.Draw (blank, kingxaxis, kingyaxis, picCopy)
        kingyaxis := kingyaxis - 1
    end for
    Pic.Draw (kingboxorz, kingxaxis, kingyaxis, picMerge)
    drawpic (0, 195, grid, picMerge)
end kdown

procedure kleft
    for count : 1 .. 20
        Pic.Draw (kingboxorz, kingxaxis, kingyaxis, picMerge)
        delay (50)
        Pic.Draw (blank, kingxaxis, kingyaxis, picCopy)
        kingxaxis := kingxaxis - 1
    end for
    Pic.Draw (kingboxorz, kingxaxis, kingyaxis, picMerge)
    drawpic (0, 195, grid, picMerge)
end kleft

procedure kright
    for count : 1 .. 20
        Pic.Draw (kingboxorz, kingxaxis, kingyaxis, picMerge)
        delay (50)
        Pic.Draw (blank, kingxaxis, kingyaxis, picCopy)
        kingxaxis := kingxaxis + 1
    end for
    Pic.Draw (kingboxorz, kingxaxis, kingyaxis, picMerge)
    drawpic (0, 195, grid, picMerge)
end kright

procedure kupright
    for count : 1 .. 20
        Pic.Draw (kingboxorz, kingxaxis, kingyaxis, picMerge)
        delay (50)
        Pic.Draw (blank, kingxaxis, kingyaxis, picCopy)
        kingyaxis := kingyaxis + 1
        kingxaxis := kingxaxis + 1
    end for
    Pic.Draw (kingboxorz, kingxaxis, kingyaxis, picMerge)
    drawpic (0, 195, grid, picMerge)
end kupright

procedure kupleft
    for count : 1 .. 20
        Pic.Draw (kingboxorz, kingxaxis, kingyaxis, picMerge)
        delay (50)
        Pic.Draw (blank, kingxaxis, kingyaxis, picCopy)
        kingyaxis := kingyaxis + 1
        kingxaxis := kingxaxis - 1
    end for
    Pic.Draw (kingboxorz, kingxaxis, kingyaxis, picMerge)
    drawpic (0, 195, grid, picMerge)
end kupleft

procedure kdownleft
    for count : 1 .. 20
        Pic.Draw (kingboxorz, kingxaxis, kingyaxis, picMerge)
        delay (50)
        Pic.Draw (blank, kingxaxis, kingyaxis, picCopy)
        kingyaxis := kingyaxis - 1
        kingxaxis := kingxaxis - 1
    end for
    Pic.Draw (kingboxorz, kingxaxis, kingyaxis, picMerge)
    drawpic (0, 195, grid, picMerge)
end kdownleft

procedure kdownright
    for count : 1 .. 20
        Pic.Draw (kingboxorz, kingxaxis, kingyaxis, picMerge)
        delay (50)
        Pic.Draw (blank, kingxaxis, kingyaxis, picCopy)
        kingyaxis := kingyaxis - 1
        kingxaxis := kingxaxis + 1
    end for
    Pic.Draw (kingboxorz, kingxaxis, kingyaxis, picMerge)
    drawpic (0, 195, grid, picMerge)
end kdownright


%Procedures for moving opposing pieces

procedure gpawnmove1
    for count : 1 .. 20
        Pic.Draw (gpawn, gpxaxis1, gpyaxis1, picMerge)     %draws the box
        delay (50)
        Pic.Draw (blank, gpxaxis1, gpyaxis1, picCopy)     %draws the blank spot over the drawn box
        gpyaxis1 := gpyaxis1 - 1     %makes the next box 1 pixel over

    end for
    Pic.Draw (gpawn, gpxaxis1, gpyaxis1, picMerge)     %draws the finished box
    drawpic (0, 195, grid, picMerge)     %redraws grid over blank spots

end gpawnmove1

procedure gpawnmove2
    for count : 1 .. 20
        Pic.Draw (gpawn2, gpxaxis2, gpyaxis2, picMerge)     %draws the box
        delay (50)
        Pic.Draw (blank, gpxaxis2, gpyaxis2, picCopy)     %draws the blank spot over the drawn box
        gpyaxis2 := gpyaxis2 - 1     %makes the next box 1 pixel over

    end for
    Pic.Draw (gpawn2, gpxaxis2, gpyaxis2, picMerge)     %draws the finished box
    drawpic (0, 195, grid, picMerge)     %redraws grid over blank spots

end gpawnmove2

procedure gpawnmove3
    for count : 1 .. 20
        Pic.Draw (gpawn3, gpxaxis3, gpyaxis3, picMerge)     %draws the box
        delay (50)
        Pic.Draw (blank, gpxaxis3, gpyaxis3, picCopy)     %draws the blank spot over the drawn box
        gpyaxis3 := gpyaxis3 - 1     %makes the next box 1 pixel over

    end for
    Pic.Draw (gpawn3, gpxaxis3, gpyaxis3, picMerge)     %draws the finished box
    drawpic (0, 195, grid, picMerge)     %redraws grid over blank spots

end gpawnmove3

%PROCEDURES FOR DOUBLE PAWN MOVES, upper team

procedure doublegpawnmove1
    for count : 1 .. 40
        Pic.Draw (gpawn, gpxaxis1, gpyaxis1, picMerge)     %draws the box
        delay (50)
        Pic.Draw (blank, gpxaxis1, gpyaxis1, picCopy)     %draws the blank spot over the drawn box
        gpyaxis1 := gpyaxis1 - 1     %makes the next box 1 pixel over

    end for
    Pic.Draw (gpawn, gpxaxis1, gpyaxis1, picMerge)     %draws the finished box
    drawpic (0, 195, grid, picMerge)     %redraws grid over blank spots

end doublegpawnmove1

procedure doublegpawnmove2
    for count : 1 .. 40
        Pic.Draw (gpawn2, gpxaxis2, gpyaxis2, picMerge)     %draws the box
        delay (50)
        Pic.Draw (blank, gpxaxis2, gpyaxis2, picCopy)     %draws the blank spot over the drawn box
        gpyaxis2 := gpyaxis2 - 1     %makes the next box 1 pixel over

    end for
    Pic.Draw (gpawn2, gpxaxis2, gpyaxis2, picMerge)     %draws the finished box
    drawpic (0, 195, grid, picMerge)     %redraws grid over blank spots

end doublegpawnmove2

procedure doublegpawnmove3
    for count : 1 .. 40
        Pic.Draw (gpawn3, gpxaxis3, gpyaxis3, picMerge)     %draws the box
        delay (50)
        Pic.Draw (blank, gpxaxis3, gpyaxis3, picCopy)     %draws the blank spot over the drawn box
        gpyaxis3 := gpyaxis3 - 1     %makes the next box 1 pixel over

    end for
    Pic.Draw (gpawn3, gpxaxis3, gpyaxis3, picMerge)     %draws the finished box
    drawpic (0, 195, grid, picMerge)     %redraws grid over blank spots

end doublegpawnmove3

%Procedures for upper knight moves

procedure gupleft
    for count : 1 .. 40 %First part of knight move, makes it go up 2 squares
        Pic.Draw (gknight1, gkxaxis1, gkyaxis1, picMerge) %draws the circle at the original location
        delay (50)
        Pic.Draw (blank, gkxaxis1, gkyaxis1, picCopy) %draws a white box over the circle, effectively erasing it
        gkyaxis1 := gkyaxis1 + 1 %adds 1 pixel to the circle's y-axis so it is redrawn 1 pixel up next time
    end for
    for count : 1 .. 20 %Second part of knight move, makes it go left 1 square after going up 2 squares
        Pic.Draw (gknight1, gkxaxis1, gkyaxis1, picMerge) %draws circle again
        delay (50)
        Pic.Draw (blank, gkxaxis1, gkyaxis1, picCopy) %draws white box to erase
        gkxaxis1 := gkxaxis1 - 1 %Takes away 1 pixel from circle's x-axis so it is redrawn 1 pixel to the left next time
    end for
    Pic.Draw (gknight1, gkxaxis1, gkyaxis1, picMerge)
    drawpic (0, 195, grid, picMerge)
end gupleft

procedure gupright
    for count : 1 .. 40 %exact same as before
        Pic.Draw (gknight1, gkxaxis1, gkyaxis1, picMerge)
        delay (50)
        Pic.Draw (blank, gkxaxis1, gkyaxis1, picCopy)
        gkyaxis1 := gkyaxis1 + 1
    end for
    for count : 1 .. 20
        Pic.Draw (gknight1, gkxaxis1, gkyaxis1, picMerge)
        delay (50)
        Pic.Draw (blank, gkxaxis1, gkyaxis1, picCopy)
        gkxaxis1 := gkxaxis1 + 1 %This time, adds a pixel to the circle's x-axis so it is drawn 1 pixel to the right
    end for
    Pic.Draw (gknight1, gkxaxis1, gkyaxis1, picMerge) %draws finished circle again
    drawpic (0, 195, grid, picMerge)  %draws grid again to eliminate broken lines
end gupright

procedure gdownright
    for count : 1 .. 40
        Pic.Draw (gknight1, gkxaxis1, gkyaxis1, picMerge)
        delay (50)
        Pic.Draw (blank, gkxaxis1, gkyaxis1, picCopy)
        gkyaxis1 := gkyaxis1 - 1
    end for
    for count : 1 .. 20
        Pic.Draw (gknight1, gkxaxis1, gkyaxis1, picMerge)
        delay (50)
        Pic.Draw (blank, gkxaxis1, gkyaxis1, picCopy)
        gkxaxis1 := gkxaxis1 + 1
    end for
    Pic.Draw (gknight1, gkxaxis1, gkyaxis1, picMerge)
    drawpic (0, 195, grid, picMerge)
end gdownright

procedure gdownleft
    for count : 1 .. 40
        Pic.Draw (gknight1, gkxaxis1, gkyaxis1, picMerge)
        delay (50)
        Pic.Draw (blank, gkxaxis1, gkyaxis1, picCopy)
        gkyaxis1 := gkyaxis1 - 1
    end for
    for count : 1 .. 20
        Pic.Draw (gknight1, gkxaxis1, gkyaxis1, picMerge)
        delay (50)
        Pic.Draw (blank, gkxaxis1, gkyaxis1, picCopy)
        gkxaxis1 := gkxaxis1 - 1
    end for
    Pic.Draw (gknight1, gkxaxis1, gkyaxis1, picMerge)
    drawpic (0, 195, grid, picMerge)
end gdownleft

procedure gleftup
    for count : 1 .. 40
        Pic.Draw (gknight1, gkxaxis1, gkyaxis1, picMerge)
        Pic.Draw (blank, gkxaxis1, gkyaxis1, picCopy)
        gkxaxis1 := gkxaxis1 - 1
    end for
    for count : 1 .. 20
        Pic.Draw (gknight1, gkxaxis1, gkyaxis1, picMerge)
        Pic.Draw (blank, gkxaxis1, gkyaxis1, picCopy)
        gkyaxis1 := gkyaxis1 + 1
    end for
    Pic.Draw (gknight1, gkxaxis1, gkyaxis1, picMerge)
    drawpic (0, 195, grid, picMerge)
end gleftup

procedure gleftdown
    for count : 1 .. 40
        Pic.Draw (gknight1, gkxaxis1, gkyaxis1, picMerge)
        Pic.Draw (blank, gkxaxis1, gkyaxis1, picCopy)
        gkxaxis1 := gkxaxis1 - 1
    end for
    for count : 1 .. 20
        Pic.Draw (gknight1, gkxaxis1, gkyaxis1, picMerge)
        Pic.Draw (blank, gkxaxis1, gkyaxis1, picCopy)
        gkyaxis1 := gkyaxis1 - 1
    end for
    Pic.Draw (gknight1, gkxaxis1, gkyaxis1, picMerge)
    drawpic (0, 195, grid, picMerge)
end gleftdown

procedure grightup
    for count : 1 .. 40
        Pic.Draw (gknight1, gkxaxis1, gkyaxis1, picMerge)
        Pic.Draw (blank, gkxaxis1, gkyaxis1, picCopy)
        gkxaxis1 := gkxaxis1 + 1
    end for
    for count : 1 .. 20
        Pic.Draw (gknight1, gkxaxis1, gkyaxis1, picMerge)
        Pic.Draw (blank, gkxaxis1, gkyaxis1, picCopy)
        gkyaxis1 := gkyaxis1 + 1
    end for
    Pic.Draw (gknight1, gkxaxis1, gkyaxis1, picMerge)
    drawpic (0, 195, grid, picMerge)

end grightup

procedure grightdown
    for count : 1 .. 40
        Pic.Draw (gknight1, gkxaxis1, gkyaxis1, picMerge)
        Pic.Draw (blank, gkxaxis1, gkyaxis1, picCopy)
        gkxaxis1 := gkxaxis1 + 1
    end for
    for count : 1 .. 20
        Pic.Draw (gknight1, gkxaxis1, gkyaxis1, picMerge)
        Pic.Draw (blank, gkxaxis1, gkyaxis1, picCopy)
        gkyaxis1 := gkyaxis1 + 1
    end for
    Pic.Draw (gknight1, gkxaxis1, gkyaxis1, picMerge)
    drawpic (0, 195, grid, picMerge)
end grightdown

%Procedues for upper rook move

procedure grookupmove1
    for count : 1 .. spacenum
        Pic.Draw (grook1, grxaxis1, gryaxis1, picMerge)
        delay (50)
        Pic.Draw (blank, grxaxis1, gryaxis1, picCopy)
        gryaxis1 := gryaxis1 + 1
    end for
    Pic.Draw (grook1, grxaxis1, gryaxis1, picMerge)
    drawpic (0, 195, grid, picMerge)

end grookupmove1

procedure grookdownmove1
    for count : 1 .. gspacenum
        Pic.Draw (grook1, grxaxis1, gryaxis1, picMerge)
        delay (50)
        Pic.Draw (blank, grxaxis1, gryaxis1, picCopy)
        gryaxis1 := gryaxis1 - 1
    end for
    Pic.Draw (grook1, grxaxis1, gryaxis1, picMerge)
    drawpic (0, 195, grid, picMerge)
end grookdownmove1

procedure grookleftmove1
    for count : 1 .. gspacenum
        Pic.Draw (grook1, grxaxis1, gryaxis1, picMerge)
        delay (50)
        Pic.Draw (blank, grxaxis1, gryaxis1, picCopy)
        grxaxis1 := grxaxis1 - 1
    end for
    Pic.Draw (grook1, grxaxis1, gryaxis1, picMerge)
    drawpic (0, 195, grid, picMerge)
end grookleftmove1

procedure grookrightmove1
    for count : 1 .. gspacenum
        Pic.Draw (grook1, grxaxis1, gryaxis1, picMerge)
        delay (50)
        Pic.Draw (blank, grxaxis1, gryaxis1, picCopy)
        grxaxis1 := grxaxis1 + 1
    end for
    Pic.Draw (grook1, grxaxis1, gryaxis1, picMerge)
    drawpic (0, 195, grid, picMerge)
end grookrightmove1



%Input section, asks which piece to move.
var answer : int %first answer for piece to move
var answer2, answer3, answer4, direction1, direction2, direction3 : string %Answer to move knight, bishops and queens
var answer5, answer6, answer7 : string %Answers to move king
var r : real %creates variable (r) to use with the random number
var ram1 : int % variable for how many spaces the rook moves

%first turn
locate (14, 1)
put "Which piece would you like to move?"
locate (15, 1)
put "1 Pawn 1"
locate (15, 12)
put "2 Pawn 2"
locate (15, 18)
put "3 Pawn 3"
locate (16, 1)
put "4 Knight"
locate (16, 12)
put "5 Rook"
locate (16, 18)
put "6 Bishop"
locate (17, 1)
put "7 Queen"
locate (17, 12)
put "8 King"

get answer

if answer = 1 then
    doublepawnmove
elsif answer = 2 then
    doublepawnmove2
elsif answer = 3 then
    doublepawnmove3
elsif answer = 4 then
    put "Would you like to move up, left, right or down?"
    get answer2
    if answer2 = "up" or answer2 = "down" then
        put "Would you like to move right or left?"
        get answer3
        if answer2 = "up" and answer3 = "left" then
            upleft
        elsif answer2 = "up" and answer3 = "right" then
            upright
        elsif answer2 = "down" and answer3 = "left" then
            downleft
        elsif answer2 = "down" and answer3 = "right" then
            downright
        else
            locate (19, 1)
            put "Unable to move there"
        end if
    elsif answer2 = "left" or answer2 = "right" then
        put "Would you like to move up or down?"
        get answer4
        if answer2 = "left" and answer4 = "up" then
            leftup
        elsif answer2 = "left" and answer4 = "down" then
            leftdown
        elsif answer2 = "right" and answer4 = "up" then
            rightup
        else
            locate (19, 1)
            put "Unable to move there"
        end if
    end if
elsif answer = 5 then
    put "Which direction would you like to move?"
    get direction1
    if direction1 = "left" then
        put "How many spaces would you like to move?"
        get spacenum
        spacenum := spacenum * 20
        rookleftmove1
    elsif direction1 = "right" then
        put "How many spaces would you like to move?"
        get spacenum
        spacenum := spacenum * 20
        rookrightmove1
    elsif direction1 = "up" then
        put "How many spaces would you like to move?"
        get spacenum
        spacenum := spacenum * 20
        rookupmove1
    elsif direction1 = "down" then
        put "How many spaces would you like to move?"
        get spacenum
        spacenum := spacenum * 20
        rookdownmove1
    end if
elsif answer = 6 then
    put "Would you like to go up right, up left, down right or down left?"
    get direction2
    if direction2 = "up right" then
        put "How many spaces would you like to move?"
        get bishnum1
        bishnum1 := bishnum1 * 20
        bishopupright
    elsif direction2 = "up left" then
        put "How many spaces would you like to move?"
        get bishnum1
        bishnum1 := bishnum1 * 20
        bishopupleft
    elsif direction2 = "down right" then
        put "How many spaces would you like to move?"
        get bishnum1
        bishnum1 := bishnum1 * 20
        bishopdownright
    elsif direction2 = "down left" then
        put "How many spaces would you like to move?"
        get bishnum1
        bishnum1 := bishnum1 * 20
        bishopdownleft
    else
        put "invalid direction"
    end if
elsif answer = 7 then
    put "How many spaces would you like to move?"
    get qnum1
    qnum1 := qnum1 * 20
    put "Would you like to go up left, up, up right, right, down right, down, or down left?"
    get direction3
    if direction3 = "up left" then
        qupleft
    elsif direction3 = "up" then
        qup
    elsif direction3 = "up right" then
        qupright
    elsif direction3 = "right" then
        qright
    elsif direction3 = "down right" then
        qdownright
    elsif direction3 = "down" then
        qdown
    elsif direction3 = "down left" then
        qdownleft
    elsif direction3 = "left" then
        qleft
    end if
elsif answer = 8 then
    put "Would you like to move up, down, left, right, or diagonally?"
    get answer5
    if answer5 = "up" then
        kup
    elsif answer5 = "down" then
        kdown
    elsif answer5 = "left" then
        kleft
    elsif answer5 = "right" then
        kright
    elsif answer5 = "diagonally" then
        put "Would you like to move up, or down diagonally?"
        get answer6
        if answer6 = "up" or answer6 = "down" then
            put "Would you like to move left, or right diagonally?"
            get answer7
            if answer6 = "up" and answer7 = "right" then
                kupright
            elsif answer6 = "up" and answer7 = "left" then
                kupleft
            elsif answer6 = "down" and answer7 = "right" then
                kdownright
            elsif answer6 = "down" and answer7 = "left" then
                kdownleft
            end if
        end if
    end if
else
    put "Unknown command"
end if
redraw     %draws pieces and grid again, just in case
Pic.Draw (blankz, 0, 0, picCopy)     %Clears the input area of text for about 2 seconds
delay (1000)


rand (r)     %assigns a random integer from 0 to 1 to (r). The computer will decide which piece to move based on the number's value
locate (15, 1)
put "Thinking..."
delay (1000)
Pic.Draw (blankz, 0, 0, picCopy)
if r <= 0.2 then     %For example, if the number is less than 0.2, then comp moves the far left pawn
    doublegpawnmove1
elsif r <= 0.45 and r > 0.2 then
    doublegpawnmove2
elsif r < 0.7 and r > 0.45 then
    doublegpawnmove3
elsif r >= 0.7 then         %This is for the knight move
    rand (r)     %assigns a new value to the variable (r)
    if r < 0.5 then     %50/50 chance to move up left or up right
        gdownleft
    elsif r >= 0.5 then
        gdownright
    end if
end if
redraw


%any turn after first
loop
    locate (14, 1)
    put "Which piece would you like to move?"
    locate (15, 1)
    put "1 Pawn 1"
    locate (15, 12)
    put "2 Pawn 2"
    locate (15, 18)
    put "3 Pawn 3"
    locate (16, 1)
    put "4 Knight"
    locate (16, 12)
    put "5 Rook"
    locate (16, 18)
    put "6 Bishop"
    locate (17, 1)
    put "7 Queen"
    locate (17, 12)
    put "8 King"

    get answer
    if answer = 1 then
        pawnmove
    elsif answer = 2 then
        pawnmove2
    elsif answer = 3 then
        pawnmove3
    elsif answer = 4 then
        put "Would you like to move up, left, right or down?"
        get answer2
        if answer2 = "up" or answer2 = "down" then
            put "Would you like to move right or left?"
            get answer3
            if answer2 = "up" and answer3 = "left" then
                upleft
            elsif answer2 = "up" and answer3 = "right" then
                upright
            elsif answer2 = "down" and answer3 = "left" then
                downleft
            elsif answer2 = "down" and answer3 = "right" then
                downright
            else
                locate (19, 1)
                put "Unable to move there"
            end if
        end if
        if answer2 = "left" or answer2 = "right" then
            put "Would you like to move up or down?"
            get answer3
            if answer2 = "left" and answer3 = "up" then
                leftup
            elsif answer2 = "left" and answer3 = "down" then
                leftdown
            elsif answer2 = "right" and answer3 = "up" then
                rightup
            elsif answer2 = "right" and answer3 = "down" then
                rightdown
            else
                locate (19, 1)
                put "Unable to move there"
            end if
        end if
    elsif answer = 5 then
        put "Which direction would you like to move?"
        get direction1
        if direction1 = "left" then
            put "How many spaces would you like to move?"
            get spacenum
            spacenum := spacenum * 20
            rookleftmove1
        elsif direction1 = "right" then
            put "How many spaces would you like to move?"
            get spacenum
            spacenum := spacenum * 20
            rookrightmove1
        elsif direction1 = "up" then
            put "How many spaces would you like to move?"
            get spacenum
            spacenum := spacenum * 20
            rookupmove1
        elsif direction1 = "down" then
            put "How many spaces would you like to move?"
            get spacenum
            spacenum := spacenum * 20
            rookdownmove1
        end if
    elsif answer = 6 then
        put "Would you like to go up right, up left, down right or down left?"
        get direction2
        if direction2 = "up right" then
            put "How many spaces would you like to move?"
            get bishnum1
            bishnum1 := bishnum1 * 20
            bishopupright
        elsif direction2 = "up left" then
            put "How many spaces would you like to move?"
            get bishnum1
            bishnum1 := bishnum1 * 20
            bishopupleft
        elsif direction2 = "down right" then
            put "How many spaces would you like to move?"
            get bishnum1
            bishnum1 := bishnum1 * 20
            bishopdownright
        elsif direction2 = "down left" then
            put "How many spaces would you like to move?"
            get bishnum1
            bishnum1 := bishnum1 * 20
            bishopdownleft
        else
            put "invalid direction"
        end if
    elsif answer = 7 then
        put "How many spaces would you like to move?"
        get qnum1
        qnum1 := qnum1 * 20
        put "Would you like to go up left, up, up right, right, down right, down, or down left?"
        get direction3
        if direction3 = "up left" then
            qupleft
        elsif direction3 = "up" then
            qup
        elsif direction3 = "up right" then
            qupright
        elsif direction3 = "right" then
            qright
        elsif direction3 = "down right" then
            qdownright
        elsif direction3 = "down" then
            qdown
        elsif direction3 = "down left" then
            qdownleft
        elsif direction3 = "left" then
            qleft
        end if
    elsif answer = 8 then
        put "Would you like to move up, down, left, right, or diagonally?"
        get answer5
        if answer5 = "up" then
            kup
        elsif answer5 = "down" then
            kdown
        elsif answer5 = "left" then
            kleft
        elsif answer5 = "right" then
            kright
        elsif answer5 = "diagonally" then
            put "Would you like to move up, or down diagonally?"
            get answer6
            if answer6 = "up" or answer6 = "down" then
                put "Would you like to move left, or right diagonally?"
                get answer7
                if answer6 = "up" and answer7 = "right" then
                    kupright
                elsif answer6 = "up" and answer7 = "left" then
                    kupleft
                elsif answer6 = "down" and answer7 = "right" then
                    kdownright
                elsif answer6 = "down" and answer7 = "left" then
                    kdownleft
                end if
            end if
        end if
    else
        put "Unknown command"
    end if
    redraw     %draws pieces and grid again, just in case
    Pic.Draw (blankz, 0, 0, picCopy)     %Clears the input area of text for about 2 seconds
    delay (1000)



    rand (r)     %assigns a random integer from 0 to 1 to (r). The computer will decide which piece to move based on the number's value
    locate (15, 1)
    put "Thinking..."
    delay (1000)
    Pic.Draw (blankz, 0, 0, picCopy)
    if r <= 0.2 then     %For example, if the number is less than 0.2, then comp moves the far left pawn
        gpawnmove1
    elsif r <= 0.45 and r > 0.2 then
        gpawnmove2
    elsif r < 0.7 and r > 0.45 then
        gpawnmove3
    elsif r >= 0.7 and r < 0.9 then     %This is for the knight move
        rand (r)     %assigns a new value to the variable (r)
        if r < 0.5 then
            gdownleft
        elsif r >= 0.5 then
            gdownright
        end if
    elsif r >= 0.9 then
        randint (ram1, 1, 10)
        gspacenum := ram1
        rand (r)
        if r < 0.25 then
            grookleftmove1
        elsif r > 0.25 and r <= 0.5 then
            grookupmove1
        elsif r > 0.5 and r <= 0.75 then
            grookrightmove1
        elsif r > 0.75 and r <= 1 then
            grookdownmove1
        end if
    end if

    redraw

end loop


We plan on swapping the grid with an image, and making it more larger. At this point the AI is kinda easy, easy as in not easy level on Street Fighter, but 'beat-the-car-up-bonus-stage in Street Fighter' kind of easy. So, back to my problem. I tried learning the example that came with Turing, drag the box....

code:
% The "Drag" program.
setscreen ("graphics")

procedure DrawTheBox (x, y : int)
    drawfillbox (x, y, x + 40, y + 40, 12)
    drawfilloval (x + 20, y + 20, 20, 20, 4)
    drawfillarc (x + 20, y + 20, 20, 20, 135, 225, 14)
    drawfillarc (x + 20, y + 20, 20, 20, 315, 45, 15)
end DrawTheBox

var xBox : int := 0
var yBox : int := 0
var x, y, diffX, diffY, btn, updown : int
var buf : array 1 .. sizepic (0, 0, 40, 40) of int

takepic (xBox, yBox, xBox + 40, yBox + 40, buf)

DrawTheBox (xBox, yBox)

loop
    if buttonmoved ("down") then
        buttonwait ("down", x, y, btn, updown)
        if xBox <= x and x <= xBox + 40 and yBox <= y and y <= yBox + 40 then
            % The mouse has been clicked in the box
            diffX := x - xBox
            diffY := y - yBox
            loop
                mousewhere (x, y, updown)
                exit when updown = 0
                if xBox not= x - diffX or yBox not= y - diffY then
                    drawpic (max (xBox, 0), max (yBox, 0), buf, 0)
                    xBox := x - diffX
                    yBox := y - diffY
                    takepic (max (0, xBox), max (0, yBox),
                        min (xBox + 40, maxx), min (yBox + 40, maxy), buf)
                    DrawTheBox (xBox, yBox)
                end if
            end loop
        end if
    end if
end loop


And a combo of the two (where it says pawnmove)
code:



procedure pawnmove
    for count : 1 .. 20

        Pic.Draw (boxorz1, pawnxaxis1, pawnyaxis1, picMerge)     %draws the box
        delay (50)
        Pic.Draw (blank, pawnxaxis1, pawnyaxis1, picCopy)     %draws the blank spot over the drawn box
        pawnyaxis1 := pawnyaxis1 + 1     %makes the next box 1 pixel over

    end for
    Pic.Draw (boxorz1, pawnxaxis1, pawnyaxis1, picMerge)     %draws the finished box
    drawpic (0, 195, grid, picMerge)     %redraws grid over blank spots

end pawnmove

var xb : int := 0
var yb : int := 0
var xb, yb, diffX, diffY, btn, updown : int
var buf : array 1 .. sizepic (0, 0, 40, 40) of int

takepic (xb, yb, xb + 40, yb + 40, buf)
pawnmove (xb, yb)

loop
    if buttonmoved ("down") then
        buttonwait ("down", x, y, btn, updown)
        if xb <= x and x <= xb + 40 and yb <= y and y <= yb + 40 then
            % The mouse has been clicked in the box
            diffX := x - xb
            diffY := y - yb
            loop
                mousewhere (x, y, updown)
                exit when updown = 0
                if xb not= x - diffX or yb not= y - diffY then
                    drawpic (max (x, 0), max (yBox, 0), buf, 0)
                    xb := x - diffX
                    yb := y - diffY
                    takepic (max (0, xb), max (0, b),
                        min (xb + 40, maxx), min (yb + 40, maxy), buf)
                    pawnmove (x, y)
                end if
            end loop
        end if
    end if
end loop


I don't know what I am doing wrong:?...it says things like procedure pawnmove has too many variables and the like.


So if someone could help me ASAP, that would be awesome.

Thanks

Amodeus
Sponsor
Sponsor
Sponsor
sponsor
CodeMonkey2000




PostPosted: Sat Oct 20, 2007 9:11 pm   Post subject: RE:Adding mouse to chess program, but I encounter a few problems, it says X has not been declared(before),now proedure..

Holy crap. There's no way I'm looking at the whole code. Anyway, at a quick glance, you are feeding in parameters to a procedure that doesn't take any. Either you take out the parameters when you call the procedures, or just add in parameters at the procedure definition.
rdrake




PostPosted: Sat Oct 20, 2007 9:24 pm   Post subject: Re: Adding mouse to chess program, but I encounter a few problems, it says X has not been declared(before),now proedure.

Two things I can offer.

  1. When posting code, generally we don't post more than 100 lines on the forum. Just attach the code (*.t file) with your post. Also, always remember to mention exactly where Turing tells you your error is.
  2. Instead of having abc1, abc2, abc3, etc., you should use arrays. A great tutorial on the subject can be found here.
HeavenAgain




PostPosted: Sun Oct 21, 2007 12:56 am   Post subject: RE:Adding mouse to chess program, but I encounter a few problems, it says X has not been declared(before),now proedure..

you can tell by the look of the topic, longgg stuffs Neutral scared me too
Euphoracle




PostPosted: Sun Oct 21, 2007 1:24 am   Post subject: RE:Adding mouse to chess program, but I encounter a few problems, it says X has not been declared(before),now proedure..

Just a side note, this is why I love OOP. This can be done so much simpler. A class for each piece derived from a base class, pass the movement to it, and have the class determine if it can move there. Eliminates a lot of code and static-ness.
Tony




PostPosted: Sun Oct 21, 2007 1:58 am   Post subject: RE:Adding mouse to chess program, but I encounter a few problems, it says X has not been declared(before),now proedure..

I love the AI part of the code
code:

rand (r)     %assigns a random integer from 0 to 1 to (r). The computer will decide which piece to move based on the number's value
locate (15, 1)
put "Thinking..."
delay (1000)

Very Happy

Re: problem -- it helps if you specify the exact line of code that's causing the problem, and the exact error message received.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Amodeus




PostPosted: Sun Oct 21, 2007 2:22 pm   Post subject: RE:Adding mouse to chess program, but I encounter a few problems, it says X has not been declared(before),now proedure..

As you can tell from the incredibly long code and lack of anything more advanced then the rudimentary AI code, I'm pretty much a noob when it comes to Turing. We've only been working with Turing for about 3~ weeks and even then we didn't look at much in the program.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 7 Posts ]
Jump to:   


Style:  
Search: