Реализация игры "Шашки" на Delphi
Дипломная работа - Компьютеры, программирование
Другие дипломы по предмету Компьютеры, программирование
?ого поля, где стояло выбитая шашка. Дамка, как и обычная шашка, обязана выбить чужую шашку, если такая возможность имеется. Дамка тоже может за раз выбить несколько шашек.
Если у игрока есть возможность выбить чужие шашки в разных направлениях, то он сам выбирает какой путь выбрать.
4. Код программы
const_DOMOVE = WM_USER + 1;_DEBUG = WM_USER + 2;_IS_ANIMATION = WM_USER + 3;
GameTactics;
{$R *.DFM}
Thinker(APosition: Pointer): Integer;: TPosition;: Integer;:= TPosition(APosition^);(Position, MainForm.Deep, Estimate);(MainForm.Handle, MM_DOMOVE, Integer(@Position), Estimate);:= 0;;
TMainForm.SelectCellBtnClick(Sender: TObject);.SelectCell(1, 6);;
TMainForm.AcceptMove(Sender: TObject; const NewPosition: TPosition);: string;.AddMove(NewPosition);.SetPosition(NewPosition);:= GameOver(NewPosition);St <> '' then(St);.AcceptMove := False;;;;;
TMainForm.FormResize(Sender: TObject);.Left := 3;.Top := 3;.Left := 3;.Top := PositionFrame.Top + PositionFrame.Height + 3;.Width := ClientWidth - 6;.Height := ClientHeight - PositionFrame.Height - 9;.Left := PositionFrame.Left + PositionFrame.Width + 3;.Width := ClientWidth - PositionFrame.Width - 9;.Top := 3;.Height := PositionFrame.Height;.Columns[0].Width := 30;.Columns[1].Width := (PartyView.Width - 40) div 2;.Columns[2].Width := (PartyView.Width - 40) div 2;;
TMainForm.DoMove(var Message: TMessage);: TPosition;:= TPosition(Pointer(Message.WParam)^);(ThreadHandle);:= 0;(nil, NewPosition);;
TMainForm.FormCreate(Sender: TObject);:= mdMachineBlack;.Clear;:= True;:= TGameHistory.Create;;
procedure TMainForm.TuneState;: Boolean;: Cardinal;: Integer;: Integer;ThreadHandle -1 then:= Integer(Lib.Objects[Index]);.Lines.Add(Format('Theory = %.3f', [V/200]));;;not RunThinker then Exit;:= BeginThread(nil, 8*4096, @Thinker, @PositionFrame.Position, CREATE_SUSPENDED, ThreadId);(ThreadHandle, THREAD_PRIORITY_BELOW_NORMAL);(ThreadHandle);;
:= Pointer(Message.WPAram);.Lines.Add(Format('E=%d N=%.3f M=%s',
[Message.LParam, Message.LParam/200, GetLastMove(Position^)]));;
_LEN = 60;
TMainForm.StopThinking;(ThreadHandle, 0);(ThreadHandle);:= 0;;
TGameHistory.AddWhiteMove(const Move: string);: TListItem;:= PartyView.Items.Add;.Caption := IntToStr((MoveNo div 2) + 1);.Subitems.Add(Move);.Selected := NewItem;.Selected.MakeVisible(False);;
procedure TGameHistory.AddBlackMove(const Move: string);: TListItem;(MainForm.PartyView.Items.Count > 0);:= PartyView.Items[PartyView.Items.Count-1];.Subitems.Add(Move);.Selected := Item;.Selected.MakeVisible(False);;
TGameHistory.AddMove(NewPosition: TPosition);: string;:= GetLastMove(NewPosition);Move <> '' thenFPositions[MoveNo].Active = ActiveWhiteAddWhiteMove(Move)AddBlackMove(Move);:= MoveNo + 1;[MoveNo] := NewPosition;;
TGameHistory.NewGame;:= 0;.Items.Clear;[0] := StartBoard;.SetPosition(StartBoard);;
TGameHistory.GetPartyView: TListView;:= MainForm.PartyView;;
TGameHistory.GetPositionFrame: TPositionFrame;:= MainForm.PositionFrame;;
TGameHistory.Undo;: Integer;: TListItem;(MoveNo > 0);.ViewItem.Click;:= MoveNo - 1;.SetPosition(FPositions[MoveNo], False);:= PartyView.Items.Count-1;(Last >= 0);:= PartyView.Items[Last];Item.SubItems.Count > 1Item.SubItems.Delete(1)PartyView.Items.Delete(Last);;
TMainForm.NewGameActionExecute(Sender: TObject);;.NewGame;Mode in [mdMachineWhite, mdTwoMachine] then MachineBlackItem.Click;.AcceptMove := True;;
TMainForm.Deselect(Action: TAction; const Category: string);: Integer;I := 0 to ActionList.ActionCount - 1 doActionList.Actions[I].Category <> Category then Continue;ActionList.Actions[I] = Action then Continue;
(ActionList.Actions[I] as TAction).Checked := False;;;
TMainForm.LevelActionExecute(Sender: TObject);(Sender as TAction, 'Level');Sender as TAction do:= True;:= Tag;;;
procedure TMainForm.UndoMoveActionExecute(Sender: TObject);.Undo;;
TMainForm.ActionListUpdate(Action: TBasicAction;Handled: Boolean);.Enabled := GameHistory.MoveNo > 0;;
TMainForm.ExitActionExecute(Sender: TObject);.Click;;;
TMainForm.MachineWhiteActionExecute(Sender: TObject);(Sender as TAction, 'Mode');
(Sender as TAction).Checked := True;Mode = mdMachineWhite then Exit;:= mdMachineWhite;.FlipBoard := True;;;
TMainForm.MachineBlackActionExecute(Sender: TObject);(Sender as TAction, 'Mode');
(Sender as TAction).Checked := True;Mode = mdMachineBlack then Exit;:= mdMachineBlack;.FlipBoard := False;;;
TMainForm.TwoMachineActionExecute(Sender: TObject);(Sender as TAction, 'Mode');
(Sender as TAction).Checked := True;Mode = mdTwoMachine then Exit;:= mdTwoMachine;;;
TMainForm.ViewGameActionExecute(Sender: TObject);(Sender as TAction, 'Mode');
(Sender as TAction).Checked := True;Mode = mdView then Exit;:= mdView;.Checked := True;ThreadHandle <> 0 then StopThinking;;
TMainForm.SetPositionActionExecute(Sender: TObject);: TPosition;.Click;(Position.Field, 32, $00);.Field[31] := -20;.Field[29] := 70;.Active := ActiveWhite;
// Position.Field[0] := 20;
// Position.Field[2] := -70;
// Position.Active := ActiveBlack;.MoveCount := 0;.SetPosition(Position);;
TMainForm.AddToLibraryActionExecute(Sender: TObject);: Integer;: string;: string;: Integer;:= '.';:= InputBox('Input', 'Please, enter estimate', '');Estimate = '' then Exit;:= StringReplace(Estimate, ',', '.', []);:= Round(200 * StrToFloat(Estimate));:= FormatPosition(PositionFrame.Position);:= Lib.IndexOf(PositionFmt);Index = -1 then.AddObject(PositionFmt, TObject(V))begin.Sorted := False;[Index] := PositionFmt;.Objects[Index] := TObject(V);.Sorted := True;;;;
TMainForm.CopyGameActionExecute(Sender: TObject);: Integer;: TListItem;: string;: TStringList;
Add(const St: string);Length(CurrentSt) + Length(St) + 1 > MAX_LEN then.Add(CurrentSt);:= '';;CurrentSt <> '' then CurrentSt := CurrentSt + ' ';:= CurrentSt + St;;
:= TStringList.Create;:= '';MoveNo := 0 to PartyView.Items.Count-1 do:= PartyView.Items[MoveNo];(Item.Caption + '.');(Item.SubItems[0]);Item.SubItems.Count > 1 then(Item.SubItems[1]);;CurrentSt <> '' then AllParty.Add(CurrentSt);.AsText := AllParty.Text;.Free;;;.
TPositionFrame.BeginDebug;
{$IFDEF SELECT_DEBUG}Assigned(Debug) then.BeginUpdate;.Clear;;
{$ENDIF};
TPositionFrame.EndDebug;
{$IFDEF SELECT_DEBUG}Assigned(Debug) then Debug.EndUpdate;
{$ENDIF};
TPositionFrame.OutputDebug(const St: string);
{$IFDEF SELECT_DEBUG}.Add(St);
{$ENDIF};
TPositionFrame.OutputDebug(const St: string; const Args: array of const);
{$IFDEF SELECT_DEBUG}(Format(St, Args));
{$ENDIF};
TPositionFrame.OutputDebugSelectMove;
{$IFDEF SELECT_DEBUG}, J: Integer;: string;
{$ENDIF}
{$IFDEF SELECT_DEBUG}('Возможные хода:');I := 0 to FAnswersCount - 1 do:= PointsDef[FAnswers[I].MoveStr[0]];:= 1;FAnswers[I].MoveStr[J] = -1 then Break;:= St + FAnswers[I].TakeChar + PointsDef[FAnswers[I].MoveStr[J]];:= J + 1;False;('(%d) %s', [I, St]);;('');:= '';I := 0 to 31 doFSelectedCells[I] then St := ' ' + PointsDef[I];('Selected =' + St);:= '';I := 0 to FAnswersCount-1 do:= St + Format(' %d(%d)', [FEnabledAnswer[I], I]);('EnabledAnswer =' + St);:= '';I := 0 to FUserSelectCount-1 do:= St + ' ' + PointsDef[FUserSelect[I]];('UserSelect =' + St);
{$ENDIF};
TPositionFrame.CellToField(X, Y: Integer): Integer;FlipBoardResult := 4*Y + (7-X) div 2Result := 28 - 4*Y + (X div 2);;
procedure TPositionFrame.ClearSelect;:= -1;;;
TPositionFrame.DrawField(X, Y, Index: Integer);.Draw(Image.Canvas, X*ImageList.Width, Y*ImageList.Height, Index);;
TPositionFrame.IsWhite(X, Y: Integer): Boolean;:= ((X xor Y) and 1) = 0;;
TPositionFrame.Loaded;;:= -1;;
TPositionFrame.RefreshView;, Y: Integer;, X2, Y1, Y2: Integer;, Q: Single;: Integer;: PPosition;AnimateOutPosition := @FAnimatePositionOutPosition := @FPosition; := 8 * ImageList.Width;:= 8 * ImageList.Height;Y := 0 to 7 doX := 0 to 7 doIsWhite(X, Y) then(X, Y, 0)begin:= CellToField(X, Y);Animate and (Position.MoveStr[0] = FieldIndex) then(X, Y, 1)OutPosition.Field[FieldIndex] of: DrawField(X, Y, 2);: DrawField(X, Y, 3);: DrawField(X, Y, 4);: DrawField(X, Y, 5);: DrawField(X, Y, 1)DrawField(X, Y, 6);FSelectedCells[FieldIndex] then.Canvas.Brush.Style := bsClear;.Canvas.Pen.Width := 1;.Canvas.Pen.Color := clGreen;.Canvas.Rectangle(CellRect(X, Y));.Canvas.Rectangle(CellRect(X, Y, -1));;;Animate thenFlipBoard then:= ImageList.Width * (7 - FAnimateWay[FAnimateStep-1] mod 8);:= ImageList.Height * (FAnimateWay[FAnimateStep-1] div 8);:= ImageList.Width * (7 - FAnimateWay[FAnimateStep] mod 8);:= ImageList.Height * (FAnimateWay[FAnimateStep] div 8);begin:= ImageList.Width * (FAnimateWay[FAnimateStep-1] mod 8);:= ImageList.Height * (7 - FAnimateWay[FAnimateStep-1] div 8);:= ImageList.Width * (FAnimateWay[FAnimateStep] mod 8);:= ImageList.Height * (7 - FAnimateWay[FA