israphelr@[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
> SysUtils;
>
> TYPE
> Tboard = ARRAY[65..71,49..55] OF STRING;
What is that?
The board has 7 cols and 6 rows. So the easiest way is
TBoard = 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 = (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 = class
private
fBoard: Array...
...
public
procedure Draw;
function getCell(x,y: Integer): TField;
function canPut(ACol: Integer): Boolean;
procedure Put(Acol: Integer);
constructor Create(who: TWhoStarts);
...
end
Wolf


|