Changeset 223 for trunk/UClientAI.pas
- Timestamp:
- Jul 14, 2018, 7:21:43 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UClientAI.pas
r222 r223 23 23 procedure Process; 24 24 procedure FallBack; 25 function AttackersCount(Cell: T Cell): Integer;25 function AttackersCount(Cell: TPlayerCell): Integer; 26 26 end; 27 27 … … 39 39 procedure TComputer.AttackNeutral; 40 40 var 41 AllCells: T Cells;41 AllCells: TPlayerCells; 42 42 TotalPower: Integer; 43 43 AttackPower: Integer; 44 44 TotalAttackPower: Integer; 45 45 CanAttack: Integer; 46 TargetCells: T Cells;47 Cell: T Cell;48 NeighborCell: T Cell;46 TargetCells: TPlayerCells; 47 Cell: TPlayerCell; 48 NeighborCell: TPlayerCell; 49 49 const 50 50 AttackDiff = 1; 51 51 begin 52 AllCells := Game.Map.Cells;53 TargetCells := T Cells.Create;52 AllCells := ControlPlayer.PlayerMap.Cells; 53 TargetCells := TPlayerCells.Create; 54 54 TargetCells.FreeObjects := False; 55 55 … … 57 57 for Cell in AllCells do 58 58 with Cell do begin 59 if ( Terrain <> ttVoid) and (Player = nil) then begin59 if (MapCell.Terrain <> ttVoid) and (MapCell.Player = nil) then begin 60 60 CanAttack := 0; 61 61 for NeighborCell in Neighbors do 62 if NeighborCell. Player = ControlPlayer then begin62 if NeighborCell.MapCell.Player = ControlPlayer then begin 63 63 Inc(CanAttack); 64 64 end; … … 77 77 TotalPower := 0; 78 78 for NeighborCell in Neighbors do 79 if NeighborCell. Player = ControlPlayer then79 if NeighborCell.MapCell.Player = ControlPlayer then 80 80 TotalPower := TotalPower + NeighborCell.GetAvialPower; 81 81 82 82 // Attack if target is weaker 83 if TotalPower >= ( Power + AttackDiff) then begin83 if TotalPower >= (MapCell.Power + AttackDiff) then begin 84 84 TotalAttackPower := 0; 85 85 for NeighborCell in Neighbors do 86 if NeighborCell. Player = ControlPlayer then begin86 if NeighborCell.MapCell.Player = ControlPlayer then begin 87 87 // Use only necessary power 88 AttackPower := Power - TotalAttackPower + AttackDiff;88 AttackPower := MapCell.Power - TotalAttackPower + AttackDiff; 89 89 if NeighborCell.GetAvialPower < AttackPower then 90 90 AttackPower := NeighborCell.GetAvialPower; … … 100 100 procedure TComputer.AttackPlayers; 101 101 var 102 AllCells: T Cells;102 AllCells: TPlayerCells; 103 103 TotalPower: Integer; 104 104 AttackPower: Integer; 105 105 TotalAttackPower: Integer; 106 106 CanAttack: Integer; 107 TargetCells: T Cells;108 TargetCell: T Cell;109 NeighborCell: T Cell;107 TargetCells: TPlayerCells; 108 TargetCell: TPlayerCell; 109 NeighborCell: TPlayerCell; 110 110 begin 111 111 if ControlPlayer.Defensive then Exit; 112 112 113 AllCells := Game.Map.Cells;114 TargetCells := T Cells.Create;113 AllCells := ControlPlayer.PlayerMap.Cells; 114 TargetCells := TPlayerCells.Create; 115 115 TargetCells.FreeObjects := False; 116 116 117 117 // Get list of all attack target cells 118 118 for TargetCell in AllCells do begin 119 if (TargetCell. Terrain <> ttVoid) and (TargetCell.Player <> ControlPlayer) and120 (TargetCell. Player <> nil) then begin119 if (TargetCell.MapCell.Terrain <> ttVoid) and (TargetCell.MapCell.Player <> ControlPlayer) and 120 (TargetCell.MapCell.Player <> nil) then begin 121 121 CanAttack := 0; 122 122 for NeighborCell in TargetCell.Neighbors do 123 if NeighborCell. Player = ControlPlayer then begin123 if NeighborCell.MapCell.Player = ControlPlayer then begin 124 124 Inc(CanAttack); 125 125 end; … … 137 137 TotalPower := 0; 138 138 for NeighborCell in TargetCell.Neighbors do 139 if NeighborCell. Player = ControlPlayer then begin139 if NeighborCell.MapCell.Player = ControlPlayer then begin 140 140 TotalPower := TotalPower + NeighborCell.GetAvialPower; 141 141 end; 142 142 // Attack if target is weaker 143 if Game.AttackProbability(TotalPower, TargetCell. Power) >=143 if Game.AttackProbability(TotalPower, TargetCell.MapCell.Power) >= 144 144 ComputerAggroProbability[ControlPlayer.Agressivity] then begin 145 145 // Try to limit total attacking power to necessary minimum 146 while Game.AttackProbability(TotalPower - 1, TargetCell. Power) >=146 while Game.AttackProbability(TotalPower - 1, TargetCell.MapCell.Power) >= 147 147 ComputerAggroProbability[ControlPlayer.Agressivity] do 148 148 Dec(TotalPower); … … 151 151 TotalAttackPower := 0; 152 152 for NeighborCell in TargetCell.Neighbors do 153 if NeighborCell. Player = ControlPlayer then begin153 if NeighborCell.MapCell.Player = ControlPlayer then begin 154 154 // Use only necessary power 155 155 AttackPower := TotalPower - TotalAttackPower; … … 168 168 procedure TComputer.InnerMoves; 169 169 var 170 AllCells: T Cells;170 AllCells: TPlayerCells; 171 171 I, J: Integer; 172 172 C: Integer; 173 173 CanAttack: Integer; 174 TargetCells: T Cells;175 NewTargetCells: T Cells;176 Cells2: T Cells;174 TargetCells: TPlayerCells; 175 NewTargetCells: TPlayerCells; 176 Cells2: TPlayerCells; 177 177 MovedPower: Integer; 178 178 begin 179 179 // We need to move available power to borders to be available for attacks 180 180 // or defense 181 AllCells := Game.Map.Cells;182 TargetCells := T Cells.Create;181 AllCells := ControlPlayer.PlayerMap.Cells; 182 TargetCells := TPlayerCells.Create; 183 183 TargetCells.FreeObjects := False; 184 NewTargetCells := T Cells.Create;184 NewTargetCells := TPlayerCells.Create; 185 185 NewTargetCells.FreeObjects := False; 186 186 … … 188 188 for C := 0 to AllCells.Count - 1 do 189 189 with AllCells[C] do begin 190 if ( Player <> ControlPlayer) and (Player <> nil) and (Terrain <> ttVoid) then begin190 if (MapCell.Player <> ControlPlayer) and (MapCell.Player <> nil) and (MapCell.Terrain <> ttVoid) then begin 191 191 CanAttack := 0; 192 192 for I := 0 to Neighbors.Count - 1 do 193 if ((Neighbors[I]. Player = ControlPlayer) or194 (Neighbors[I]. Player = nil)) and (Neighbors[I].Terrain <> ttVoid) then begin193 if ((Neighbors[I].MapCell.Player = ControlPlayer) or 194 (Neighbors[I].MapCell.Player = nil)) and (Neighbors[I].MapCell.Terrain <> ttVoid) then begin 195 195 Inc(CanAttack); 196 196 end; … … 210 210 // Set mark for selected border cells 211 211 for C := 0 to TargetCells.Count - 1 do 212 TargetCells[C].Ma rk := True;212 TargetCells[C].MapCell.Mark := True; 213 213 214 214 // Move all power from unmarked cells and mark them … … 217 217 with TargetCells[C] do begin 218 218 for I := 0 to Neighbors.Count - 1 do begin 219 if (Neighbors[I]. Terrain <> ttVoid) and (not Neighbors[I].Mark) then begin220 if (TargetCells[C]. Player = ControlPlayer) and221 (Neighbors[I]. Player = ControlPlayer) then begin219 if (Neighbors[I].MapCell.Terrain <> ttVoid) and (not Neighbors[I].MapCell.Mark) then begin 220 if (TargetCells[C].MapCell.Player = ControlPlayer) and 221 (Neighbors[I].MapCell.Player = ControlPlayer) then begin 222 222 // Do not take units from front line 223 223 Cells2 := Neighbors[I].Neighbors; 224 224 CanAttack := 0; 225 225 for J := 0 to Cells2.Count - 1 do 226 if ((Cells2[J]. Player <> ControlPlayer) or (Cells2[J].Player = nil))227 and (Cells2[J]. Terrain <> ttVoid) then begin226 if ((Cells2[J].MapCell.Player <> ControlPlayer) or (Cells2[J].MapCell.Player = nil)) 227 and (Cells2[J].MapCell.Terrain <> ttVoid) then begin 228 228 Inc(CanAttack); 229 229 end; … … 232 232 if (TargetCells[C].GetAvialPower + TargetCells[C].GetAttackPower + MovedPower) > Game.Map.MaxPower then 233 233 MovedPower := Game.Map.MaxPower - TargetCells[C].GetAvialPower - TargetCells[C].GetAttackPower; 234 Player.SetMove(Neighbors[I], TargetCells[C], MovedPower, False);234 MapCell.Player.SetMove(Neighbors[I], TargetCells[C], MovedPower, False); 235 235 end; 236 236 end; 237 Neighbors[I].Ma rk := True;237 Neighbors[I].MapCell.Mark := True; 238 238 NewTargetCells.Add(Neighbors[I]); 239 239 end; … … 244 244 FreeAndNil(TargetCells); 245 245 TargetCells := NewTargetCells; 246 NewTargetCells := T Cells.Create;246 NewTargetCells := TPlayerCells.Create; 247 247 NewTargetCells.FreeObjects := False; 248 248 end; … … 281 281 C: Integer; 282 282 I: Integer; 283 AllCells: T Cells;284 BorderCells: T Cells;283 AllCells: TPlayerCells; 284 BorderCells: TPlayerCells; 285 285 EnemyPower: Integer; 286 286 begin 287 BorderCells := T Cells.Create;287 BorderCells := TPlayerCells.Create; 288 288 BorderCells.FreeObjects := False; 289 AllCells := Game.Map.Cells;289 AllCells := ControlPlayer.PlayerMap.Cells; 290 290 291 291 // Get list of border cells 292 292 for C := 0 to AllCells.Count - 1 do 293 293 with AllCells[C] do begin 294 if ( Terrain <> ttVoid) and (Player = ControlPlayer) then begin294 if (MapCell.Terrain <> ttVoid) and (MapCell.Player = ControlPlayer) then begin 295 295 if AttackersCount(AllCells[C]) > 0 then 296 296 BorderCells.Add(AllCells[C]); … … 305 305 EnemyPower := 0; 306 306 for I := 0 to Neighbors.Count - 1 do 307 if (Neighbors[I]. Player <> ControlPlayer) and (Neighbors[I].Player <> nil) then begin308 Inc(EnemyPower, Neighbors[I]. Power);307 if (Neighbors[I].MapCell.Player <> ControlPlayer) and (Neighbors[I].MapCell.Player <> nil) then begin 308 Inc(EnemyPower, Neighbors[I].MapCell.Power); 309 309 end; 310 310 if EnemyPower > (GetAvialPower + GetAttackPower) then begin 311 311 // Fallback 312 312 for I := MovesTo.Count - 1 downto 0 do 313 Player.Moves.Remove(MovesTo[I]);313 MapCell.Player.Moves.Remove(MovesTo[I]); 314 314 for I := 0 to Neighbors.Count - 1 do 315 if (Neighbors[I]. Player =Player) and (AttackersCount(Neighbors[I]) = 0) then begin316 Player.SetMove(BorderCells[C], Neighbors[I], GetAvialPower, False);315 if (Neighbors[I].MapCell.Player = MapCell.Player) and (AttackersCount(Neighbors[I]) = 0) then begin 316 MapCell.Player.SetMove(BorderCells[C], Neighbors[I], GetAvialPower, False); 317 317 Break; 318 318 end; … … 323 323 end; 324 324 325 function TComputer.AttackersCount(Cell: T Cell): Integer;325 function TComputer.AttackersCount(Cell: TPlayerCell): Integer; 326 326 var 327 327 I: Integer; … … 329 329 Result := 0; 330 330 for I := 0 to Cell.Neighbors.Count - 1 do 331 if (Cell.Neighbors[I]. Player <> ControlPlayer) and332 (Cell.Neighbors[I]. Player <> nil) then begin331 if (Cell.Neighbors[I].MapCell.Player <> ControlPlayer) and 332 (Cell.Neighbors[I].MapCell.Player <> nil) then begin 333 333 Inc(Result); 334 334 end;
Note:
See TracChangeset
for help on using the changeset viewer.