Autor Beitrag
Tilo
ontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 1098
Erhaltene Danke: 13

Win7 geg. WInXP oder sogar Win98
Rad2007
BeitragVerfasst: Sa 03.07.04 13:36 
Also erstmal weiss ich nicht in welche Rubik dies gehört, da ich nicht weiss wo der fehler liegt.

Der Code ist folgender:
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:
program StartDateiersteller;

uses

math;

type
  Tfigur = record
  spieler:(weiss,schwarz);
  typ:(Bauer,Turm,Springer,Laeufer,Koenig,Dame);
  xpos: 1..8;
  ypos: 1..8;
 end;

{$R *.res}
var
figurs:array [1..32] of Tfigur;
a:integer;
b:integer;
c:string[1];
d:integer;
bitstring:string;
charstring:string;
startfile:file;
begin
b:=0;
//BauernPositionen
for a:=1 to 8 do
begin
 figurs[a].typ:=Bauer;   figurs[a].ypos:=2;
 figurs[a].spieler:=weiss;       figurs[a].xpos:=a;
end;
b:=8;
for a:=1 to 8 do
begin
 figurs[a+b].spieler:=schwarz;   figurs[a+b].typ:=Bauer;
 figurs[a+b].ypos:=7;    figurs[a+b].xpos:=a;
end;
b:=b+8;
//TurmPositionen
Figurs[17].spieler:=weiss;       Figurs[17].typ:=turm;
Figurs[17].ypos:=1;     Figurs[17].xpos:=1;
Figurs[18].spieler:=weiss;       Figurs[18].typ:=turm;
Figurs[18].ypos:=1;     Figurs[18].xpos:=8;
Figurs[19].spieler:=schwarz;    Figurs[19].typ:=turm;
Figurs[19].ypos:=8;     Figurs[19].xpos:=1;
Figurs[20].spieler:=schwarz;    Figurs[20].typ:=turm;
Figurs[20].ypos:=8;     Figurs[20].xpos:=8;
//SpringerPositionen
Figurs[21].spieler:=weiss;      Figurs[21].typ:=springer;
Figurs[21].ypos:=1;     Figurs[21].xpos:=2;
Figurs[22].spieler:=weiss;      Figurs[22].typ:=springer;
Figurs[22].ypos:=1;     Figurs[22].xpos:=7;
Figurs[23].spieler:=schwarz;    Figurs[23].typ:=springer;
Figurs[23].ypos:=8;     Figurs[23].xpos:=7;
Figurs[24].spieler:=schwarz;    Figurs[24].typ:=springer;
Figurs[24].ypos:=1;     Figurs[24].xpos:=2;
//LäuferPositionen
Figurs[25].spieler:=weiss;      Figurs[25].typ:=laeufer;
Figurs[25].ypos:=1;     Figurs[25].xpos:=3;
Figurs[26].spieler:=weiss;      Figurs[26].typ:=laeufer;
Figurs[26].ypos:=1;     Figurs[26].xpos:=6;
Figurs[27].spieler:=schwarz;    Figurs[27].typ:=laeufer;
Figurs[27].ypos:=8;     Figurs[27].xpos:=3;
Figurs[28].spieler:=schwarz;    Figurs[28].typ:=laeufer;
Figurs[28].ypos:=8;     Figurs[28].xpos:=6;
//KönigPositionen
Figurs[29].spieler:=weiss;      Figurs[29].typ:=koenig;
Figurs[29].ypos:=1;     Figurs[29].xpos:=5;
Figurs[30].spieler:=schwarz;    Figurs[30].typ:=koenig;
Figurs[30].ypos:=8;     Figurs[30].xpos:=5;
//DamePositionen
Figurs[31].spieler:=weiss;      Figurs[31].typ:=dame;
Figurs[31].ypos:=1;     Figurs[31].xpos:=4;
Figurs[32].spieler:=schwarz;    Figurs[32].typ:=dame;
Figurs[32].ypos:=8;     Figurs[32].xpos:=4;

//Bitzerlegung?
charstring:='';
bitstring:='';
for a:=1 to 32 do
begin
 case figurs[a].spieler of
  weiss:        bitstring:=bitstring+'1';
  schwarz:     bitstring:=bitstring+'0';
 end;
 case figurs[a].typ of
  bauer:        bitstring:=bitstring+'000';
  turm:         bitstring:=bitstring+'001';
  springer:     bitstring:=bitstring+'010';
  laeufer:      bitstring:=bitstring+'011';
  koenig:       bitstring:=bitstring+'100';
  dame:         bitstring:=bitstring+'101';
 end;
 case figurs[a].xpos of
  1:        bitstring:=bitstring+'000';
  2:        bitstring:=bitstring+'001';
  3:        bitstring:=bitstring+'010';
  4:        bitstring:=bitstring+'011';
  5:        bitstring:=bitstring+'100';
  6:        bitstring:=bitstring+'101';
  7:        bitstring:=bitstring+'110';
  8:        bitstring:=bitstring+'111';
 end;
 case figurs[a].ypos of
  1:        bitstring:=bitstring+'000';
  2:        bitstring:=bitstring+'001';
  3:        bitstring:=bitstring+'010';
  4:        bitstring:=bitstring+'011';
  5:        bitstring:=bitstring+'100';
  6:        bitstring:=bitstring+'101';
  7:        bitstring:=bitstring+'110';
  8:        bitstring:=bitstring+'111';
 end;
 //BittoChar
end;
d:=0;
for a:=0 to 39 do
begin
 for b:=1 to 8 do
 begin
  c:=copy(bitstring,b+a*8,1);
  if c='1' then d:=d+ceil(intpower(2,8-b));
 end;
 charstring:=charstring+chr(d);
end;

//Speichern
assignfile(startfile,'startpos.dat');
rewrite(startfile,1);
//blockwrite(startfile,bitstring,length(bitstring));
blockwrite(startfile,charstring,length(charstring));
closefile(startfile);

end.

Das ist das komplette Programm. Es besitzt keine grafischen Elemente und es erscheint auch keinerlei Meldungen.
Das Programm dient nur dazu die Startposition der Figuren beim Schach in eine Datei abzuspeichern.
Dazu werden zuerst die Informationen über die Figuren in den Zeilen 41 bis 76 festgelegt. Bis Zeile 114 werden die Informationen in eine BitFolge umgewandelt und dann bis Zeile 126 in charsumgewandelt. Das Ganze dient dazu die Informationen Platzsparend abzuspeichern.

Nun Mein Problem: Wenn mann in Zeile 132 das Programm anhält und sich die Variable "charstring" ansieht (also auswerten lässt) und dann mit dem Inhalt der Datei vergleicht ist das nicht das selbe. Es müsste aber doch das selbe sein, oder?
Könnt ihr mir sagen, wo mein denkfehler liegt?


Moderiert von user profile iconPeter Lustig: Topic aus Off Topic verschoben am Sa 03.07.2004 um 14:38
MartinPb
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 698



BeitragVerfasst: Sa 03.07.04 14:24 
Wenn du das Programm in Zeile 132 anhällst und mit der Datei vergeichst, dann kann der Inhalt nicht der gleiche sein. In der Zeile 132 ist das Ergebnis noch nicht gespeichert worden, bzw. in die Datei geschrieben worden. Erst in der Zeile 133 ist die Aktion durchgeführt. Allerdings ist in der Zeile 133 die Datei immer noch offen.

Ob es jedoch daran liegt, weiß ich nicht.

_________________
Gruß
Martin
Tilo Threadstarter
ontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 1098
Erhaltene Danke: 13

Win7 geg. WInXP oder sogar Win98
Rad2007
BeitragVerfasst: Sa 03.07.04 18:11 
Das in Zeile 132 es noch nicht das gleiche sein kann weiss ich. Mit dem Vergleich bezog ich mich nach Ablauf des gesamten Programms (sind dann ja nur noch 3 Zeilen).
Tilo Threadstarter
ontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 1098
Erhaltene Danke: 13

Win7 geg. WInXP oder sogar Win98
Rad2007
BeitragVerfasst: So 04.07.04 13:44 
Okay ich habe jetzt eine Verbesserung:,
wenn mann in Zeile 24 startfile als textfile definiert und Zeile 130 anpasst, dann ist mein Problem behoben.

Trotzdem Danke für das Interesse an diesem Problem.