| 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; |
| 37 |
FTurnNumber: integer; |
FTurnNumber: integer; |
| 38 |
FTurnIndex: integer; |
FTurnIndex: integer; |
| 39 |
FActive: Boolean; |
FActive: Boolean; |
| 40 |
List: TList; |
FList: TList; |
| 41 |
|
FEffectStone: TStoneType; |
| 42 |
FBool: Boolean; |
FBool: Boolean; |
| 43 |
|
FTerminated: Boolean; |
| 44 |
FIndex_X: integer; |
FIndex_X: integer; |
| 45 |
FIndex_Y: integer; |
FIndex_Y: integer; |
| 46 |
function GetStrings(X, Y: integer): TStoneType; |
function GetStrings(X, Y: integer): TStoneType; |
| 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; |
| 134 |
begin |
begin |
| 135 |
if CanSetStone(Stone, X, Y, true) = true then |
if CanSetStone(Stone, X, Y, true) = true then |
| 136 |
begin |
begin |
|
if Stone = stBlack then |
|
|
Stone := stWhite |
|
|
else |
|
|
Stone := stBlack; |
|
| 137 |
result := 0; |
result := 0; |
| 138 |
|
case Stone of |
| 139 |
|
stBlack: |
| 140 |
|
Stone := stWhite; |
| 141 |
|
stWhite: |
| 142 |
|
Stone := stBlack; |
| 143 |
|
end; |
| 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; |
| 168 |
while true do |
while true do |
| 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 |
| 172 |
|
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 |
| 185 |
Form1.PaintBox1.Repaint; |
Form1.PaintBox1.Repaint; |
| 186 |
if Visible = true then |
if Visible = true then |
| 187 |
begin |
begin |
| 188 |
|
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 10 do |
for k := 1 to 100 do |
| 197 |
begin |
begin |
| 198 |
Sleep(10); |
Sleep(1); |
| 199 |
Application.ProcessMessages; |
Application.ProcessMessages; |
| 200 |
end; |
end; |
| 201 |
end |
end |
| 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; |
| 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 |
|
|
| 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 |
| 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 |
FActive := FBool; |
if FTerminated = true then |
| 322 |
|
FActive := false |
| 323 |
|
else |
| 324 |
|
FActive := FBool; |
| 325 |
inc(FTurnIndex); |
inc(FTurnIndex); |
| 326 |
inc(FTurnNumber); |
inc(FTurnNumber); |
| 327 |
FBuffer[FTurnIndex] := FStrings; |
FBuffer[FTurnIndex] := FStrings; |
| 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 |
| 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); |
| 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; |
| 373 |
|
|
| 374 |
procedure TStoneGrid.Pause; |
procedure TStoneGrid.Pause; |
| 375 |
begin |
begin |
|
FBool := false; |
|
| 376 |
FActive := false; |
FActive := false; |
| 377 |
|
FTerminated := true; |
| 378 |
end; |
end; |
| 379 |
|
|
| 380 |
procedure TStoneGrid.Restart; |
procedure TStoneGrid.Restart; |
| 381 |
begin |
begin |
| 382 |
FActive := true; |
FActive := true; |
| 383 |
FTurnIndex := FTurnNumber; |
FTurnIndex := FTurnNumber; |
| 384 |
|
FTerminated := false; |
| 385 |
end; |
end; |
| 386 |
|
|
| 387 |
procedure TStoneGrid.SetStrings(X, Y: integer; const Value: TStoneType); |
procedure TStoneGrid.SetStrings(X, Y: integer; const Value: TStoneType); |
| 398 |
FTurnNumber := 0 |
FTurnNumber := 0 |
| 399 |
else |
else |
| 400 |
FTurnNumber := Value; |
FTurnNumber := Value; |
|
FActive := false; |
|
| 401 |
FStrings := FBuffer[FTurnNumber]; |
FStrings := FBuffer[FTurnNumber]; |
| 402 |
end; |
end; |
| 403 |
|
|
| 404 |
procedure TStoneGrid.Start; |
procedure TStoneGrid.Start; |
| 405 |
begin |
begin |
| 406 |
Clear; |
Clear; |
| 407 |
|
FTerminated := false; |
| 408 |
FActive := true; |
FActive := true; |
| 409 |
end; |
end; |
| 410 |
|
|
| 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 |
| 435 |
|
for j := 0 to Count - 1 do |
| 436 |
|
if StoneGrid.CanSetStone(Index.Stone, i, j, false) = true then |
| 437 |
|
begin |
| 438 |
|
result := true; |
| 439 |
|
Exit; |
| 440 |
|
end; |
| 441 |
result := false; |
result := false; |
|
with StoneGrid do |
|
|
for i := 0 to Count - 1 do |
|
|
for j := 0 to Count - 1 do |
|
|
if CanSetStone(Index.Stone, i, j, false) = true then |
|
|
begin |
|
|
for m := 0 to Count - 1 do |
|
|
for n := 0 to Count - 1 do |
|
|
if GetStrings(m, n) <> Index.Stone then |
|
|
begin |
|
|
result := true; |
|
|
Exit; |
|
|
end; |
|
|
result := false; |
|
|
end; |
|
| 442 |
end; |
end; |
| 443 |
|
|
| 444 |
begin |
begin |
| 448 |
Main; |
Main; |
| 449 |
if Execute = false then |
if Execute = false then |
| 450 |
begin |
begin |
|
Timer1.Enabled := false; |
|
| 451 |
StoneGrid.Pause; |
StoneGrid.Pause; |
| 452 |
m := 0; |
m := 0; |
| 453 |
n := 0; |
n := 0; |
| 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 |
|
|
| 491 |
procedure TForm1.GameStart; |
procedure TForm1.GameStart; |
| 492 |
begin |
begin |
| 493 |
|
Index := Player1; |
| 494 |
StoneGrid.Start; |
StoneGrid.Start; |
| 495 |
PaintBox1.Repaint; |
PaintBox1.Repaint; |
|
Index := Player1; |
|
| 496 |
Caption := '黒から始めます'; |
Caption := '黒から始めます'; |
|
Timer1.Enabled := true; |
|
| 497 |
end; |
end; |
| 498 |
|
|
| 499 |
procedure TForm1.MenuItem10Click(Sender: TObject); |
procedure TForm1.MenuItem10Click(Sender: TObject); |
| 500 |
begin |
begin |
| 501 |
StoneGrid.Restart; |
StoneGrid.Restart; |
|
Timer1.Enabled := true; |
|
| 502 |
end; |
end; |
| 503 |
|
|
| 504 |
procedure TForm1.MenuItem11Click(Sender: TObject); |
procedure TForm1.MenuItem11Click(Sender: TObject); |
| 535 |
begin |
begin |
| 536 |
Player1.Auto := MenuItem6.IsChecked; |
Player1.Auto := MenuItem6.IsChecked; |
| 537 |
Player2.Auto := MenuItem7.IsChecked; |
Player2.Auto := MenuItem7.IsChecked; |
|
MenuItem10Click(Sender); |
|
| 538 |
end; |
end; |
| 539 |
|
|
| 540 |
procedure TForm1.MenuItem8Click(Sender: TObject); |
procedure TForm1.MenuItem8Click(Sender: TObject); |
| 546 |
var |
var |
| 547 |
i, j: integer; |
i, j: integer; |
| 548 |
begin |
begin |
| 549 |
|
if StoneGrid.Active = false then |
| 550 |
|
StoneGrid.Paint(Canvas); |
| 551 |
for i := 0 to Count - 1 do |
for i := 0 to Count - 1 do |
| 552 |
begin |
begin |
| 553 |
for j := 0 to Count - 1 do |
for j := 0 to Count - 1 do |
| 576 |
PointF(Count * Size, Count * Size), 1); |
PointF(Count * Size, Count * Size), 1); |
| 577 |
Canvas.DrawLine(PointF(0, Count * Size), |
Canvas.DrawLine(PointF(0, Count * Size), |
| 578 |
PointF(Count * Size, Count * Size), 1); |
PointF(Count * Size, Count * Size), 1); |
|
if StoneGrid.Active = false then |
|
|
StoneGrid.Paint(Canvas); |
|
| 579 |
end; |
end; |
| 580 |
|
|
| 581 |
procedure TForm1.PaintBox1Resize(Sender: TObject); |
procedure TForm1.PaintBox1Resize(Sender: TObject); |
| 619 |
procedure TForm1.Timer1Timer(Sender: TObject); |
procedure TForm1.Timer1Timer(Sender: TObject); |
| 620 |
begin |
begin |
| 621 |
if (StoneGrid.Active = true) and (Index.Auto = true) then |
if (StoneGrid.Active = true) and (Index.Auto = true) then |
|
begin |
|
|
Timer1.Enabled := false; |
|
| 622 |
CompStone; |
CompStone; |
|
Timer1.Enabled := true; |
|
|
end; |
|
| 623 |
end; |
end; |
| 624 |
|
|
| 625 |
procedure TForm1.Timer2Timer(Sender: TObject); |
procedure TForm1.Timer2Timer(Sender: TObject); |
| 626 |
begin |
begin |
| 627 |
if StoneGrid.ListExecute = true then |
if (StoneGrid.Active = false) and (StoneGrid.ListExecute = true) then |
| 628 |
PaintBox1.Repaint; |
PaintBox1.Repaint; |
| 629 |
end; |
end; |
| 630 |
|
|