Talk About Network



Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Pascal Borland > Connect Four ga...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 9 Topic 1081 of 1102
Post > Topic >>

Connect Four game - 2D Array problem?

by "israphelr@[EMAIL PROTECTED] " <israphelr@[EMAIL PROTECTED] > Jan 18, 2008 at 05:25 PM

Hi all.

I have been writing a connect four game.

So far I have defined the board using a 2D Array.

Because I have no graphical programming experience, this is being done
in the console application.

My board is displayed and in each cell appears notation which
represents that cell. The user chooses for e.g. 'A1'. So the counter
appears in this cell. That's how I want it to go, I've tried
implementing it using a search algorithm, but something is up and I'm
sturuggling with this, help would be very appreciated, many thanks.

PROGRAM ConnectFour;

{$APPTYPE CONSOLE}

uses
  SysUtils;

TYPE
  Tboard = ARRAY[65..71,49..55] OF STRING;


{*************************************************
**********************
Creates the Connect four board
**************************************************
**********************}
PROCEDURE makeBoard(VAR board : Tboard);

VAR
  x, y : integer;
  m, n : STRING;

BEGIN
  FOR x:= 65 TO 71 DO
  BEGIN
  m := chr(x);
    FOR y := 49 TO 55 DO
    BEGIN
      n := chr(y);
      board[X,Y] := m + n;
    END;
  END;
END;



{*************************************************
***********************
Accesses the board and displays it.
**************************************************
***********************}
PROCEDURE displayBoard(board : Tboard);

VAR
  X, Y : INTEGER;

BEGIN
  writeln('
----------------------------------------------------------------');
  FOR x:= 65 TO 71 DO
  BEGIN
    FOR y := 49 TO 55 DO
    BEGIN
      write('   |');
      write('   ',board[X,Y]);
    END;
    write('   |');
    writeln;
    writeln('   ==================================================
==============');
  END;
END;

PROCEDURE placeCounter(cell : STRING; var board : Tboard);

VAR
  x, y : integer;

BEGIN
  FOR x:= 65 TO 71 DO
    FOR y:= 49 TO 55 DO
      IF (board[x,y] = 'A1') THEN
        board[x,y] := '#'
END;


PROCEDURE chooseCell(board : Tboard);

VAR
  cell : STRING;

BEGIN
  writeln;
  writeln('Choose a cell you would like to drop a counter in.(e.g.
''B3'') : ');
  readln(cell);
END;


{*************************************************
****************
Puts all of the procedures uses in the game together, The loop
controll will also be administered in here(overall game control).
**************************************************
*****************}
PROCEDURE newGame();

VAR
  board : Tboard;
  won : boolean;

BEGIN
  won := false;


  makeboard(board);
  repeat
  displayboard(board);
  chooseCell(board);
  until (won = true);

END;


PLEASE NOTE HERE : I have attempted to replace 'A1' string with '#' to
represent the cell. Ultimately this is not how the program will work,
but at the moment my primary concern is getting this search and
replace procedure working.




 9 Posts in Topic:
Connect Four game - 2D Array problem?
"israphelr@[EMAIL PR  2008-01-18 17:25:06 
Re: Connect Four game - 2D Array problem?
Wolf Behrenhoff <NoSpa  2008-01-19 16:51:40 
Re: Connect Four game - 2D Array problem?
"israphelr@[EMAIL PR  2008-01-19 14:44:11 
Re: Connect Four game - 2D Array problem?
"israphelr@[EMAIL PR  2008-01-19 14:49:36 
Re: Connect Four game - 2D Array problem?
Dr J R Stockton <jrs@[  2008-01-19 22:49:41 
Re: Connect Four game - 2D Array problem?
"israphelr@[EMAIL PR  2008-01-19 16:48:09 
Re: Connect Four game - 2D Array problem?
Dr J R Stockton <jrs@[  2008-01-20 18:44:31 
Re: Connect Four game - 2D Array problem?
"israphelr@[EMAIL PR  2008-01-20 13:55:05 
Re: Connect Four game - 2D Array problem?
Dr J R Stockton <jrs@[  2008-01-20 21:04:39 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Wed May 14 6:01:57 CDT 2008.