
-----------------------------------
customae7
Fri Mar 23, 2007 11:54 am

Connect 4 errors but if someone can look at it and let me know whats wrong!
-----------------------------------
Just copy and paste the game into turing to run it you may have some errors let me know if you can fix them!

Freakman Edit: Please use 


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                     CONNECT 4                                     %
%                                      ICS 4M                                       %
%                                    March  2007                                    %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

setscreen ("graphics:max;max")                  %setscreen to full size
setscreen ("offscreenonly")                     %allows smooth animation
setscreen ("nocursor")                          %hides cursor


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                DECLARATION OF CONSTANTS, VARIABLES, AND TYPES                     %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
const radius : int := 25
const player1 : int := red
const player2 : int := black
const none : int := white
const space : int := 10

type boardCell :
    record
        x : int                                 %x coordinate of cell
        y : int                                 %y coordinate of cell
        owner : int                             %colour of cell
    end record



var board : array 1 .. 7, 1 .. 6 of boardCell   %sets the size of board


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                          PROCEDURES AND FUNCTIONS                                 %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

procedure introScreen ()
    %precondition:  none
    %postcondition: intro screen is displayed







end introScreen

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

procedure rules ()
    %precondition:  none
    %postcondition: rules have been displayed








end rules

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
procedure initBoard (var board : array 1 .. 7, 1 .. 6 of boardCell)
    %precondition:  board has been declared
    %postcondition: sets postion of cells and starts them all empty

    for i : 1 .. 7
        for j : 1 .. 6
            %the next two lines set the locations of the cells
            board (i, j).x := 185 + (i * (2 * radius + space)) - radius
            board (i, j).y := 115 + (j * (2 * radius + space)) - radius
            board (i, j).owner := none          %sets cells to empty
        end for
    end for

end initBoard

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

procedure drawBoard (board : array 1 .. 7, 1 .. 6 of boardCell)
    %precondtion:   initBoard had been called
    %postcondtion:  board has been displayed on output screen

    drawbox (185, 115, 615, 485, yellow)        %main part of board

    for i : 1 .. 7
        for j : 1 .. 6
            %Outline cells
            drawoval (board (i, j).x, board (i, j).y, radius, radius, yellow)
        end for

        locatexy (board (i, 1).x, 100)          %displays column numbers below board
        put i
    end for


    drawfill (190, 120, yellow, yellow)         %Fills in board yellow
    drawfillbox (185, 50, 175, 485, blue)       %left leg of board
    drawfillbox (615, 50, 625, 485, blue)       %right leg of board
    drawfillbox (185, 120, 625, 110, blue)      %bottom stopper of board
    View.Update

end drawBoard

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

procedure drawChip (x, y, owner : int)
    %precondtion:   dropchip has been called
    %postcondition: draws chip at location (x,y)

    drawfilloval (x, y, radius, radius, owner)

end drawChip

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function findHeight (column : int) : int
    %precondition:  board has been initialized, and row has been entered
    %postcondition: determines which row chip must fall to

    var cellheight : int

    for decreasing j : 6 .. 1

        %Find which row the chip needs to fall to

    end for
    result cellheight
end findHeight

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

procedure drawPreviousChips ()
    %precondition:  board has been initialized
    %postcondition: draws previously played chips
    for i : 1 .. 7
        for j : 1 .. 6
            %only draw cells that have chip in them (reduces flashing)

            %use an if statement to see what chips must be drawn

        end for
    end for
    View.Update

end drawPreviousChips

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

procedure dropChip (column, owner : int)
    %precondition:  isEmpty has been called
    %postcondition: animates chip falling down board
    var columnX : int

    columnX := board (column, 1).x              %determines x-coordinate of chip

    %animates chip dropping
    for decreasing y : 500 .. findHeight (column) by 2
        cls

        drawChip (columnX, y, owner)

        drawBoard (board)
        drawPreviousChips ()


        View.Update
    end for

    board (column, row).owner := owner

end dropChip

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function isWinner (board : array 1 .. 7, 1 .. 6 of boardCell) : boolean
    %precondition:  board has been initialized
    %postcondition: determines if there is a winner

    %  Determines if there is a Horizontal winner


    %  Determines if there is a Vertical winner

    %  Determines if there is a Diagonal (up to the right) winner


    %  Determines if there is a Diagonal (up to the left) winner


    %no winner
    result false

end isWinner

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function isEmpty (row : int) : boolean
    %precondition:  board has been initialized, and user has entered column
    %postcondition: returns true if chip can be played in that row

    if board (row, 6).owner = none then         %if top cell is open, chip can be played
        result true
    else
        result false                            %Column is full
    end if

end isEmpty


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                   MAIN PROGRAM                                    %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

var cellheight : int                            %height chip drops to
var turn : int := 0                             %keeps track of who's turn it is
var owner : int := 0                            %whose chip is being played (colour)
var ownerString : string                        %whose chip is being played (word)
var count : int                                 %number of chips played
var font1 : int := Font.New ("sans serif:36:bold")
var tempstr : string

introScreen ()
rules ()

%allows to play more than once
loop
    size1 := 210
    size2 := 210
    count := 0
    initBoard (board)                           %Initialize board
    drawBoard (board)                           %draws board
    %drawStacks (size1, size2)

    %loops single game
    loop

        if turn mod 2 = 0 then                  %Determines who turn it is
            owner := player1                    %sets colour of chip
            ownerString := "Player 1"           %sets name of current player
        else
            owner := player2                    %sets colour of chip
            ownerString := "Player 2"           %sets name of current player
        end if

        getch (input)                           %getch() do not need to hit enter
        if input = "q" or input = "Q" then      %allows players to quit game
            cls
            exit
        end if
        row := strint (input)                   %change input to an integer value


        if row >= 1 and row 