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 30 by yamat0jp, Sun Aug 16 04:15:52 2015 UTC revision 31 by yamat0jp, Sun Aug 16 06:21:21 2015 UTC
# Line 51  type Line 51  type
51      constructor Create;      constructor Create;
52      destructor Destroy; override;      destructor Destroy; override;
53      procedure Clear;      procedure Clear;
54      function CalScore(Stone: TStoneType; X, Y: integer): integer;      function CalScore(Stone: TStoneType; X, Y: integer; out Score: integer): Boolean;
55      function CanSetStone(Stone: TStoneType; X, Y: integer; Reverse: Boolean;      function CanSetStone(Stone: TStoneType; X, Y: integer; Reverse: Boolean;
56        const Visible: Boolean = false): Boolean;        const Visible: Boolean = false): Boolean;
57      function NextStone(Stone: TStoneType; var Pos: TPoint): Boolean;      function NextStone(Stone: TStoneType; var Pos: TPoint): Boolean;
# Line 130  implementation Line 130  implementation
130  {$R *.fmx}  {$R *.fmx}
131  {$R *.Windows.fmx MSWINDOWS}  {$R *.Windows.fmx MSWINDOWS}
132  {$R *.XLgXhdpiTb.fmx ANDROID}  {$R *.XLgXhdpiTb.fmx ANDROID}
   
133  { TStoneGrid }  { TStoneGrid }
134    
135  function TStoneGrid.AddScore(X, Y: integer; const NG: array of TPoint): integer;  function TStoneGrid.AddScore(X, Y: integer; const NG: array of TPoint): integer;
# Line 146  begin Line 145  begin
145      end;      end;
146  end;  end;
147    
148  function TStoneGrid.CalScore(Stone: TStoneType; X, Y: integer): integer;  function TStoneGrid.CalScore(Stone: TStoneType; X, Y: integer; out Score: integer): Boolean;
149  var  var
150    i, j: integer;    i, j: integer;
151    const
152      wast: array [0 .. 11] of TPoint = ((X: 1; Y: 0), (X: 6; Y: 0), (X: 0;
153        Y: 1), (X: 1; Y: 1), (X: 6; Y: 1), (X: 7; Y: 1), (X: 0; Y: 6), (X: 1; Y: 6),
154        (X: 6; Y: 6), (X: 7; Y: 6), (X: 1; Y: 7), (X: 6; Y: 7));
155      worth: array [0 .. 3] of TPoint = ((X: 0; Y: 0), (X: 7; Y: 0), (X: 0;
156        Y: 7), (X: 7; Y: 7));
157  begin  begin
158    if CanSetStone(Stone, X, Y, true) = true then    if CanSetStone(Stone, X, Y, true) = true then
159    begin    begin
160      result := 0;      Score := 0;
161        result:=true;
162      if FTurnIndex < 50 then      if FTurnIndex < 50 then
163        inc(result, AddScore(X, Y, [Point(1, 0), Point(6, 0), Point(0, 1),        inc(Score, AddScore(X, Y, wast));
164          Point(1, 1), Point(6, 1), Point(7, 1), Point(0, 6), Point(1, 6),      dec(Score, AddScore(X, Y, worth));
         Point(6, 6), Point(7, 6), Point(1, 7), Point(6, 7)]));  
165      case Stone of      case Stone of
166        stBlack:        stBlack:
167          Stone := stWhite;          Stone := stWhite;
# Line 167  begin Line 172  begin
172        for j := 0 to Count - 1 do        for j := 0 to Count - 1 do
173          if CanSetStone(Stone, i, j, false) = true then          if CanSetStone(Stone, i, j, false) = true then
174          begin          begin
175            inc(result);            inc(Score);
176            if FTurnIndex < 50 then            inc(Score, AddScore(i, j, worth));
             inc(result, AddScore(i, j, [Point(0, 0), Point(7, 0), Point(0, 7),  
               Point(7, 7)]));  
177          end;          end;
178    end    end
179    else    else
180      result := -1;      result := false;
181    FStrings := FBuffer[FTurnIndex];    FStrings := FBuffer[FTurnIndex];
182  end;  end;
183    
# Line 357  begin Line 360  begin
360        inc(FTurnIndex);        inc(FTurnIndex);
361        inc(FTurnNumber);        inc(FTurnNumber);
362        FBuffer[FTurnIndex] := FStrings;        FBuffer[FTurnIndex] := FStrings;
363          Form1.PaintBox1.Repaint;
364          Form1.ChangePlayer;
365        if FGameOver = false then        if FGameOver = false then
366        begin          FActive := true
         Form1.ChangePlayer;  
         FActive:=true;  
       end;  
367      end;      end;
368      result := true;      result := true;
369    end;    end;
# Line 371  function TStoneGrid.NextStone(Stone: TSt Line 373  function TStoneGrid.NextStone(Stone: TSt
373  var  var
374    i, j, m, n: integer;    i, j, m, n: integer;
375  begin  begin
376    n := -1;    result:=false;
377      n:=0;
378    for i := 0 to Count - 1 do    for i := 0 to Count - 1 do
379      for j := 0 to Count - 1 do      for j := 0 to Count - 1 do
380      begin        if (CalScore(Stone, i, j, m) = true) and ((result = false)or(m < n)) then
       m := CalScore(Stone, i, j);  
       if (n = -1) or ((0 < m) and (m < n)) then  
381        begin        begin
382          n := m;          if result = false then
383              result:=true;
384            n:=m;
385          Pos := Point(i, j);          Pos := Point(i, j);
386        end;        end;
     end;  
   result := not(n = -1);  
387  end;  end;
388    
389  procedure TStoneGrid.Paint(Canvas: TCanvas);  procedure TStoneGrid.Paint(Canvas: TCanvas);
# Line 415  end; Line 416  end;
416    
417  procedure TStoneGrid.Restart;  procedure TStoneGrid.Restart;
418  begin  begin
419    FActive:=true;    FActive := true;
420    FGameOver := false;    FGameOver := false;
421    FTurnIndex := FTurnNumber;    FTurnIndex := FTurnNumber;
422  end;  end;
423    
424  procedure TStoneGrid.SetActive(const Value: Boolean);  procedure TStoneGrid.SetActive(const Value: Boolean);
425  begin  begin
426    if (FGameOver = false)or(Value = false) then    if (FGameOver = false) or (Value = false) then
427      FActive := Value;      FActive := Value;
428  end;  end;
429    
# Line 508  begin Line 509  begin
509        else        else
510          s := 'Draw:' + #13#10;          s := 'Draw:' + #13#10;
511        StoneGrid.GameOver;        StoneGrid.GameOver;
512        Showmessage(s + '(Player1) ' + IntToStr(m) + #13#10 + '(Player2) ' +        Showmessage(s + '(Player1) ' + m.ToString+ #13#10 + '(Player2) ' +
513          IntToStr(n));          n.ToString);
514      end      end
515      else      else
516        Caption := s;        Caption := s;
# Line 523  var Line 524  var
524    s: TPoint;    s: TPoint;
525  begin  begin
526    StoneGrid.Active := false;    StoneGrid.Active := false;
527    StoneGrid.NextStone(Index.Stone, s);    if StoneGrid.NextStone(Index.Stone, s) = true then
528    StoneGrid.CanSetStone(Index.Stone, s.X, s.Y, true, true);    begin
529    PaintBox1.Repaint;      StoneGrid.CanSetStone(Index.Stone, s.X, s.Y, true, true);
530        PaintBox1.Repaint;
531      end
532      else
533        ChangePlayer;
534  end;  end;
535    
536  procedure TForm1.GameStart;  procedure TForm1.GameStart;
# Line 629  end; Line 634  end;
634    
635  procedure TForm1.FormCreate(Sender: TObject);  procedure TForm1.FormCreate(Sender: TObject);
636  begin  begin
637    ClientWidth:=20*Count;    ClientWidth := 50 * Count;
638    ClientHeight:=20*Count;    ClientHeight := 50 * Count;
639    StoneGrid := TStoneGrid.Create;    StoneGrid := TStoneGrid.Create;
640    StoneGrid.ImageCount(Form1.Image1.Bitmap.Width div Form1.Image3.Bitmap.Width,    StoneGrid.ImageCount(Form1.Image1.Bitmap.Width div Form1.Image3.Bitmap.Width,
641      Form1.Image1.Bitmap.Height div Form1.Image3.Bitmap.Height);      Form1.Image1.Bitmap.Height div Form1.Image3.Bitmap.Height);

Legend:
Removed from v.30  
changed lines
  Added in v.31

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