| 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; |
| 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; |
| 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 |
| 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 |
| 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 |
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); |
| 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 |
| 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); |
| 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 |
|
|
| 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 |
| 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 |
|
|
| 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 |
|
|