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 24 by yamat0jp, Sun Jul 19 01:35:48 2015 UTC revision 26 by yamat0jp, Mon Jul 20 07:09:07 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 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  function TStoneGrid.CalScore(Stone: TSto Line 134  function TStoneGrid.CalScore(Stone: TSto
134  var  var
135    i, j: integer;    i, j: integer;
136  begin  begin
137      result := 0;
138    if CanSetStone(Stone, X, Y, true) = true then    if CanSetStone(Stone, X, Y, true) = true then
139    begin    begin
140        if Stone = stEffect then
141          Stone := FEffectStone;
142      case Stone of      case Stone of
143        stBlack:        stBlack:
144          Stone := stWhite;          Stone := stWhite;
145        stWhite:        stWhite:
146          Stone := stBlack;          Stone := stBlack;
147        stEffect:      else
148          Stone := FEffectStone;        Exit;
149      end;      end;
     result := 0;  
150      for i := 0 to Count - 1 do      for i := 0 to Count - 1 do
151        for j := 0 to Count - 1 do        for j := 0 to Count - 1 do
152          if CanSetStone(Stone, i, j, false) = true then          if CanSetStone(Stone, i, j, false) = true then
153            inc(result);            inc(result);
     FStrings := FBuffer[FTurnIndex];  
   end  
   else  
   begin  
     FStrings := FBuffer[FTurnIndex];  
     result := -1;  
154    end;    end;
155      FStrings := FBuffer[FTurnIndex];
156  end;  end;
157    
158  function TStoneGrid.CanSetStone(Stone: TStoneType; X, Y: integer;  function TStoneGrid.CanSetStone(Stone: TStoneType; X, Y: integer;
# Line 197  var Line 193  var
193                  New(q);                  New(q);
194                  q^.Left := X + m * j;                  q^.Left := X + m * j;
195                  q^.Top := Y + n * j;                  q^.Top := Y + n * j;
                 q^.Stone := Stone;  
196                  q^.X := 0;                  q^.X := 0;
197                  q^.Y := 0;                  q^.Y := 0;
198                  FList.Add(q);                  FList.Add(q);
# Line 317  begin Line 312  begin
312        end        end
313        else        else
314        begin        begin
315          SetStrings(p^.Left, p^.Top, p^.Stone);          SetStrings(p^.Left, p^.Top, FEffectStone);
316          Dispose(p);          Dispose(p);
317          FList[i] := nil;          FList[i] := nil;
318        end;        end;
# Line 339  begin Line 334  begin
334    end;    end;
335  end;  end;
336    
337  function TStoneGrid.NextStone(Stone: TStoneType): TPoint;  function TStoneGrid.NextStone(Stone: TStoneType; var Pos: TPoint): Boolean;
338  var  var
339    i, j, m, n: integer;    i, j, m, n: integer;
340  begin  begin
341    n := -1;    n := 0;
342    for i := 0 to Count - 1 do    for i := 0 to Count - 1 do
343      for j := 0 to Count - 1 do      for j := 0 to Count - 1 do
344      begin      begin
345        m := CalScore(Stone, i, j);        m := CalScore(Stone, i, j);
346        if (n = -1) or ((m > -1) and (n > m)) then        if ((n = 0) and (m > 0)) or ((0 < m) and (m < n)) then
347        begin        begin
348          n := m;          n := m;
349          result := Point(i, j);          Pos := Point(i, j);
350        end;        end;
351      end;      end;
352    if n = -1 then    result := not(n = 0);
     result := Point(-1, -1);  
353  end;  end;
354    
355  procedure TStoneGrid.Paint(Canvas: TCanvas);  procedure TStoneGrid.Paint(Canvas: TCanvas);
# Line 371  begin Line 365  begin
365    for i := 0 to FList.Count - 1 do    for i := 0 to FList.Count - 1 do
366    begin    begin
367      p := FList[i];      p := FList[i];
368      if p^.Stone = stBlack then      if FEffectStone = stBlack then
369        s := Form1.Image1.Bitmap        s := Form1.Image1.Bitmap
370      else      else
371        s := Form1.Image2.Bitmap;        s := Form1.Image2.Bitmap;
# Line 383  end; Line 377  end;
377    
378  procedure TStoneGrid.Pause;  procedure TStoneGrid.Pause;
379  begin  begin
380    if FActive = true then    FActive := false;
     FActive := false;  
381    FTerminated := true;    FTerminated := true;
382  end;  end;
383    
384  procedure TStoneGrid.Restart;  procedure TStoneGrid.Restart;
385  begin  begin
386    if FTerminated = true then    FActive := true;
387    begin    FTurnIndex := FTurnNumber;
388      FActive := true;    FTerminated := false;
     FTurnIndex := FTurnNumber;  
     FTerminated := false;  
   end;  
389  end;  end;
390    
391  procedure TStoneGrid.SetStrings(X, Y: integer; const Value: TStoneType);  procedure TStoneGrid.SetStrings(X, Y: integer; const Value: TStoneType);
# Line 444  var Line 434  var
434    function Execute: Boolean;    function Execute: Boolean;
435    var    var
436      i, j: integer;      i, j: integer;
     m: integer;  
     n: integer;  
437    begin    begin
438      for i := 0 to Count - 1 do      for i := 0 to Count - 1 do
439        for j := 0 to Count - 1 do        for j := 0 to Count - 1 do
# Line 458  var Line 446  var
446    end;    end;
447    
448  begin  begin
   Timer1.Enabled:=false;  
449    Main;    Main;
450    if Execute = false then    if Execute = false then
451    begin    begin
# Line 491  begin Line 478  begin
478    end    end
479    else    else
480      Caption := s;      Caption := s;
   Timer1.Enabled:=true;  
481  end;  end;
482    
483  procedure TForm1.CompStone;  procedure TForm1.CompStone;
484  var  var
485    s: TPoint;    s: TPoint;
486  begin  begin
487    s := StoneGrid.NextStone(Index.Stone);    if StoneGrid.NextStone(Index.Stone, s) = true then
488    StoneGrid.CanSetStone(Index.Stone, s.X, s.Y, true, true);    begin
489    PaintBox1.Repaint;      StoneGrid.CanSetStone(Index.Stone, s.X, s.Y, true, true);
490    ChangePlayer;      PaintBox1.Repaint;
491        ChangePlayer;
492      end;
493  end;  end;
494    
495  procedure TForm1.GameStart;  procedure TForm1.GameStart;
496  begin  begin
497    Timer1.Enabled:=false;    Timer1.Enabled := false;
498    Index := Player1;    Index := Player1;
499    StoneGrid.Start;    StoneGrid.Start;
500    PaintBox1.Repaint;    PaintBox1.Repaint;
501    Caption := '黒から始めます';    Caption := '黒から始めます';
502    Timer1.Enabled:=true;    Timer1.Enabled := true;
503  end;  end;
504    
505  procedure TForm1.MenuItem10Click(Sender: TObject);  procedure TForm1.MenuItem10Click(Sender: TObject);

Legend:
Removed from v.24  
changed lines
  Added in v.26

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