Changeset 66
- Timestamp:
- Sep 28, 2014, 11:51:26 AM (10 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UGame.pas
r65 r66 59 59 60 60 TCellArray = array of TCell; 61 TCells = class(TObjectList) 62 63 end; 61 64 62 65 { TView } … … 201 204 Game: TGame; 202 205 Targets: TObjectList; 206 procedure Attack; 207 procedure InnerMoves; 203 208 procedure Process; 204 209 end; … … 1113 1118 end; 1114 1119 1115 procedure TComputer.Process; 1120 function CellCompare(Item1, Item2: Pointer): Integer; 1121 begin 1122 if TCell(Item1).Power > TCell(Item2).Power then Result := 1 1123 else if TCell(Item1).Power < TCell(Item2).Power then Result := -1 1124 else Result := 0; 1125 end; 1126 1127 procedure TComputer.Attack; 1116 1128 var 1117 1129 AllCells: TObjectList; 1118 1130 Cells, Cells2: TCellArray; 1119 X, Y: Integer;1120 1131 TotalPower: Integer; 1121 1132 AttackPower: Integer; … … 1124 1135 C: Integer; 1125 1136 CanAttack, CanAttack2: Integer; 1137 TargetCells: TCells; 1138 S: string; 1126 1139 const 1127 1140 AttackDiff = 2; 1128 1141 begin 1129 1142 AllCells := Game.Map.Cells; 1143 TargetCells := TCells.Create; 1144 TargetCells.OwnsObjects := False; 1145 1146 // Get list of all attack target cells 1130 1147 for C := 0 to AllCells.Count - 1 do 1131 1148 with TCell(AllCells[C]) do begin 1132 1149 if (Terrain <> ttVoid) and (Player <> Game.CurrentPlayer) then begin 1150 Cells := Game.Map.GetCellNeighbors(TCell(AllCells[C])); 1151 CanAttack := 0; 1152 for I := 0 to Length(Cells) - 1 do 1153 if (Cells[I].Player = Game.CurrentPlayer) then begin 1154 Inc(CanAttack); 1155 end; 1156 if CanAttack > 0 then TargetCells.Add(AllCells[C]); 1157 end; 1158 end; 1159 1160 // Sort ascending to attack cells with lower power first 1161 TargetCells.Sort(CellCompare); 1162 1163 for C := 0 to TargetCells.Count - 1 do 1164 with TCell(TargetCells[C]) do begin 1133 1165 // Attack to not owned cell yet 1134 1166 // Count own possible power 1135 Cells := Game.Map.GetCellNeighbors(TCell( AllCells[C]));1167 Cells := Game.Map.GetCellNeighbors(TCell(TargetCells[C])); 1136 1168 TotalPower := 0; 1137 1169 for I := 0 to Length(Cells) - 1 do … … 1148 1180 if Cells[I].GetAvialPower < AttackPower then 1149 1181 AttackPower := Cells[I].GetAvialPower; 1150 Game.SetMove(Cells[I], TCell( AllCells[C]), AttackPower);1182 Game.SetMove(Cells[I], TCell(TargetCells[C]), AttackPower); 1151 1183 TotalAttackPower := TotalAttackPower + AttackPower; 1152 1184 end; 1153 1185 end; 1154 end else 1155 if (Terrain <> ttVoid) and (Player = Game.CurrentPlayer) then begin 1186 end; 1187 1188 TargetCells.Free; 1189 end; 1190 1191 procedure TComputer.InnerMoves; 1192 var 1193 AllCells: TObjectList; 1194 Cells, Cells2: TCellArray; 1195 I, J: Integer; 1196 C: Integer; 1197 CanAttack, CanAttack2: Integer; 1198 begin 1199 AllCells := Game.Map.Cells; 1200 for C := 0 to AllCells.Count - 1 do 1201 with TCell(AllCells[C]) do begin 1202 if (Terrain <> ttVoid) and (Player = Game.CurrentPlayer) then begin 1156 1203 // Inner moves 1157 1204 // We need to move available power to borders to be available for attacks … … 1188 1235 end; 1189 1236 1237 procedure TComputer.Process; 1238 begin 1239 Attack; 1240 InnerMoves; 1241 end; 1242 1190 1243 procedure TView.SelectCell(Pos: TPoint; Player: TPlayer); 1191 1244 var -
trunk/xtactics.lpi
r62 r66 1 <?xml version="1.0" ?>1 <?xml version="1.0" encoding="UTF-8"?> 2 2 <CONFIG> 3 3 <ProjectOptions> … … 56 56 </Options> 57 57 </Linking> 58 <Other>59 <CompilerPath Value="$(CompPath)"/>60 </Other>61 58 </CompilerOptions> 62 59 </Item2> … … 68 65 <local> 69 66 <FormatVersion Value="1"/> 70 <LaunchingApplication PathPlusParams="/usr/bin/xterm -T 'Lazarus Run Output' -e $(LazarusDir)/tools/runwait.sh $(TargetCmdLine)"/>71 67 </local> 72 68 </RunParams> … … 115 111 <HasResources Value="True"/> 116 112 <ResourceBaseClass Value="Form"/> 117 <UnitName Value="UFormPlayer"/>118 113 </Unit3> 119 114 <Unit4> … … 123 118 <HasResources Value="True"/> 124 119 <ResourceBaseClass Value="Form"/> 125 <UnitName Value="UFormSettings"/>126 120 </Unit4> 127 121 <Unit5> … … 139 133 <HasResources Value="True"/> 140 134 <ResourceBaseClass Value="Form"/> 141 <UnitName Value="UFormMove"/>142 135 </Unit6> 143 136 <Unit7> … … 147 140 <HasResources Value="True"/> 148 141 <ResourceBaseClass Value="Form"/> 149 <UnitName Value="UFormNew"/>150 142 </Unit7> 151 143 <Unit8> … … 155 147 <HasResources Value="True"/> 156 148 <ResourceBaseClass Value="Form"/> 157 <UnitName Value="UFormAbout"/>158 149 </Unit8> 159 150 </Units> … … 199 190 <Other> 200 191 <CustomOptions Value="-dDEBUG"/> 201 <CompilerPath Value="$(CompPath)"/>202 192 </Other> 203 193 </CompilerOptions>
Note:
See TracChangeset
for help on using the changeset viewer.