Autor Beitrag
der organist
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 467
Erhaltene Danke: 17

WIN 7
NQC, Basic, Delphi 2010
BeitragVerfasst: Sa 23.04.11 08:22 
Guten Morgen Forum,

hab gestern (und heute) nen wahrscheinlich ganz besonders großen Murks fabriziert, seht selbst:

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
type

  TKaro = -1 .. 1;

  TFeld = Array [1 .. 3of Array [1 .. 3of TKaro;

  TSpiel = class
  private
    AnzahlZuge: Integer;
    FFeld : TFeld;
  public
    constructor Create;
    procedure Zug(AKaroTyp: TKaro; AFeld: TPoint);
    procedure Zeichnen(AMemo: TMemo);
    function Spielende: Boolean;
    function Gewinn: Integer;
  end;

const
  Kreuz = TKaro(-1);
  Frei = TKaro(0);
  Kreis = TKaro(1);

type
  TReihe = Array [1..3of ^TPoint;

const
  Horizontal_I : TReihe = [@TFeld[1,1],@TFeld[2,1],@TFeld[3,1]];
  Horizontal_II : TReihe = [@TFeld[1,2],@TFeld[2,2],@TFeld[3,2]];
  Horizontal_III : TReihe = [@TFeld[1,3],@TFeld[2,3],@TFeld[3,3]];
  Vertikal_I : TReihe = [@TFeld[1,1],@TFeld[1,2],@TFeld[1,3]];
  Vertikal_II : TReihe = [@TFeld[2,1],@TFeld[2,2],@TFeld[2,3]];
  Vertikal_III : TReihe = [@TFeld[3,1],@TFeld[3,1],@TFeld[3,3]];
  Diagonal_I : TReihe = [@TFeld[1,1],@TFeld[2,2],@TFeld[3,3]];
  Diagonal_II : TReihe = [@TFeld[1,3],@TFeld[2,2],@TFeld[3,1]];
  Reihe : Array [1..8of TReihe = [Horizontal_I,Horizontal_II,Horizontal_III,
                                   Vertikal_I,Vertikal_II,Vertikal_II,
                                   Diagonal_I,Diagonal_II];


Sinn der Sache ist es ein TicTacToe-Spiel zu schreiben. Das klappt auch bis zu der Sache mit den Reihen (markiert bis Ende).
Ich bekomme den Fehler (erst beim Compilieren): "(" erwartet, aber "[" gefunden, dabei geht es um die oben markierte Klammer.
Wenn nötig, erkläre ich meinen Code weiter, vielleicht ist es ja aber auch nur ein kleiner Syntaxfehler (Bitte Bitte Bitte).

Gruss,

_________________
»Gedanken sind mächtiger als Waffen. Wir erlauben es unseren Bürgern nicht, Waffen zu führen - warum sollten wir es ihnen erlauben, selbständig zu denken?« Josef Stalin
bummi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1248
Erhaltene Danke: 187

XP - Server 2008R2
D2 - Delphi XE
BeitragVerfasst: Sa 23.04.11 09:05 
ich vermute Du suchst so was (mit @ in Consts wird nicht funktionieren)
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
type
  TReihe = Array [1..3of TPoint;

const
  Horizontal_I : TReihe = ((x:1;y:1),(x:2;y:1),(x:3;y:1));
  Horizontal_II : TReihe = ((x:1;y:2),(x:2;y:2),(x:3;y:2));
  Horizontal_III : TReihe = ((x:1;y:3),(x:2;y:3),(x:3;y:3));
  Vertikal_I : TReihe = ((x:1;y:1),(x:1;y:2),(x:1;y:3));
  Vertikal_II : TReihe = ((x:2;y:1),(x:2;y:2),(x:2;y:3));
  Vertikal_III : TReihe = ((x:3;y:1),(x:3;y:2),(x:3;y:3));
  Diagonal_I : TReihe = ((x:1;y:1),(x:2;y:2),(x:3;y:3));
  Diagonal_II : TReihe = ((x:1;y:3),(x:2;y:2),(x:3;y:1));


  Reihe : Array [1..8of TReihe = (
                                    ((x:1;y:1),(x:2;y:1),(x:3;y:1)),
                                    ((x:1;y:2),(x:2;y:2),(x:3;y:2)),
                                    ((x:1;y:3),(x:2;y:3),(x:3;y:3)),
                                    ((x:1;y:1),(x:1;y:2),(x:1;y:3)),
                                    ((x:2;y:1),(x:2;y:2),(x:2;y:3)),
                                    ((x:3;y:1),(x:3;y:2),(x:3;y:3)),
                                    ((x:1;y:1),(x:2;y:2),(x:3;y:3)),
                                    ((x:1;y:3),(x:2;y:2),(x:3;y:1))
                                    ) ;

_________________
Das Problem liegt üblicherweise zwischen den Ohren H₂♂
DRY DRY KISS
Hidden
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 2242
Erhaltene Danke: 55

Win10
VS Code, Delphi 2010 Prof.
BeitragVerfasst: Sa 23.04.11 09:26 
Moin Lukas,

Da steht, du willst auf die Speicheradresse des Datentyps TFeld zugreifen? :) (@TFeld[1,1]).

Statt TPoint würde ich einen Index-Datentyp deklarieren, das ist dann dein 1..3. Dann ist immer schonmal klar, was da reinkommt.
Programmieren ist so ein bisschen wie Physik: Mit Einheiten, das heißt genau passenden Datentypen, ist es ein bisschen besser lesbar und weniger fehleranfällig.

Du musst dein Array dann zur Laufzeit füllen, damit klappt alles wunderbar.

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
const
  FeldGroesse = 3;
  MaxH = Feldgroesse-1;
  MaxV = MaxH;  //Lässt sich später leicht erweitern
  MaxReihen = (MaxH+1) + (MaxV+1) + 2*(Abs(MaxH-MaxV)+1) - 1;

type
  TEintrag = (Kreuz, Frei, Kreis);
  PEintrag = ^TEintrag;

  HIndex = 0..MaxH;
  VIndex = HIndex;
  TSpalte = Array [VIndex] of TEintrag;
  TFeld = Array [HIndex] of TSpalte;

  TReihe = Array [HIndex] of PEintrag;  //Für Höhe <> Breite wird's komplizierter..
  TReihen = Array[0..MaxReihen] of TReihe;

  TSpiel = class
  private
    FFeld : TFeld;
    FReihen: TReihen;
  public
    procedure Neu;  //Startet neues Spiel, initialisiert Spielbrett
  end;

implementation

procedure TSpiel.Neu;
var
  h: HIndex;
  v: VIndex;
begin
  {..}
  for h := 0 to MaxH do begin
    for v := 0 to MaxV do begin
      FFeld[h,v] := Frei;
      FReihen[Ord(h),v] := @(FFeld[h,v]);  //Zeilen
      FReihen[MaxH+1 + Ord(v), h] := @(FFeld[h,v]);  //Spalten
    end;
  end;
  //Die Diagonalen einzutragen, fehlt noch, die überlasse ich mal dir :)
  {..} 
end;

_________________
Centaur spears can block many spells, but no one tries to block if they see that the spell is a certain shade of green. For this purpose it is useful to know some green stunning hexes. (HPMoR)
der organist Threadstarter
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 467
Erhaltene Danke: 17

WIN 7
NQC, Basic, Delphi 2010
BeitragVerfasst: Sa 23.04.11 19:07 
hei bummi,

ich vermute, dass das genau das ist, was ich suche. Nur eine Frage habe ich dazu noch: Kann ich nachher im Array nicht auch die vorher definierten Reihen benutzen, anstatt wieder alle Koordinaten aufzuschreiben?

Gruss,

_________________
»Gedanken sind mächtiger als Waffen. Wir erlauben es unseren Bürgern nicht, Waffen zu führen - warum sollten wir es ihnen erlauben, selbständig zu denken?« Josef Stalin
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19340
Erhaltene Danke: 1752

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Sa 23.04.11 19:18 
Natürlich geht das:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
type
  TReihe = Array [1 .. 3of TPoint;
  PReihe = ^TReihe;

const
  Horizontal_I: TReihe = ((x: 1; y: 1), (x: 2; y: 1), (x: 3; y: 1));
  Horizontal_II: TReihe = ((x: 1; y: 2), (x: 2; y: 2), (x: 3; y: 2));
  Horizontal_III: TReihe = ((x: 1; y: 3), (x: 2; y: 3), (x: 3; y: 3));
  Vertikal_I: TReihe = ((x: 1; y: 1), (x: 1; y: 2), (x: 1; y: 3));
  Vertikal_II: TReihe = ((x: 2; y: 1), (x: 2; y: 2), (x: 2; y: 3));
  Vertikal_III: TReihe = ((x: 3; y: 1), (x: 3; y: 2), (x: 3; y: 3));
  Diagonal_I: TReihe = ((x: 1; y: 1), (x: 2; y: 2), (x: 3; y: 3));
  Diagonal_II: TReihe = ((x: 1; y: 3), (x: 2; y: 2), (x: 3; y: 1));

  Reihe: Array [1 .. 8of PReihe = (@Horizontal_I, @Horizontal_II, @Horizontal_III,
    @Vertikal_I, @Vertikal_II, @Vertikal_III, @Diagonal_I, @Diagonal_II);
der organist Threadstarter
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 467
Erhaltene Danke: 17

WIN 7
NQC, Basic, Delphi 2010
BeitragVerfasst: So 24.04.11 11:48 
Dachte mir schon. Danke an alle. Wenn das jetzt auch noch klappt ;)

Frohe Ostern,

_________________
»Gedanken sind mächtiger als Waffen. Wir erlauben es unseren Bürgern nicht, Waffen zu führen - warum sollten wir es ihnen erlauben, selbständig zu denken?« Josef Stalin