| 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; |
FEffectStone: TStoneType; |
| 42 |
FBool: Boolean; |
FBool: Boolean; |
| 43 |
FTerminated: Boolean; |
FTerminated: Boolean; |
| 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; |
| 104 |
procedure MenuItem10Click(Sender: TObject); |
procedure MenuItem10Click(Sender: TObject); |
| 105 |
procedure MenuItem11Click(Sender: TObject); |
procedure MenuItem11Click(Sender: TObject); |
| 106 |
procedure Timer2Timer(Sender: TObject); |
procedure Timer2Timer(Sender: TObject); |
| 107 |
|
procedure FormDeactivate(Sender: TObject); |
| 108 |
|
procedure FormActivate(Sender: TObject); |
| 109 |
private |
private |
| 110 |
{ Private 宣言 } |
{ Private 宣言 } |
| 111 |
StoneGrid: TStoneGrid; |
StoneGrid: TStoneGrid; |
| 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 |
case Stone of |
if Stone = stEffect then |
|
stBlack: |
|
|
Stone := stWhite; |
|
|
stWhite: |
|
|
Stone := stBlack; |
|
|
stEffect: |
|
| 141 |
Stone := FEffectStone; |
Stone := FEffectStone; |
| 142 |
|
case Stone of |
| 143 |
|
stBlack: |
| 144 |
|
Stone := stWhite; |
| 145 |
|
stWhite: |
| 146 |
|
Stone := stBlack; |
| 147 |
|
else |
| 148 |
|
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; |
| 173 |
begin |
begin |
| 174 |
s := GetStrings(X + m * i, Y + n * i); |
s := GetStrings(X + m * i, Y + n * i); |
| 175 |
if s = stEffect then |
if s = stEffect then |
| 176 |
s:=FEffectStone; |
s := FEffectStone; |
| 177 |
if (s = stNone) or (s = stError) then |
if (s = stNone) or (s = stError) then |
| 178 |
break |
break |
| 179 |
else if s = Stone then |
else if s = Stone then |
| 189 |
Form1.PaintBox1.Repaint; |
Form1.PaintBox1.Repaint; |
| 190 |
if Visible = true then |
if Visible = true then |
| 191 |
begin |
begin |
| 192 |
FEffectStone:=Stone; |
FEffectStone := Stone; |
| 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 |
List.Add(q); |
FList.Add(q); |
| 199 |
SetStrings(q^.Left, q^.Top, stEffect); |
SetStrings(q^.Left, q^.Top, stEffect); |
| 200 |
for k := 1 to 100 do |
for k := 1 to 100 do |
| 201 |
begin |
begin |
| 246 |
var |
var |
| 247 |
i, j: integer; |
i, j: integer; |
| 248 |
begin |
begin |
| 249 |
|
for i := 0 to FList.Count - 1 do |
| 250 |
|
Dispose(FList[i]); |
| 251 |
|
FList.Clear; |
| 252 |
for i := 0 to Count - 1 do |
for i := 0 to Count - 1 do |
| 253 |
for j := 0 to Count - 1 do |
for j := 0 to Count - 1 do |
| 254 |
Strings[i, j] := stNone; |
Strings[i, j] := stNone; |
| 264 |
constructor TStoneGrid.Create; |
constructor TStoneGrid.Create; |
| 265 |
begin |
begin |
| 266 |
inherited; |
inherited; |
| 267 |
List := TList.Create; |
FList := TList.Create; |
| 268 |
end; |
end; |
| 269 |
|
|
| 270 |
destructor TStoneGrid.Destroy; |
destructor TStoneGrid.Destroy; |
| 271 |
var |
var |
| 272 |
i: integer; |
i: integer; |
| 273 |
begin |
begin |
| 274 |
for i := 0 to List.Count - 1 do |
for i := 0 to FList.Count - 1 do |
| 275 |
Dispose(List[i]); |
Dispose(FList[i]); |
| 276 |
List.Free; |
FList.Free; |
| 277 |
inherited; |
inherited; |
| 278 |
end; |
end; |
| 279 |
|
|
| 296 |
p: ^TEffectData; |
p: ^TEffectData; |
| 297 |
i: integer; |
i: integer; |
| 298 |
begin |
begin |
| 299 |
if List.Count = 0 then |
if FList.Count = 0 then |
| 300 |
result := false |
result := false |
| 301 |
else |
else |
| 302 |
begin |
begin |
| 303 |
for i := 0 to List.Count - 1 do |
for i := 0 to FList.Count - 1 do |
| 304 |
begin |
begin |
| 305 |
p := List.List[i]; |
p := FList[i]; |
| 306 |
if p^.X < FIndex_X - 1 then |
if p^.X < FIndex_X - 1 then |
| 307 |
p^.X := p^.X + 1 |
p^.X := p^.X + 1 |
| 308 |
else if p^.Y < FIndex_Y - 1 then |
else if p^.Y < FIndex_Y - 1 then |
| 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 |
List[i] := nil; |
FList[i] := nil; |
| 318 |
end; |
end; |
| 319 |
end; |
end; |
| 320 |
for i := List.Count - 1 downto 0 do |
for i := FList.Count - 1 downto 0 do |
| 321 |
if List[i] = nil then |
if FList[i] = nil then |
| 322 |
List.Delete(i); |
FList.Delete(i); |
| 323 |
if List.Count = 0 then |
if FList.Count = 0 then |
| 324 |
begin |
begin |
| 325 |
if FTerminated = true then |
if FTerminated = true then |
| 326 |
FActive:=false |
FActive := false |
| 327 |
else |
else |
| 328 |
FActive := FBool; |
FActive := FBool; |
| 329 |
inc(FTurnIndex); |
inc(FTurnIndex); |
| 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); |
| 362 |
m := Form1.Image3.Bitmap.Width; |
m := Form1.Image3.Bitmap.Width; |
| 363 |
n := Form1.Image3.Bitmap.Height; |
n := Form1.Image3.Bitmap.Height; |
| 364 |
k := Form1.Size; |
k := Form1.Size; |
| 365 |
for i := 0 to List.Count - 1 do |
for i := 0 to FList.Count - 1 do |
| 366 |
begin |
begin |
| 367 |
p := List[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; |
| 377 |
|
|
| 378 |
procedure TStoneGrid.Pause; |
procedure TStoneGrid.Pause; |
| 379 |
begin |
begin |
| 380 |
FTerminated:=true; |
FActive := false; |
| 381 |
|
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); |
| 408 |
procedure TStoneGrid.Start; |
procedure TStoneGrid.Start; |
| 409 |
begin |
begin |
| 410 |
Clear; |
Clear; |
| 411 |
FTerminated:=false; |
FTerminated := false; |
| 412 |
FActive := true; |
FActive := true; |
| 413 |
end; |
end; |
| 414 |
|
|
| 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 |
| 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; |
| 498 |
Index := Player1; |
Index := Player1; |
| 499 |
StoneGrid.Start; |
StoneGrid.Start; |
| 500 |
PaintBox1.Repaint; |
PaintBox1.Repaint; |
| 501 |
Caption := '黒から始めます'; |
Caption := '黒から始めます'; |
| 502 |
|
Timer1.Enabled := true; |
| 503 |
end; |
end; |
| 504 |
|
|
| 505 |
procedure TForm1.MenuItem10Click(Sender: TObject); |
procedure TForm1.MenuItem10Click(Sender: TObject); |
| 589 |
Size := Min(ClientWidth, ClientHeight) div Count; |
Size := Min(ClientWidth, ClientHeight) div Count; |
| 590 |
end; |
end; |
| 591 |
|
|
| 592 |
|
procedure TForm1.FormActivate(Sender: TObject); |
| 593 |
|
begin |
| 594 |
|
Timer1.Enabled := true; |
| 595 |
|
end; |
| 596 |
|
|
| 597 |
procedure TForm1.FormCreate(Sender: TObject); |
procedure TForm1.FormCreate(Sender: TObject); |
| 598 |
begin |
begin |
| 599 |
StoneGrid := TStoneGrid.Create; |
StoneGrid := TStoneGrid.Create; |
| 614 |
GameStart; |
GameStart; |
| 615 |
end; |
end; |
| 616 |
|
|
| 617 |
|
procedure TForm1.FormDeactivate(Sender: TObject); |
| 618 |
|
begin |
| 619 |
|
Timer1.Enabled := false; |
| 620 |
|
end; |
| 621 |
|
|
| 622 |
procedure TForm1.FormDestroy(Sender: TObject); |
procedure TForm1.FormDestroy(Sender: TObject); |
| 623 |
begin |
begin |
| 624 |
StoneGrid.Free; |
StoneGrid.Free; |
| 640 |
|
|
| 641 |
procedure TForm1.Timer2Timer(Sender: TObject); |
procedure TForm1.Timer2Timer(Sender: TObject); |
| 642 |
begin |
begin |
| 643 |
if (StoneGrid.Active = false)and(StoneGrid.ListExecute = true) then |
if (StoneGrid.Active = false) and (StoneGrid.ListExecute = true) then |
| 644 |
PaintBox1.Repaint; |
PaintBox1.Repaint; |
| 645 |
end; |
end; |
| 646 |
|
|