Talk About Network

Google


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 > Re: Connect Fou...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 3 of 9 Topic 1081 of 1118
Post > Topic >>

Re: Connect Four game - 2D Array problem?

by "israphelr@[EMAIL PROTECTED] " <israphelr@[EMAIL PROTECTED] > Jan 19, 2008 at 02:44 PM

On Jan 19, 7:51=A0am, Wolf Behrenhoff
<NoSpamPleaseButThisIsVal...@[EMAIL PROTECTED]
> wrote:
> israph...@[EMAIL PROTECTED]
 schrieb:
>
> > 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.
>
> The user only needs to enter a column!
>
>
>
> > PROGRAM ConnectFour;
>
> > {$APPTYPE CONSOLE}
>
> > uses
> > =A0 SysUtils;
>
> > TYPE
> > =A0 Tboard =3D ARRAY[65..71,49..55] OF STRING;
>
> What is that?
>
> The board has 7 cols and 6 rows. So the easiest way is
> TBoard =3D Array[0..6, 0..5] of Whatever;
>
> Why an array of string? Better define a type of what can be at that
> position. For example
> type TField =3D (empty, red, yellow);
>
> There is no need to store something that you already know! You know that
> the file in the lower left corner is A1, so why store that?
>
> You should NOT define internal structures (like the TBoard) based on a
> representation the user sees. Rather define it so that they match the
> problem.
>
> And more, you should put functions/procedures and the internal board
> representation together in a class.
>
> What compiler are you using? (I'm asking because of the $APPTYPE)
>
> You could do (in Delphi, FPC)
> type TBoard =3D class
> =A0 private
> =A0 =A0 fBoard: Array...
>
> =A0 =A0 ...
> =A0 public
> =A0 =A0 procedure Draw;
> =A0 =A0 function getCell(x,y: Integer): TField;
> =A0 =A0 function canPut(ACol: Integer): Boolean;
> =A0 =A0 procedure Put(Acol: Integer);
> =A0 =A0 constructor Create(who: TWhoStarts);
> =A0 =A0 ...
> =A0 end
>
> Wolf

Thanks for the reply and the help.

I am using Borland Delphi 7

I am Not sure about cl*****. (Am new to programming)



I'm a little confused here with some things. I am new to this thank
for your patience.

> There is no need to store something that you already know! You know that
> the file in the lower left corner is A1, so why store that?
>
> You should NOT define internal structures (like the TBoard) based on a
> representation the user sees. Rather define it so that they match the
> problem.

=46rom this I am stuck as to how I can represent each square to the
user. Do you actually mean instead of having the cells showing 'A1'
just maybe something like this..
   _ _ _
A |_|_|_|
B |_|_|_|
C |_|_|_|
D |_|_|_|

   1 2 3

Displayed? (In order to obtain player input).
 




 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 Fri Jul 25 0:16:20 CDT 2008.