AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Sieger-Prüfung "Vier gewinnt"

Ein Thema von Luckie · begonnen am 28. Jun 2004 · letzter Beitrag vom 30. Jun 2004
 
Benutzerbild von glkgereon
glkgereon

Registriert seit: 16. Mär 2004
2.287 Beiträge
 
#25

Re: Sieger-Prüfung "Vier gewinnt"

  Alt 29. Jun 2004, 13:12
boah nee sind die codes lang, machts doch so:

Delphi-Quellcode:
function check4gewinnt(x, y{, spieler}:Byte):boolean //Koordinaten
var
i, j, anzahl:Byte;
gewonnen:boolean;

begin
//reihen
i:=x-4;
anzahl:=0;
while (i<x+5) and (anzahl<4) do begin
   anzahl:=anzahl+1;
   i:=i+1;
   if feld[i,y]<>feld[x,y] then anzahl:=0;
   end;
if anzahl=4 then gewonnen:=true

//spalten
i:=y-4;
anzahl:=0;
while (i<y+5) and (anzahl<4) do begin
   anzahl:=anzahl+1;
   i:=i+1;
   if feld[x,i]<>feld[x,y] then anzahl:=0;
   end;
if anzahl=4 then gewonnen:=true


//diagonalen
i:=x-4; j:=y-4;
anzahl:=0;
while (i<x+5) and (j<y+5) and (anzahl<4) do begin
   anzahl1:=anzahl1+1;
   i:=i+1;
   j:=j+1;
   if feld[i,j]<>feld[x,y] then anzahl:=0;
   end;
if anzahl=4 then gewonnen:=true;

i:=x-4; j:=y+4;
anzahl:=0;
while (i<x+5) and (j<y+5) and (anzahl<4) do begin
   anzahl1:=anzahl1+1;
   i:=i+1;
   j:=j-1;
   if feld[i,j]<>feld[x,y] then anzahl:=0;
   end;
if anzahl=4 then gewonnen:=true;

return:=gewonnen;
end;
das is doch wesentlich kürzer, oder???

und es müsste funzen...

also feld ist das feld halt
zweidimensionales array, das mit bytes gefüllt ist...
x und y sind die "koordinaten" des aktuell gesetzten feldes...
mir fällt grad ma so auf dasses so viel kürzer gar nit ist, oder?
und die variable spieler brauch ich gar nit...
»Unlösbare Probleme sind in der Regel schwierig...«
  Mit Zitat antworten Zitat
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 23:39 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz