Forums before death by AOL, social media and spammers... "We can't have nice things"
|    comp.lang.pascal.borland    |    Borland Pascal was actually pretty neat    |    2,978 messages    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
|    Message 2,611 of 2,978    |
|    Wolf Behrenhoff to israphelr@googlemail.com    |
|    Re: Connect Four game - 2D Array problem    |
|    19 Jan 08 16:51:40    |
   
   a37aa840   
   From: NoSpamPleaseButThisIsValid3@gmx.net   
      
   israphelr@googlemail.com 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   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca