- Timestamp:
- Sep 26, 2014, 12:05:30 AM (10 years ago)
- Location:
- trunk
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Forms/UFormMove.lfm
r42 r59 1 1 object FormMove: TFormMove 2 Left = 7702 Left = 435 3 3 Height = 257 4 Top = 4844 Top = 165 5 5 Width = 320 6 6 ActiveControl = ButtonOk … … 8 8 ClientHeight = 257 9 9 ClientWidth = 320 10 OnCreate = FormCreate 10 11 OnShow = FormShow 11 LCLVersion = '1. 3'12 LCLVersion = '1.0.10.0' 12 13 object SpinEditOnce: TSpinEdit 13 14 Left = 208 14 Height = 3215 Top = 1615 Height = 27 16 Top = 32 16 17 Width = 98 17 18 OnChange = SpinEditOnceChange … … 20 21 object Label1: TLabel 21 22 Left = 24 22 Height = 2223 Top = 1624 Width = 4623 Height = 18 24 Top = 32 25 Width = 36 25 26 Caption = 'Once:' 26 27 ParentColor = False … … 29 30 Left = 184 30 31 Height = 25 31 Top = 2 0832 Top = 224 32 33 Width = 75 33 34 Caption = 'Ok' … … 39 40 Left = 72 40 41 Height = 25 41 Top = 2 0842 Top = 224 42 43 Width = 75 43 44 Caption = 'Cancel' … … 47 48 object Label2: TLabel 48 49 Left = 24 49 Height = 2250 Top = 1 2051 Width = 8750 Height = 18 51 Top = 136 52 Width = 66 52 53 Caption = 'Every turn:' 53 54 ParentColor = False … … 55 56 object SpinEditRepeat: TSpinEdit 56 57 Left = 208 57 Height = 3258 Top = 1 1258 Height = 27 59 Top = 128 59 60 Width = 98 60 61 OnChange = SpinEditRepeatChange … … 64 65 Left = 56 65 66 Height = 43 66 Top = 5567 Top = 71 67 68 Width = 208 68 69 OnChange = TrackBarOnceChange … … 76 77 Left = 56 77 78 Height = 43 78 Top = 1 5279 Top = 168 79 80 Width = 208 80 81 OnChange = TrackBarRepeatChange … … 88 89 Left = 8 89 90 Height = 25 90 Top = 6491 Top = 80 91 92 Width = 48 92 93 Caption = 'Min' 93 OnClick = uttonOnceMinClick94 OnClick = ButtonOnceMinClick 94 95 TabOrder = 6 95 96 end … … 97 98 Left = 264 98 99 Height = 25 99 Top = 64100 Top = 80 100 101 Width = 48 101 102 Anchors = [akTop, akRight] … … 107 108 Left = 8 108 109 Height = 25 109 Top = 1 60110 Top = 176 110 111 Width = 48 111 112 Caption = 'Min' … … 116 117 Left = 264 117 118 Height = 25 118 Top = 1 60119 Top = 176 119 120 Width = 48 120 121 Anchors = [akTop, akRight] … … 123 124 TabOrder = 9 124 125 end 126 object Label3: TLabel 127 Left = 16 128 Height = 18 129 Top = 8 130 Width = 96 131 Caption = 'Win probability:' 132 ParentColor = False 133 end 134 object LabelWinProbability: TLabel 135 Left = 232 136 Height = 18 137 Top = 8 138 Width = 10 139 Caption = ' ' 140 ParentColor = False 141 end 125 142 end -
trunk/Forms/UFormMove.lrt
r42 r59 8 8 TFORMMOVE.BUTTONREPEATMIN.CAPTION=Min 9 9 TFORMMOVE.BUTTONREPEATMAX.CAPTION=Max 10 TFORMMOVE.LABEL3.CAPTION=Win probability: 11 TFORMMOVE.LABELWINPROBABILITY.CAPTION= -
trunk/Forms/UFormMove.pas
r42 r59 22 22 Label1: TLabel; 23 23 Label2: TLabel; 24 Label3: TLabel; 25 LabelWinProbability: TLabel; 24 26 SpinEditOnce: TSpinEdit; 25 27 SpinEditRepeat: TSpinEdit; … … 28 30 procedure ButtonOnceMaxClick(Sender: TObject); 29 31 procedure ButtonRepeatMinClick(Sender: TObject); 30 procedure uttonOnceMinClick(Sender: TObject); 32 procedure FormCreate(Sender: TObject); 33 procedure ButtonOnceMinClick(Sender: TObject); 31 34 procedure ButtonRepeatMaxClick(Sender: TObject); 32 35 procedure FormShow(Sender: TObject); … … 38 41 { private declarations } 39 42 public 40 { public declarations } 43 DefendCount: Integer; 44 procedure UpdateView; 41 45 end; 42 46 … … 47 51 48 52 {$R *.lfm} 53 54 uses 55 UCore; 49 56 50 57 { TFormMove } … … 62 69 end; 63 70 71 procedure TFormMove.UpdateView; 72 begin 73 LabelWinProbability.Caption := 74 IntToStr(Round(Core.Game.AttackProbability(SpinEditOnce.Value, 75 DefendCount) * 100)) + ' %'; 76 end; 77 64 78 procedure TFormMove.SpinEditOnceChange(Sender: TObject); 65 79 begin 66 80 if SpinEditOnce.Value <> TrackBarOnce.Position then 67 81 TrackBarOnce.Position := SpinEditOnce.Value; 82 UpdateView; 68 83 end; 69 84 … … 71 86 begin 72 87 ButtonOk.SetFocus; 88 UpdateView; 73 89 end; 74 90 … … 83 99 end; 84 100 85 procedure TFormMove.uttonOnceMinClick(Sender: TObject); 101 procedure TFormMove.FormCreate(Sender: TObject); 102 begin 103 104 end; 105 106 procedure TFormMove.ButtonOnceMinClick(Sender: TObject); 86 107 begin 87 108 TrackBarOnce.Position := TrackBarOnce.Min; -
trunk/Languages/xtactics.cs.po
r58 r59 190 190 msgstr "Každý tah:" 191 191 192 #: tformmove.label3.caption 193 msgid "Win probability:" 194 msgstr "" 195 196 #: tformmove.labelwinprobability.caption 197 msgid " " 198 msgstr "" 199 192 200 #: tformnew.aplayeradd.caption 193 201 msgid "Add player" -
trunk/Languages/xtactics.po
r58 r59 180 180 msgstr "" 181 181 182 #: tformmove.label3.caption 183 msgid "Win probability:" 184 msgstr "" 185 186 #: tformmove.labelwinprobability.caption 187 msgid " " 188 msgstr "" 189 182 190 #: tformnew.aplayeradd.caption 183 191 msgid "Add player" -
trunk/UCore.pas
r56 r59 88 88 FormMove.TrackBarRepeat.Max := FormMove.SpinEditRepeat.MaxValue; 89 89 FormMove.TrackBarRepeat.Position := FormMove.SpinEditRepeat.Value; 90 FormMove.DefendCount := CellTo.Power; 90 91 if FormMove.ShowModal = mrOk then begin 91 92 CountOnce := FormMove.SpinEditOnce.Value; -
trunk/UGame.pas
r58 r59 252 252 StayAliveForDefinedTurns: Integer; 253 253 MaxNeutralUnits: Integer; 254 function AttackProbability(AttackCount, DefendCount: Integer): Double; 254 255 procedure SaveConfig(Config: TXmlConfig; Path: string); 255 256 procedure LoadConfig(Config: TXmlConfig; Path: string); … … 1087 1088 { TGame } 1088 1089 1090 function ComparePointer(Item1, Item2: Pointer): Integer; 1091 begin 1092 Result := -CompareValue(Integer(Item1), Integer(Item2)); 1093 end; 1094 1089 1095 procedure TGame.Attack(var AttackPower, DefendPower: Integer); 1090 1096 var … … 1094 1100 DefenderHighestRoll: Integer; 1095 1101 RollResult: Integer; 1096 LoseCount: Integer; 1097 I: Integer; 1098 begin 1102 S: string; 1103 I: Integer; 1104 AttackRolls: TList; 1105 DefendRolls: TList; 1106 begin 1107 AttackRolls := TList.Create; 1108 DefendRolls := TList.Create; 1099 1109 if AttackPower < 1 then 1100 1110 raise Exception.Create('Attacker power have to be higher then 0.'); … … 1104 1114 // Risk game rules: 1105 1115 // Each side do their dice roll and compare result. Defender wins tie. 1106 // Attacer can use three dices and defender two 1107 if AttackPower < 3 then AttackerDiceCount := AttackPower 1108 else AttackerDiceCount := 3; 1109 if DefendPower < 2 then DefenderDiceCount := DefendPower 1110 else DefenderDiceCount := 2; 1111 // Roll and calculate each side highest number 1112 AttackerHighestRoll := 1; 1116 // Attacker can use three dices and defender two 1117 AttackerDiceCount := Min(AttackPower, 3); 1118 DefenderDiceCount := Min(DefendPower, 2); 1119 // Roll and sort numbers 1120 AttackRolls.Count := AttackerDiceCount; 1113 1121 for I := 0 to AttackerDiceCount - 1 do begin 1114 RollResult := Random(7); 1115 if RollResult > AttackerHighestRoll then 1116 AttackerHighestRoll := RollResult; 1117 end; 1118 DefenderHighestRoll := 1; 1122 AttackRolls[I] := Pointer(Random(7)); 1123 end; 1124 AttackRolls.Sort(ComparePointer); 1125 S := 'Att:'; 1126 for I := 0 to AttackerDiceCount - 1 do 1127 S := S + InTToStr(Integer(AttackRolls[I])) + ', '; 1128 DefendRolls.Count := DefenderDiceCount; 1119 1129 for I := 0 to DefenderDiceCount - 1 do begin 1120 RollResult := Random(7); 1121 if RollResult > DefenderHighestRoll then 1122 DefenderHighestRoll := RollResult; 1123 end; 1130 DefendRolls[I] := Pointer(Random(7)); 1131 end; 1132 DefendRolls.Sort(ComparePointer); 1133 S := S + ' Def:'; 1134 for I := 0 to DefenderDiceCount - 1 do 1135 S := S + IntToStr(Integer(DefendRolls[I])) + ', '; 1124 1136 // Resolution 1125 LoseCount := Min(AttackerDiceCount, DefenderDiceCount); 1126 if AttackerHighestRoll > DefenderHighestRoll then Dec(DefendPower, LoseCount) 1127 else Dec(AttackPower, LoseCount); 1128 end; 1137 for I := 0 to Min(AttackerDiceCount, DefenderDiceCount) - 1 do 1138 if AttackRolls[I] > DefendRolls[I] then Dec(DefendPower) 1139 else Dec(AttackPower); 1140 end; 1141 AttackRolls.Free; 1142 DefendRolls.Free; 1143 end; 1144 1145 function TGame.AttackProbability(AttackCount, DefendCount: Integer): Double; 1146 var 1147 OA, OD: Integer; 1148 begin 1149 if AttackCount = 0 then begin 1150 Result := 0; 1151 Exit; 1152 end else Result := 1; 1153 if DefendCount = 0 then Exit; 1154 1155 OA := Min(AttackCount, 3); 1156 OD := Min(DefendCount, 2); 1157 1158 if (OA = 1) and (OD = 1) then 1159 Result := 0.4167 * AttackProbability(AttackCount, DefendCount - 1) + 1160 0.5833 * AttackProbability(AttackCount - 1, DefendCount) 1161 else if (OA = 2) and (OD = 1) then 1162 Result := 0.5787 * AttackProbability(AttackCount, DefendCount - 1) + 1163 0.4213 * AttackProbability(AttackCount - 1, DefendCount) 1164 else if (OA = 3) and (OD = 1) then 1165 Result := 0.6597 * AttackProbability(AttackCount, DefendCount - 1) + 1166 0.3403 * AttackProbability(AttackCount - 1, DefendCount) 1167 else if (OA = 1) and (OD = 2) then 1168 Result := 0.2546 * AttackProbability(AttackCount, DefendCount - 1) + 1169 0.7454 * AttackProbability(AttackCount - 1, DefendCount) 1170 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) 1174 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); 1129 1178 end; 1130 1179 -
trunk/xtactics.lpi
r57 r59 138 138 <HasResources Value="True"/> 139 139 <ResourceBaseClass Value="Form"/> 140 <UnitName Value="UFormMove"/> 140 141 </Unit6> 141 142 <Unit7>
Note:
See TracChangeset
for help on using the changeset viewer.