Autor Beitrag
guerkchen
Hält's aus hier
Beiträge: 13



BeitragVerfasst: Do 04.05.06 16:01 
hallo!

ich muss in der schule für info irgendein programm schreiben (als projekt)
da ich nicht viel ahnung von dephi habe (...) hab ich mir hier im forum ein sudoku lösungsprogramm runtergeladen - wollte mir das eigentlich angucken & verstehen - aber schon am anfang seh ich überhaupt nicht durch,...
HILFE!!

wie bekommt man es hin, dass bei einem stringgrid die trennlinien zwischen den zellen verschieden dick werden?

was muss man machen, damit der nutzer in eine zelle nur eine zahl eingeben kann (ich bin gerade soweit, dass man irgendwas hineinschreiben kann,...)

DANKE

EDIT:
auf den rat von jasocul hin suche ich nun ein tic tac toe programm - am donnerstag muss ich info irgendetwas machen - also müsste ich mich morgen schon damit beschäftigen können

bitte bitte helfen!!
danke


Zuletzt bearbeitet von guerkchen am Di 09.05.06 15:52, insgesamt 1-mal bearbeitet
MrFox
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 208

WIN 2000 Professional, Ubuntu 5.10
D3 Prof, D7 Pers, D2005 Pers, Java (Eclipse)
BeitragVerfasst: Do 04.05.06 17:06 
Das mit den dicken Linien lässt sich lösen, indem man im OnPaint-Ereignis des Grids die Linien per Canvas zeichnet.

Die Lösung des Sudokus würde ich mit Backtracking angehen, das lässt sich mit einer rekursiven Funktion elegant formulieren.

_________________
Das Leben auf der Erde mag zwar teuer sein, aber eine jährliche Rundreise um die Sonne ist gratis mit dabei.
Magic J
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 66

WinXP Prof., Vista
Delphi6, Delphi 2009, Java(Eclipse), C++, Basic
BeitragVerfasst: Do 04.05.06 17:50 
Hi,

ich habe da mal vor längerer Zeit auch nen Sudoku-Teil programmiert.

des ist mit Edits als Eingabefeld...

...kannstes ja mal anschauen!

Viel Spaß!
Einloggen, um Attachments anzusehen!
Jetstream
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 222



BeitragVerfasst: Fr 05.05.06 19:40 
hab auch eins für dich.
selbst gemacht natürlich.

www.flechtmann.net/SudokuSolv.exe
guerkchen Threadstarter
Hält's aus hier
Beiträge: 13



BeitragVerfasst: So 07.05.06 11:12 
danke :)

aber ich muss das program auch selbst schreiben & verstehen können - muss nämlich ne dokumenrtation über die entstehung schreiben ... *jammer*
guerkchen Threadstarter
Hält's aus hier
Beiträge: 13



BeitragVerfasst: Mo 08.05.06 15:36 
ähm - ich kann gar kein onpaint ereignis finden,...

EDIT:
das programm, dass ich - ohne jeglichen plan - versuche nachzubasteln -.-
www.delphi-forum.de/....php?p=291436#291436


Zuletzt bearbeitet von guerkchen am Mo 08.05.06 15:43, insgesamt 1-mal bearbeitet
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Mo 08.05.06 15:40 
Guerkchen, ich will dir nicht zu nahe treten, aber deine Fragen und Probleme deuten auf fehlendes Grundwissen hin. Da ist eine Sudoku-Programm vielleicht ein paar Nummer zu groß.
guerkchen Threadstarter
Hält's aus hier
Beiträge: 13



BeitragVerfasst: Mo 08.05.06 15:45 
ich weis - das stell ich auch fest - aber jetzt ist das zu spät -.-
ich mein - ich würd mich ja nicht gerade als dumm bezeichnen - ich hab nur keine ahnung von delphi -.-
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Mo 08.05.06 16:10 
Mit Dummheit hat das nichts zu tun.
Als Alternative wäre vielleicht ein Tic-Tac-Toe-Programm eine Möglichkeit. Ist erheblich einfacher. Im Internet sollte es dazu genügend Beispiele geben. Vermutlich haben auch schon einige im Forum eine brauchbare Lösung parat.
guerkchen Threadstarter
Hält's aus hier
Beiträge: 13



BeitragVerfasst: Mo 08.05.06 18:00 
ich weis nur nicht, ob ich nochmal neu anfangen kann & mein thema ändern, aber ich werde mal schauen
guerkchen Threadstarter
Hält's aus hier
Beiträge: 13



BeitragVerfasst: Mi 10.05.06 17:34 
ich hab jetzt stundenlang nach so einem progam gesucht & die meisten dowloads funktionieren nicht,...
ich bräuchte blos ein einfaches program - also wo zwei spieler gegeneinander spielen & nicht gegen den computer

bitte verratet mir, wie ich das am besten löse - ich hab hier im forum zwar schon viel gelesen, aber alles so spezialisiert,...

was sollte ich am besten als "grundgerüst" nehmen - also wo kreuz und kreis dann hereingesetzt werden?

sollte man nur die Buschstaben X und O nehmen, oder Bilder?!
HIIIIIIILFE,...
Marco D.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Mi 10.05.06 17:41 
Du nimmst einfach 9 Images (3*3) und in der OnClick-Procedure lädst du Bilder rein oder mals t mit canvas.textout eben ein X oder O.

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Mi 10.05.06 17:51 
Ich habe hier im Forum im zweiten Anlauf folgendes gefunden:
www.delphi-forum.de/...;highlight=tictactoe
Das sollte für den Anfang genügen. Ich habe den Source natürlich nicht geprüft.
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: Mi 10.05.06 18:02 
Oder 9 Panels, dann kannste Panel1.Caption benutzen ;-).

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)
guerkchen Threadstarter
Hält's aus hier
Beiträge: 13



BeitragVerfasst: Do 11.05.06 15:37 
danke ^^

ich hab mich jetz mal dran gemacht, ein eigenes progamm zu schreiben - da kommt folgender fehler:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
procedure TForm2.l0Click(Sender: TObject);
var O:char;
    X:char;
begin
X:='X';
O:='O';
if l0.caption:=' ' then
begin
l0.caption:=X;
lanweis.Caption:='Kreis ist an der Reihe!'
end;
end;


AUSDRUCKSTYP MUSS BOOLEAN SEIN

- ich hab keine ahnung, was daran falsch ist,...

Moderiert von user profile iconraziel: I- durch Delphi-Tags ersetzt
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Do 11.05.06 15:49 
ausblenden Delphi-Quelltext
1:
if l0.caption:=' ' then					

geht nicht. := ist eine Zuweisung. Ein Vergleich sieht so aus:
ausblenden Delphi-Quelltext
1:
if l0.caption=' ' then					

Also ohne Doppelpunkt
azubi_20
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 593

WinXP SP2, Ubuntu 8.4
D7 Enterp., D2005 Prof., Java (Eclipse 3.4.0)
BeitragVerfasst: Do 11.05.06 15:50 
Bei Vergleichen musst du = schreiben
:= ist nur bei Zuweisungen
also :
ausblenden Delphi-Quelltext
1:
if l0.caption =' ' then					


Edit : da war jemand schneller ^^ 8)
guerkchen Threadstarter
Hält's aus hier
Beiträge: 13



BeitragVerfasst: Do 11.05.06 17:33 
ah - danke (*schäm*)

jetzt hab ich aber schon ein neues problem:

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:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216:
217:
218:
219:
220:
221:
222:
223:
224:
225:
226:
227:
228:
229:
230:
231:
232:
233:
234:
235:
236:
237:
238:
239:
240:
241:
242:
243:
244:
245:
246:
247:
248:
249:
250:
251:
252:
253:
254:
255:
256:
257:
258:
259:
260:
261:
262:
263:
264:
265:
266:
267:
268:
269:
270:
271:
272:
273:
274:
275:
276:
277:
278:
279:
280:
281:
282:
283:
284:
285:
286:
287:
288:
289:
290:
291:
292:
293:
294:
295:
296:
297:
298:
299:
300:
301:
302:
303:
304:
305:
306:
307:
308:
309:
310:
311:
312:
313:
314:
315:
316:
317:
318:
319:
320:
321:
322:
323:
324:
325:
326:
327:
328:
329:
330:
331:
332:
333:
334:
335:
336:
337:
338:
339:
340:
341:
342:
343:
344:
345:
346:
347:
348:
349:
350:
351:
352:
353:
354:
355:
356:
357:
358:
359:
360:
361:
362:
363:
364:
365:
366:
367:
368:
369:
370:
371:
372:
373:
374:
375:
376:
377:
378:
379:
380:
381:
382:
383:
384:
385:
386:
387:
388:
389:
390:
391:
392:
393:
394:
395:
396:
397:
398:
399:
unit uprojekt2;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Grids, StdCtrls, jpeg, ExtCtrls;

type
  TForm2 = class(TForm)
    luebers: TLabel;
    bclose: TButton;
    breset: TButton;
    iraster: TImage;
    lanweis: TLabel;
    l0: TLabel;
    l1: TLabel;
    l2: TLabel;
    l3: TLabel;
    l4: TLabel;
    l5: TLabel;
    l6: TLabel;
    l7: TLabel;
    l8: TLabel;
    procedure bcloseClick(Sender: TObject);
    procedure bresetClick(Sender: TObject);
    procedure l0Click(Sender: TObject);
    procedure l1Click(Sender: TObject);
    procedure l2Click(Sender: TObject);
    procedure l3Click(Sender: TObject);
    procedure l4Click(Sender: TObject);
    procedure l5Click(Sender: TObject);
    procedure l6Click(Sender: TObject);
    procedure l7Click(Sender: TObject);
    procedure l8Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form2: TForm2;

implementation

{$R *.dfm}

procedure TForm2.bcloseClick(Sender: TObject);
begin
  form2.close;
end;

procedure TForm2.bresetClick(Sender: TObject);
begin
l0.caption:=' ';
l1.caption:=' ';
l2.caption:=' ';
l3.caption:=' ';
l4.caption:=' ';
l5.caption:=' ';
l6.caption:=' ';
l7.caption:=' ';
l8.caption:=' ';
lanweis.caption:='Kreis ist an der Reihe!';
end;

procedure TForm2.l0Click(Sender: TObject);
var O:char;
    X:char;
    AO:string;
    AX:string;
begin
X:='X';
O:='O';
AO:='Kreis ist an der Reihe!';
AX:='Kreuz ist an der Reihe!';

if lanweis.caption=AO then
begin
  if l0.caption=X then
    lanweis.Caption:='FEHLER!';
  if l0.caption=O then
    lanweis.Caption:='FEHLER!';
  if l0.caption=' ' then
    begin
    l0.caption:=O;
    lanweis.Caption:=AX
    end
else
begin
  if l0.caption=X then
    lanweis.Caption:='FEHLER!';
  if l0.caption=O then
    lanweis.Caption:='FEHLER!';
  if l0.caption=' ' then
    begin
    l0.caption:=X;
    lanweis.Caption:=AO
    end;
end;
end;
end;

procedure TForm2.l1Click(Sender: TObject);
var O:char;
    X:char;
    AO:string;
    AX:string;
begin
X:='X';
O:='O';
AO:='Kreis ist an der Reihe!';
AX:='Kreuz ist an der Reihe!';

if lanweis.caption=AO then
begin
  if l1.caption=X then
    lanweis.Caption:='FEHLER!';
  if l1.caption=O then
    lanweis.Caption:='FEHLER!';
  if l1.caption=' ' then
    begin
    l1.caption:=O;
    lanweis.Caption:=AX
    end
else
begin
  if l1.caption=X then
    lanweis.Caption:='FEHLER!';
  if l1.caption=O then
    lanweis.Caption:='FEHLER!';
  if l1.caption=' ' then
    begin
    l1.caption:=X;
    lanweis.Caption:=AO
    end;
end;
end;
end;

procedure TForm2.l2Click(Sender: TObject);
var O:char;
    X:char;
    AO:string;
    AX:string;
begin
X:='X';
O:='O';
AO:='Kreis ist an der Reihe!';
AX:='Kreuz ist an der Reihe!';

if lanweis.caption=AO then
begin
  if l2.caption=X then
    lanweis.Caption:='FEHLER!';
  if l2.caption=O then
    lanweis.Caption:='FEHLER!';
  if l2.caption=' ' then
    begin
    l2.caption:=O;
    lanweis.Caption:=AX
    end
else
begin
  if l2.caption=X then
    lanweis.Caption:='FEHLER!';
  if l2.caption=O then
    lanweis.Caption:='FEHLER!';
  if l2.caption=' ' then
    begin
    l2.caption:=X;
    lanweis.Caption:=AO
    end;
end;
end;
end;

procedure TForm2.l3Click(Sender: TObject);
var O:char;
    X:char;
    AO:string;
    AX:string;
begin
X:='X';
O:='O';
AO:='Kreis ist an der Reihe!';
AX:='Kreuz ist an der Reihe!';

if lanweis.caption=AO then
begin
  if l3.caption=X then
    lanweis.Caption:='FEHLER!';
  if l3.caption=O then
    lanweis.Caption:='FEHLER!';
  if l3.caption=' ' then
    begin
    l3.caption:=O;
    lanweis.Caption:=AX
    end
else
begin
  if l3.caption=X then
    lanweis.Caption:='FEHLER!';
  if l3.caption=O then
    lanweis.Caption:='FEHLER!';
  if l3.caption=' ' then
    begin
    l3.caption:=X;
    lanweis.Caption:=AO
    end;
end;
end;
end;

procedure TForm2.l4Click(Sender: TObject);
var O:char;
    X:char;
    AO:string;
    AX:string;
begin
X:='X';
O:='O';
AO:='Kreis ist an der Reihe!';
AX:='Kreuz ist an der Reihe!';

if lanweis.caption=AO then
begin
  if l4.caption=X then
    lanweis.Caption:='FEHLER!';
  if l4.caption=O then
    lanweis.Caption:='FEHLER!';
  if l4.caption=' ' then
    begin
    l4.caption:=O;
    lanweis.Caption:=AX
    end
else
begin
  if l4.caption=X then
    lanweis.Caption:='FEHLER!';
  if l4.caption=O then
    lanweis.Caption:='FEHLER!';
  if l4.caption=' ' then
    begin
    l4.caption:=X;
    lanweis.Caption:=AO
    end;
end;
end;
end;

procedure TForm2.l5Click(Sender: TObject);
var O:char;
    X:char;
    AO:string;
    AX:string;
begin
X:='X';
O:='O';
AO:='Kreis ist an der Reihe!';
AX:='Kreuz ist an der Reihe!';

if lanweis.caption=AO then
begin
  if l5.caption=X then
    lanweis.Caption:='FEHLER!';
  if l5.caption=O then
    lanweis.Caption:='FEHLER!';
  if l5.caption=' ' then
    begin
    l5.caption:=O;
    lanweis.Caption:=AX
    end
else
begin
  if l5.caption=X then
    lanweis.Caption:='FEHLER!';
  if l5.caption=O then
    lanweis.Caption:='FEHLER!';
  if l5.caption=' ' then
    begin
    l5.caption:=X;
    lanweis.Caption:=AO
    end;
end;
end;
end;

procedure TForm2.l6Click(Sender: TObject);
var O:char;
    X:char;
    AO:string;
    AX:string;
begin
X:='X';
O:='O';
AO:='Kreis ist an der Reihe!';
AX:='Kreuz ist an der Reihe!';

if lanweis.caption=AO then
begin
  if l6.caption=X then
    lanweis.Caption:='FEHLER!';
  if l6.caption=O then
    lanweis.Caption:='FEHLER!';
  if l6.caption=' ' then
    begin
    l6.caption:=O;
    lanweis.Caption:=AX
    end
else
begin
  if l6.caption=X then
    lanweis.Caption:='FEHLER!';
  if l6.caption=O then
    lanweis.Caption:='FEHLER!';
  if l6.caption=' ' then
    begin
    l6.caption:=X;
    lanweis.Caption:=AO
    end;
end;
end;
end;

procedure TForm2.l7Click(Sender: TObject);
var O:char;
    X:char;
    AO:string;
    AX:string;
begin
X:='X';
O:='O';
AO:='Kreis ist an der Reihe!';
AX:='Kreuz ist an der Reihe!';

if lanweis.caption=AO then
begin
  if l7.caption=X then
    lanweis.Caption:='FEHLER!';
  if l7.caption=O then
    lanweis.Caption:='FEHLER!';
  if l7.caption=' ' then
    begin
    l7.caption:=O;
    lanweis.Caption:=AX
    end
else
begin
  if l7.caption=X then
    lanweis.Caption:='FEHLER!';
  if l7.caption=O then
    lanweis.Caption:='FEHLER!';
  if l7.caption=' ' then
    begin
    l7.caption:=X;
    lanweis.Caption:=AO
    end;
end;
end;
end;

procedure TForm2.l8Click(Sender: TObject);
var O:char;
    X:char;
    AO:string;
    AX:string;
begin
X:='X';
O:='O';
AO:='Kreis ist an der Reihe!';
AX:='Kreuz ist an der Reihe!';

if lanweis.caption=AO then
begin
  if l8.caption=X then
    lanweis.Caption:='FEHLER!';
  if l8.caption=O then
    lanweis.Caption:='FEHLER!';
  if l8.caption=' ' then
    begin
    l8.caption:=O;
    lanweis.Caption:=AX
    end
else
begin
  if l8.caption=X then
    lanweis.Caption:='FEHLER!';
  if l8.caption=O then
    lanweis.Caption:='FEHLER!';
  if l8.caption=' ' then
    begin
    l8.caption:=X;
    lanweis.Caption:=AO
    end;
end;
end;
end;


ich hab ja nun gaaanz viele alternativen drin - also der erste zug funktioniert, außer in den labels l2;l4 &l8
dannach kann ich anklicken, was ich will - es passiert nichts,... ich glaube die altervnativen schließen sich irgendwie gegenseitig aus - WO IST DA DER FEHLER?

(weis nich, ob man sich das prog jetzt so vorstellen kann,...)
DANKE!!!!
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Do 11.05.06 17:56 
Hast du die Möglichkeit das Projekt mal in komprimierter Form hochzuladen? Das würde die Sache vereinfachen. Bitte nicht die EXE, DCU und die Dateien mit "~" mitliefern. Die braucht niemand.
F34r0fTh3D4rk
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 5285
Erhaltene Danke: 29

Win Vista (32), Win 7 (64)
Eclipse, SciTE, Lazarus
BeitragVerfasst: Do 11.05.06 18:21 
sind 400 zeilen nicht ein wenig viel für ein tictactoe ?
meins kommt unoptmiert mit ki mit 224 aus, ich benutze shapes, ich kann
hier ja mal den code posten. das spielfeld ist ein eindimensionales array
(mit den "oop" sachen kannst du vielleicht nicht viel anfangen aber zb die
siegbedingungen und die sache mit dem array könntest du dir abgucken:
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:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216:
217:
218:
219:
220:
221:
222:
223:
224:
unit UMain;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, StdCtrls;

type
  TSpieler = (keiner, mensch, maschine, unentschieden);
  TFeld = (nix, rot, blau);
  TForm1 = class(TForm)
    Shape1: TShape;
    Shape2: TShape;
    Shape3: TShape;
    Shape4: TShape;
    Shape5: TShape;
    Shape6: TShape;
    Shape7: TShape;
    Shape8: TShape;
    Shape9: TShape;
    Button1: TButton;
    Label1: TLabel;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure initgame;
    procedure reinitgame;
    function bewertung(spieler, gegner: TSpieler): integer;
    procedure ki;
    function gwinner: TSpieler;
    procedure myMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;
  spieler: TSpieler;
  runden: integer;
  spielende: boolean;
  felder: array[1..9] of TFeld;

implementation

{$R *.dfm}

function TForm1.bewertung(spieler, gegner: TSpieler): integer;
begin
  result := 0;
  if gwinner = spieler then
    result := 1;
  if gwinner = gegner then
    result := -1;
end;

procedure TForm1.ki;
var
  nextone: integer;
  function minimax(Level, MaxLevel: Integer; Spieler, Gegner: TSpieler; var aBestMove: integer): integer;
  var
    S, MaxS, i: Integer;
    Dummy: integer;
  begin
    MaxS := - maxint;
    for i := 1 To 9 Do
      if felder[i] = nix then
      begin
        case Spieler of
          mensch: felder[i] := rot;
          maschine: felder[i] := blau;
        end;  
        S := Bewertung(Spieler, Gegner);
        if (S = 0) and (Level < MaxLevel) then
          S := - minimax(Level + 1, MaxLevel, Gegner, Spieler, Dummy);
        felder[i] := nix;
        if S > MaxS then
        begin
          MaxS := s;
          aBestMove := i;
          If s > 0 then
          begin
            Result := s;
            exit;
          end;
        end;
      end;
    If MaxS = - maxint then
    begin
      Result := Bewertung(Spieler, Gegner);
      aBestMove := -1;
    end else
      Result := MaxS;
  end;
begin
  nextone := 5;
  if not spielende then
  begin
    if (runden = 1) and (felder[5] = rot) then
      nextone := 1;
    if runden > 1 then
      minimax(0, maxint, maschine, mensch, nextone);
    if felder[nextone] = nix then
    begin
      felder[nextone] := blau;
      tshape(findcomponent('shape' + inttostr(nextone))).brush.color := clblue;
      if gwinner = maschine then
      begin
        spielende := true;
        showmessage('Du hast verloren');
      end else
        if gwinner = unentschieden then
          showmessage('Unentschieden');
      spieler := mensch;
      inc(runden);
      label1.caption := 'Du bist dran';
    end;
  end;
end;

procedure TForm1.initgame;
var
  rand: byte;
begin
  spielende := false;
  runden := 0;
  rand := random(2);
  if rand = 0 then
  begin
    spieler := mensch;
    label1.caption := 'Du bist dran';
  end else
  begin
    spieler := maschine;
    ki;
  end;
end;

procedure TForm1.reinitgame;
var
  i: integer;
begin
  for i := 1 to 9 do
  begin
    felder[i] := nix;
    TShape(findcomponent('shape' + inttostr(i))).brush.color := clwhite;
  end;
  initgame;
end;

function TForm1.gwinner: TSpieler;
  function checkf(farbe: TFeld): boolean;
  begin
    result := ((felder[1] = farbe) and (felder[2] = farbe) and (felder[3] = farbe)) or
              ((felder[4] = farbe) and (felder[5] = farbe) and (felder[6] = farbe)) or
              ((felder[7] = farbe) and (felder[8] = farbe) and (felder[9] = farbe)) or
              ((felder[1] = farbe) and (felder[4] = farbe) and (felder[7] = farbe)) or
              ((felder[2] = farbe) and (felder[5] = farbe) and (felder[8] = farbe)) or
              ((felder[3] = farbe) and (felder[6] = farbe) and (felder[9] = farbe));
    if ((felder[1] = farbe) and (felder[5] = farbe) and (felder[9] = farbe)) then
      result := true;
    if ((felder[3] = farbe) and (felder[5] = farbe) and (felder[7] = farbe)) then
      result := true;
  end;
var
  i: integer;
  ucheck: boolean;
begin
  ucheck := true;
  result := keiner;
  if checkf(rot) then
    result := mensch;
  if checkf(blau) then
    result := maschine;
  if (result = keiner) then
  begin
    for i := 1 to 9 do
      if felder[i] = nix then
        ucheck := false;
    if ucheck then
      result := unentschieden;
  end;
end;

procedure TForm1.myMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  if (spieler = mensch) and (not spielende) and (felder[TShape(Sender).Tag] = nix) then
  begin
    felder[TShape(Sender).Tag] := rot;
    TShape(Sender).brush.color := clred;
    if gwinner = mensch then
    begin
      spielende := true;
      showmessage('Du hast gewonnen');
    end else
      if gwinner = unentschieden then
        showmessage('Unentschieden');
    spieler := maschine;
    inc(runden);
    ki;
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
var
  i: byte;
begin
  for i := 1 to 9 do
    TShape(findcomponent('Shape' + inttostr(i))).Tag := i;
  initgame;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  reInitGame;
end;

Initialization
  randomize;

end.

da ist auch noch die anzeige da, falls der spieler gewonnen hat (was bei mir nie der fall ist ;) )

das bewertungs und ki zeugs kannst du ignorieren, ohne das komme ich auf 151 zeilen

du hast auch immer ne menge arbeit, da du jedes feld einzeln extra bearbeiten musst, da ist ne menge doppelt.