Einzelnen Beitrag anzeigen

Nils_13

Registriert seit: 15. Nov 2004
2.647 Beiträge
 
#5

Re: Vier Gewinnt Anfängerbeispiel

  Alt 2. Apr 2005, 09:02
Hi,

bei der procedure KI; ist es ziemlich sinnlos, andauernd
Delphi-Quellcode:
if AktuellesBrett[x+1,y]=1 and if AktuellesBrett[x+2,y]=1 and if AktuellesBrett[x+3,y]=1 then //
        begin
          AktuellesBrett[x,y]:=1;
          P:=x; ergebnisliegtvor:=True; Exit;
        end
aufzurufen.
Delphi-Quellcode:
procedure ki(x, y: Integer);
begin
  for x:=1 to breite do //Ueberpfrung, ob Computer im n�hsten Zug gewinnen kann
    for y:=1 to hoehe do //Im Folgenden werden alle m�lichen Zge des Computers und deren Nachbarn betrachtet
      if AktuellesBrett[x,y]=2 then //Gegenenfalls wird das Viererpaar vollendet und die Prozedur KI beendet
        if AktuellesBrett[x+1,y]=1 and if AktuellesBrett[x+2,y]=1 and if AktuellesBrett[x+3,y]=1 then //
        begin
          AktuellesBrett[x,y]:=1;
          P:=x; ergebnisliegtvor:=True; Exit;
        end
        else if AktuellesBrett[x-1,y]=1 and if AktuellesBrett[x-2,y]=1 and if AktuellesBrett[x-3,y]=1 then
        begin
          AktuellesBrett[x,y]:=1;
          P:=x; ergebnisliegtvor:=True; Exit;
        end
        else if AktuellesBrett[x-2,y]=1 and if AktuellesBrett[x-1,y]=1 and if AktuellesBrett[x+1,y]=1 then
        begin
          AktuellesBrett[x,y]:=1;
          P:=x; ergebnisliegtvor:=True; Exit;
        end
        else if AktuellesBrett[x-1,y]=1 and if AktuellesBrett[x+1,y]=1 and if AktuellesBrett[x+2,y]=1 then
        begin
          AktuellesBrett[x,y]:=1;
          P:=x; ergebnisliegtvor:=True; Exit;
        end
        else if AktuellesBrett[x,y+1]=1 and if AktuellesBrett[x,y+2]=1 and if AktuellesBrett[x,y+3]=1 then
        begin
          AktuellesBrett[x,y]:=1;
          P:=x; ergebnisliegtvor:=True; Exit;
        end
        else if AktuellesBrett[x,y-1]=1 and if AktuellesBrett[x,y-2]=1 and if AktuellesBrett[x,y-3]=1 then
        begin
          AktuellesBrett[x,y]:=1;
          P:=x; ergebnisliegtvor:=True; Exit;
        end
        else if AktuellesBrett[x,y+1]=1 and if AktuellesBrett[x,y+2]=1 and if AktuellesBrett[x,y-1]=1 then
        begin
          AktuellesBrett[x,y]:=1;
          P:=x; ergebnisliegtvor:=True; Exit;
        end
        else if AktuellesBrett[x,y+1]=1 and if AktuellesBrett[x,y-1]=1 and if AktuellesBrett[x,y-2]=1 then
        begin
          AktuellesBrett[x,y]:=1;
          P:=x; ergebnisliegtvor:=True; Exit;
        end
        else if AktuellesBrett[x+1,y+1]=1 and if AktuellesBrett[x+2,y+2]=1 and if AktuellesBrett[x+3,y+3]=1 then
        begin
          AktuellesBrett[x,y]:=1;
          P:=x; ergebnisliegtvor:=True; Exit;
        end
        else if AktuellesBrett[x-1,y+1]=1 and if AktuellesBrett[x-2,y+2]=1 and if AktuellesBrett[x-3,y+3]=1 then
        begin
          AktuellesBrett[x,y]:=1;
          P:=x; ergebnisliegtvor:=True; Exit;
        end
        else if AktuellesBrett[x-1,y-1]=1 and if AktuellesBrett[x-2,y-2]=1 and if AktuellesBrett[x-3,y-3]=1 then
        begin
          AktuellesBrett[x,y]:=1;
          P:=x; ergebnisliegtvor:=True; Exit;
        end
        else if AktuellesBrett[x+1,y-1]=1 and if AktuellesBrett[x+2,y-2]=1 and if AktuellesBrett[x+3,y-3]=1 then
        begin
          AktuellesBrett[x,y]:=1;
          P:=x; ergebnisliegtvor:=True; Exit;
        end
        else if AktuellesBrett[x+1,y+1]=1 and if AktuellesBrett[x+2,y+2]=1 and if AktuellesBrett[x-1,y-1]=1 then
        begin
          AktuellesBrett[x,y]:=1;
          P:=x; ergebnisliegtvor:=True; Exit;
        end
        else if AktuellesBrett[x-1,y+1]=1 and if AktuellesBrett[x-2,y+2]=1 and if AktuellesBrett[x+1,y-1]=1 then
        begin
          AktuellesBrett[x,y]:=1;
          P:=x; ergebnisliegtvor:=True; Exit;
        end
        else if AktuellesBrett[x-1,y-1]=1 and if AktuellesBrett[x-2,y-2]=1 and if AktuellesBrett[x+1,y+1]=1 then
        begin
          AktuellesBrett[x,y]:=1;
          P:=x; ergebnisliegtvor:=True; Exit;
        end
        else if AktuellesBrett[x+1,y-1]=1 and if AktuellesBrett[x+2,y-2]=1 and if
AktuellesBrett[x-1,y+1]=1 then
Lass dir da noch etwas besseres und kompakteres einfallen.

Bei der Brettnalyse ebenfalls.
  Mit Zitat antworten Zitat