Changeset 90 for trunk/UGame.pas
- Timestamp:
- Nov 16, 2014, 5:12:25 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UGame.pas
r89 r90 239 239 240 240 TPlayerMode = (pmHuman, pmComputer); 241 TComputerAgressivity = (caLow, caMedium, caHigh); 241 242 242 243 { TPlayer } … … 258 259 StartCell: TCell; 259 260 PlayerMap: TPlayerMap; 261 Defensive: Boolean; 262 Agressivity: TComputerAgressivity; 260 263 procedure LoadFromNode(Node: TDOMNode); 261 264 procedure SaveToNode(Node: TDOMNode); … … 404 407 PlayerColors: array[0..7] of TColor = (clBlue, clRed, clGreen, clOrange, 405 408 clPurple, clMaroon, clAqua, clFuchsia); 409 ComputerAggroProbability: array[TComputerAgressivity] of Single = (0.9, 0.7, 0.5); 406 410 407 411 procedure InitStrings; … … 787 791 NewPlayer.Mode := Mode; 788 792 NewPlayer.Id := GetNewPlayerId; 793 if Mode = pmComputer then 794 NewPlayer.Agressivity := caMedium; 789 795 Add(NewPlayer); 790 796 end; … … 1671 1677 StartCell := FGame.Map.Cells.FindById(ReadInteger(Node, 'StartCell', 0)); 1672 1678 StartUnits := ReadInteger(Node, 'StartUnits', 0); 1679 Agressivity := TComputerAgressivity(ReadInteger(Node, 'Agressivity', Integer(caMedium))); 1680 Defensive := ReadBoolean(Node, 'Defensive', False); 1673 1681 1674 1682 with Node do begin … … 1689 1697 WriteInteger(Node, 'StartCell', StartCell.Id); 1690 1698 WriteInteger(Node, 'StartUnits', StartUnits); 1699 WriteInteger(Node, 'Agressivity', Integer(Agressivity)); 1700 WriteBoolean(Node, 'Defensive', Defensive); 1691 1701 1692 1702 with Node do begin … … 1787 1797 AttackDiff = 2; 1788 1798 begin 1799 if Game.CurrentPlayer.Defensive then Exit; 1800 1789 1801 AllCells := Game.Map.Cells; 1790 1802 TargetCells := TCells.Create; … … 1818 1830 end; 1819 1831 // Attack if target is weaker 1820 if TotalPower >= (Power + AttackDiff) then begin 1832 if Game.AttackProbability(TotalPower, Power) >= ComputerAggroProbability[Game.CurrentPlayer.Agressivity] then begin 1833 // Try to limit total attacking power to necessary minimum 1834 while Game.AttackProbability(TotalPower - 1, Power) >= ComputerAggroProbability[Game.CurrentPlayer.Agressivity] do 1835 Dec(TotalPower); 1836 1837 // Collect required attack units from our cells 1821 1838 TotalAttackPower := 0; 1822 1839 for I := 0 to Neighbors.Count - 1 do 1823 1840 if (TCell(Neighbors[I]).Player = Game.CurrentPlayer) then begin 1824 1841 // Use only necessary power 1825 AttackPower := Power - TotalAttackPower + AttackDiff;1842 AttackPower := TotalPower - TotalAttackPower; 1826 1843 if TCell(Neighbors[I]).GetAvialPower < AttackPower then 1827 1844 AttackPower := TCell(Neighbors[I]).GetAvialPower; 1828 1845 Game.SetMove(TCell(Neighbors[I]), TCell(TargetCells[C]), AttackPower, False); 1829 1846 TotalAttackPower := TotalAttackPower + AttackPower; 1847 if TotalAttackPower >= TotalPower then Break; 1830 1848 end; 1831 1849 end; … … 2084 2102 StartUnits := Source.StartUnits; 2085 2103 StartCell := Source.StartCell; 2104 Agressivity := Source.Agressivity; 2105 Defensive := Source.Defensive; 2086 2106 View.Assign(Source.View); 2087 2107 end;
Note:
See TracChangeset
for help on using the changeset viewer.