Changeset 60


Ignore:
Timestamp:
Sep 26, 2014, 12:27:50 AM (10 years ago)
Author:
chronos
Message:
  • Fixed: Limited depth of win probability calculation.
  • Fixed: Show probability using sum of all attacking units from multiple cells.
Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Forms/UFormMove.pas

    r59 r60  
    4242  public
    4343    DefendCount: Integer;
     44    AttackCount: Integer;
    4445    procedure UpdateView;
    4546  end;
     
    7273begin
    7374  LabelWinProbability.Caption :=
    74     IntToStr(Round(Core.Game.AttackProbability(SpinEditOnce.Value,
    75     DefendCount) * 100)) + ' %';
     75    IntToStr(Round(Core.Game.AttackProbability(AttackCount + SpinEditOnce.Value,
     76    DefendCount, 1) * 100)) + ' %';
    7677end;
    7778
  • trunk/UCore.pas

    r59 r60  
    8989  FormMove.TrackBarRepeat.Position := FormMove.SpinEditRepeat.Value;
    9090  FormMove.DefendCount := CellTo.Power;
     91  FormMove.AttackCount := CellTo.GetAttackPower;
    9192  if FormMove.ShowModal = mrOk then begin
    9293    CountOnce := FormMove.SpinEditOnce.Value;
  • trunk/UGame.pas

    r59 r60  
    5050    function GetColor: TColor;
    5151    function GetAvialPower: Integer;
     52    function GetAttackPower: Integer;
    5253    constructor Create;
    5354    destructor Destroy; override;
     
    252253    StayAliveForDefinedTurns: Integer;
    253254    MaxNeutralUnits: Integer;
    254     function AttackProbability(AttackCount, DefendCount: Integer): Double;
     255    function AttackProbability(AttackCount, DefendCount, Depth: Integer): Double;
    255256    procedure SaveConfig(Config: TXmlConfig; Path: string);
    256257    procedure LoadConfig(Config: TXmlConfig; Path: string);
     
    899900    Result := Result - TUnitMove(MovesFrom[I]).CountOnce;
    900901  if Result < 0 then Result := 0;
     902end;
     903
     904function TCell.GetAttackPower: Integer;
     905var
     906  I: Integer;
     907begin
     908  Result := 0;
     909  for I := 0 to MovesTo.Count - 1 do
     910    Result := Result + TUnitMove(MovesTo[I]).CountOnce;
    901911end;
    902912
     
    11431153end;
    11441154
    1145 function TGame.AttackProbability(AttackCount, DefendCount: Integer): Double;
     1155function TGame.AttackProbability(AttackCount, DefendCount, Depth: Integer): Double;
    11461156var
    11471157  OA, OD: Integer;
     
    11521162  end else Result := 1;
    11531163  if DefendCount = 0 then Exit;
     1164  if Depth > 5 then Exit;
    11541165
    11551166  OA := Min(AttackCount, 3);
     
    11571168
    11581169  if (OA = 1) and (OD = 1) then
    1159     Result := 0.4167 * AttackProbability(AttackCount, DefendCount - 1) +
    1160       0.5833 * AttackProbability(AttackCount - 1, DefendCount)
     1170    Result := 0.4167 * AttackProbability(AttackCount, DefendCount - 1, Depth + 1) +
     1171      0.5833 * AttackProbability(AttackCount - 1, DefendCount, Depth + 1)
    11611172  else if (OA = 2) and (OD = 1) then
    1162     Result := 0.5787 * AttackProbability(AttackCount, DefendCount - 1) +
    1163       0.4213 * AttackProbability(AttackCount - 1, DefendCount)
     1173    Result := 0.5787 * AttackProbability(AttackCount, DefendCount - 1, Depth + 1) +
     1174      0.4213 * AttackProbability(AttackCount - 1, DefendCount, Depth + 1)
    11641175  else if (OA = 3) and (OD = 1) then
    1165     Result := 0.6597 * AttackProbability(AttackCount, DefendCount - 1) +
    1166       0.3403 * AttackProbability(AttackCount - 1, DefendCount)
     1176    Result := 0.6597 * AttackProbability(AttackCount, DefendCount - 1, Depth + 1) +
     1177      0.3403 * AttackProbability(AttackCount - 1, DefendCount, Depth + 1)
    11671178  else if (OA = 1) and (OD = 2) then
    1168     Result := 0.2546 * AttackProbability(AttackCount, DefendCount - 1) +
    1169       0.7454 * AttackProbability(AttackCount - 1, DefendCount)
     1179    Result := 0.2546 * AttackProbability(AttackCount, DefendCount - 1, Depth + 1) +
     1180      0.7454 * AttackProbability(AttackCount - 1, DefendCount, Depth + 1)
    11701181  else if (OA = 2) and (OD = 2) then
    1171     Result := 0.2276 * AttackProbability(AttackCount, DefendCount - 2) +
    1172       0.4483 * AttackProbability(AttackCount - 2, DefendCount) +
    1173       0.3241 * AttackProbability(AttackCount - 1, DefendCount - 1)
     1182    Result := 0.2276 * AttackProbability(AttackCount, DefendCount - 2, Depth + 1) +
     1183      0.4483 * AttackProbability(AttackCount - 2, DefendCount, Depth + 1) +
     1184      0.3241 * AttackProbability(AttackCount - 1, DefendCount - 1, Depth + 1)
    11741185  else if (OA = 3) and (OD = 2) then
    1175     Result := 0.3717 * AttackProbability(AttackCount, DefendCount - 2) +
    1176       0.2926 * AttackProbability(AttackCount - 2, DefendCount) +
    1177       0.3358 * AttackProbability(AttackCount - 1, DefendCount - 1);
     1186    Result := 0.3717 * AttackProbability(AttackCount, DefendCount - 2, Depth + 1) +
     1187      0.2926 * AttackProbability(AttackCount - 2, DefendCount, Depth + 1) +
     1188      0.3358 * AttackProbability(AttackCount - 1, DefendCount - 1, Depth + 1);
    11781189end;
    11791190
Note: See TracChangeset for help on using the changeset viewer.