Changeset 66 for trunk/UGame.pas
- Timestamp:
- Sep 28, 2014, 11:51:26 AM (10 years ago)
- File:
-
- 1 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
Note:
See TracChangeset
for help on using the changeset viewer.