Develop and Download Open Source Software

Browse Subversion Repository

Diff of /Unit1.pas

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 21 by yamat0jp, Sat Jul 18 22:36:44 2015 UTC revision 27 by yamat0jp, Mon Jul 20 09:01:47 2015 UTC
# Line 17  type Line 17  type
17    TEffectData = record    TEffectData = record
18      X, Y: integer;      X, Y: integer;
19      Left, Top: integer;      Left, Top: integer;
     Stone: TStoneType;  
20    end;    end;
21    
22    TGridData = array [0 .. Count - 1] of array [0 .. Count - 1] of TStoneType;    TGridData = array [0 .. Count - 1] of array [0 .. Count - 1] of TStoneType;
# Line 38  type Line 37  type
37      FTurnNumber: integer;      FTurnNumber: integer;
38      FTurnIndex: integer;      FTurnIndex: integer;
39      FActive: Boolean;      FActive: Boolean;
40      List: TList;      FList: TList;
41      FEffectStone: TStoneType;      FEffectStone: TStoneType;
42      FBool: Boolean;      FBool: Boolean;
43      FTerminated: Boolean;      FTerminated: Boolean;
# Line 54  type Line 53  type
53      function CalScore(Stone: TStoneType; X, Y: integer): integer;      function CalScore(Stone: TStoneType; X, Y: integer): integer;
54      function CanSetStone(Stone: TStoneType; X, Y: integer; Reverse: Boolean;      function CanSetStone(Stone: TStoneType; X, Y: integer; Reverse: Boolean;
55        const Visible: Boolean = false): Boolean;        const Visible: Boolean = false): Boolean;
56      function NextStone(Stone: TStoneType): TPoint;      function NextStone(Stone: TStoneType; var Pos: TPoint): Boolean;
57      procedure Start;      procedure Start;
58      procedure Restart;      procedure Restart;
59      procedure Pause;      procedure Pause;
# Line 135  var Line 134  var
134  begin  begin
135    if CanSetStone(Stone, X, Y, true) = true then    if CanSetStone(Stone, X, Y, true) = true then
136    begin    begin
137        result := 0;
138      case Stone of      case Stone of
139      stBlack:        stBlack:
140        Stone := stWhite;          Stone := stWhite;
141      stWhite:        stWhite:
142        Stone := stBlack;          Stone := stBlack;
     stEffect:  
       Stone := FEffectStone;  
143      end;      end;
     result := 0;  
144      for i := 0 to Count - 1 do      for i := 0 to Count - 1 do
145        for j := 0 to Count - 1 do        for j := 0 to Count - 1 do
146          if CanSetStone(Stone, i, j, false) = true then          if CanSetStone(Stone, i, j, false) = true then
147            inc(result);            inc(result);
     FStrings := FBuffer[FTurnIndex];  
148    end    end
149    else    else
   begin  
     FStrings := FBuffer[FTurnIndex];  
150      result := -1;      result := -1;
151    end;    FStrings := FBuffer[FTurnIndex];
152  end;  end;
153    
154  function TStoneGrid.CanSetStone(Stone: TStoneType; X, Y: integer;  function TStoneGrid.CanSetStone(Stone: TStoneType; X, Y: integer;
# Line 175  var Line 169  var
169      begin      begin
170        s := GetStrings(X + m * i, Y + n * i);        s := GetStrings(X + m * i, Y + n * i);
171        if s = stEffect then        if s = stEffect then
172          s:=FEffectStone;          s := FEffectStone;
173        if (s = stNone) or (s = stError) then        if (s = stNone) or (s = stError) then
174          break          break
175        else if s = Stone then        else if s = Stone then
# Line 191  var Line 185  var
185                Form1.PaintBox1.Repaint;                Form1.PaintBox1.Repaint;
186                if Visible = true then                if Visible = true then
187                begin                begin
188                  FEffectStone:=Stone;                  FEffectStone := Stone;
189                  New(q);                  New(q);
190                  q^.Left := X + m * j;                  q^.Left := X + m * j;
191                  q^.Top := Y + n * j;                  q^.Top := Y + n * j;
                 q^.Stone := Stone;  
192                  q^.X := 0;                  q^.X := 0;
193                  q^.Y := 0;                  q^.Y := 0;
194                  List.Add(q);                  FList.Add(q);
195                  SetStrings(q^.Left, q^.Top, stEffect);                  SetStrings(q^.Left, q^.Top, stEffect);
196                  for k := 1 to 100 do                  for k := 1 to 100 do
197                  begin                  begin
# Line 249  procedure TStoneGrid.Clear; Line 242  procedure TStoneGrid.Clear;
242  var  var
243    i, j: integer;    i, j: integer;
244  begin  begin
245      for i := 0 to FList.Count - 1 do
246        Dispose(FList[i]);
247      FList.Clear;
248    for i := 0 to Count - 1 do    for i := 0 to Count - 1 do
249      for j := 0 to Count - 1 do      for j := 0 to Count - 1 do
250        Strings[i, j] := stNone;        Strings[i, j] := stNone;
# Line 264  end; Line 260  end;
260  constructor TStoneGrid.Create;  constructor TStoneGrid.Create;
261  begin  begin
262    inherited;    inherited;
263    List := TList.Create;    FList := TList.Create;
264  end;  end;
265    
266  destructor TStoneGrid.Destroy;  destructor TStoneGrid.Destroy;
267  var  var
268    i: integer;    i: integer;
269  begin  begin
270    for i := 0 to List.Count - 1 do    for i := 0 to FList.Count - 1 do
271      Dispose(List[i]);      Dispose(FList[i]);
272    List.Free;    FList.Free;
273    inherited;    inherited;
274  end;  end;
275    
# Line 296  var Line 292  var
292    p: ^TEffectData;    p: ^TEffectData;
293    i: integer;    i: integer;
294  begin  begin
295    if List.Count = 0 then    if FList.Count = 0 then
296      result := false      result := false
297    else    else
298    begin    begin
299      for i := 0 to List.Count - 1 do      for i := 0 to FList.Count - 1 do
300      begin      begin
301        p := List.List[i];        p := FList[i];
302        if p^.X < FIndex_X - 1 then        if p^.X < FIndex_X - 1 then
303          p^.X := p^.X + 1          p^.X := p^.X + 1
304        else if p^.Y < FIndex_Y - 1 then        else if p^.Y < FIndex_Y - 1 then
# Line 312  begin Line 308  begin
308        end        end
309        else        else
310        begin        begin
311          SetStrings(p^.Left, p^.Top, p^.Stone);          SetStrings(p^.Left, p^.Top, FEffectStone);
312          Dispose(p);          Dispose(p);
313          List[i] := nil;          FList[i] := nil;
314        end;        end;
315      end;      end;
316      for i := List.Count - 1 downto 0 do      for i := FList.Count - 1 downto 0 do
317        if List[i] = nil then        if FList[i] = nil then
318          List.Delete(i);          FList.Delete(i);
319      if List.Count = 0 then      if FList.Count = 0 then
320      begin      begin
321        if FTerminated = true then        if FTerminated = true then
322          FActive:=false          FActive := false
323        else        else
324          FActive := FBool;          FActive := FBool;
325        inc(FTurnIndex);        inc(FTurnIndex);
# Line 334  begin Line 330  begin
330    end;    end;
331  end;  end;
332    
333  function TStoneGrid.NextStone(Stone: TStoneType): TPoint;  function TStoneGrid.NextStone(Stone: TStoneType; var Pos: TPoint): Boolean;
334  var  var
335    i, j, m, n: integer;    i, j, m, n: integer;
336  begin  begin
# Line 343  begin Line 339  begin
339      for j := 0 to Count - 1 do      for j := 0 to Count - 1 do
340      begin      begin
341        m := CalScore(Stone, i, j);        m := CalScore(Stone, i, j);
342        if (n = -1) or ((m > -1) and (n > m)) then        if (n = -1) or ((0 < m) and (m < n)) then
343        begin        begin
344          n := m;          n := m;
345          result := Point(i, j);          Pos := Point(i, j);
346        end;        end;
347      end;      end;
348    if n = -1 then    result := not(n = -1);
     result := Point(-1, -1);  
349  end;  end;
350    
351  procedure TStoneGrid.Paint(Canvas: TCanvas);  procedure TStoneGrid.Paint(Canvas: TCanvas);
# Line 363  begin Line 358  begin
358    m := Form1.Image3.Bitmap.Width;    m := Form1.Image3.Bitmap.Width;
359    n := Form1.Image3.Bitmap.Height;    n := Form1.Image3.Bitmap.Height;
360    k := Form1.Size;    k := Form1.Size;
361    for i := 0 to List.Count - 1 do    for i := 0 to FList.Count - 1 do
362    begin    begin
363      p := List[i];      p := FList[i];
364      if p^.Stone = stBlack then      if FEffectStone = stBlack then
365        s := Form1.Image1.Bitmap        s := Form1.Image1.Bitmap
366      else      else
367        s := Form1.Image2.Bitmap;        s := Form1.Image2.Bitmap;
# Line 378  end; Line 373  end;
373    
374  procedure TStoneGrid.Pause;  procedure TStoneGrid.Pause;
375  begin  begin
376    FTerminated:=true;    FActive := false;
377      FTerminated := true;
378  end;  end;
379    
380  procedure TStoneGrid.Restart;  procedure TStoneGrid.Restart;
381  begin  begin
382    if FTerminated = true then    FActive := true;
383    begin    FTurnIndex := FTurnNumber;
384      FActive := true;    FTerminated := false;
     FTurnIndex := FTurnNumber;  
     FTerminated:=false;  
   end;  
385  end;  end;
386    
387  procedure TStoneGrid.SetStrings(X, Y: integer; const Value: TStoneType);  procedure TStoneGrid.SetStrings(X, Y: integer; const Value: TStoneType);
# Line 411  end; Line 404  end;
404  procedure TStoneGrid.Start;  procedure TStoneGrid.Start;
405  begin  begin
406    Clear;    Clear;
407    FTerminated:=false;    FTerminated := false;
408    FActive := true;    FActive := true;
409  end;  end;
410    
# Line 437  var Line 430  var
430    function Execute: Boolean;    function Execute: Boolean;
431    var    var
432      i, j: integer;      i, j: integer;
     m: integer;  
     n: integer;  
433    begin    begin
434      for i := 0 to Count - 1 do      for i := 0 to Count - 1 do
435        for j := 0 to Count - 1 do        for j := 0 to Count - 1 do
# Line 489  procedure TForm1.CompStone; Line 480  procedure TForm1.CompStone;
480  var  var
481    s: TPoint;    s: TPoint;
482  begin  begin
483    s := StoneGrid.NextStone(Index.Stone);    if StoneGrid.NextStone(Index.Stone, s) = true then
484    StoneGrid.CanSetStone(Index.Stone, s.X, s.Y, true, true);    begin
485    PaintBox1.Repaint;      StoneGrid.CanSetStone(Index.Stone, s.X, s.Y, true, true);
486        PaintBox1.Repaint;
487      end;
488    ChangePlayer;    ChangePlayer;
489  end;  end;
490    
# Line 631  end; Line 624  end;
624    
625  procedure TForm1.Timer2Timer(Sender: TObject);  procedure TForm1.Timer2Timer(Sender: TObject);
626  begin  begin
627    if (StoneGrid.Active = false)and(StoneGrid.ListExecute = true) then    if (StoneGrid.Active = false) and (StoneGrid.ListExecute = true) then
628      PaintBox1.Repaint;      PaintBox1.Repaint;
629  end;  end;
630    

Legend:
Removed from v.21  
changed lines
  Added in v.27

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26