Changeset 66


Ignore:
Timestamp:
Sep 28, 2014, 11:51:26 AM (10 years ago)
Author:
chronos
Message:
  • Modified: Computer strategy divided to Attack and InnerMoves.
  • Modified: Computer attack lower power cells first.
Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/UGame.pas

    r65 r66  
    5959
    6060  TCellArray = array of TCell;
     61  TCells = class(TObjectList)
     62
     63  end;
    6164
    6265  { TView }
     
    201204    Game: TGame;
    202205    Targets: TObjectList;
     206    procedure Attack;
     207    procedure InnerMoves;
    203208    procedure Process;
    204209  end;
     
    11131118end;
    11141119
    1115 procedure TComputer.Process;
     1120function CellCompare(Item1, Item2: Pointer): Integer;
     1121begin
     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;
     1125end;
     1126
     1127procedure TComputer.Attack;
    11161128var
    11171129  AllCells: TObjectList;
    11181130  Cells, Cells2: TCellArray;
    1119   X, Y: Integer;
    11201131  TotalPower: Integer;
    11211132  AttackPower: Integer;
     
    11241135  C: Integer;
    11251136  CanAttack, CanAttack2: Integer;
     1137  TargetCells: TCells;
     1138  S: string;
    11261139const
    11271140  AttackDiff = 2;
    11281141begin
    11291142  AllCells := Game.Map.Cells;
     1143  TargetCells := TCells.Create;
     1144  TargetCells.OwnsObjects := False;
     1145
     1146  // Get list of all attack target cells
    11301147  for C := 0 to AllCells.Count - 1 do
    11311148  with TCell(AllCells[C]) do begin
    11321149    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
    11331165      // Attack to not owned cell yet
    11341166      // Count own possible power
    1135       Cells := Game.Map.GetCellNeighbors(TCell(AllCells[C]));
     1167      Cells := Game.Map.GetCellNeighbors(TCell(TargetCells[C]));
    11361168      TotalPower := 0;
    11371169      for I := 0 to Length(Cells) - 1 do
     
    11481180          if Cells[I].GetAvialPower < AttackPower then
    11491181            AttackPower := Cells[I].GetAvialPower;
    1150           Game.SetMove(Cells[I], TCell(AllCells[C]), AttackPower);
     1182          Game.SetMove(Cells[I], TCell(TargetCells[C]), AttackPower);
    11511183          TotalAttackPower := TotalAttackPower + AttackPower;
    11521184        end;
    11531185      end;
    1154     end else
    1155     if (Terrain <> ttVoid) and (Player = Game.CurrentPlayer) then begin
     1186  end;
     1187
     1188  TargetCells.Free;
     1189end;
     1190
     1191procedure TComputer.InnerMoves;
     1192var
     1193  AllCells: TObjectList;
     1194  Cells, Cells2: TCellArray;
     1195  I, J: Integer;
     1196  C: Integer;
     1197  CanAttack, CanAttack2: Integer;
     1198begin
     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
    11561203      // Inner moves
    11571204      // We need to move available power to borders to be available for attacks
     
    11881235end;
    11891236
     1237procedure TComputer.Process;
     1238begin
     1239  Attack;
     1240  InnerMoves;
     1241end;
     1242
    11901243procedure TView.SelectCell(Pos: TPoint; Player: TPlayer);
    11911244var
  • trunk/xtactics.lpi

    r62 r66  
    1 <?xml version="1.0"?>
     1<?xml version="1.0" encoding="UTF-8"?>
    22<CONFIG>
    33  <ProjectOptions>
     
    5656            </Options>
    5757          </Linking>
    58           <Other>
    59             <CompilerPath Value="$(CompPath)"/>
    60           </Other>
    6158        </CompilerOptions>
    6259      </Item2>
     
    6865      <local>
    6966        <FormatVersion Value="1"/>
    70         <LaunchingApplication PathPlusParams="/usr/bin/xterm -T 'Lazarus Run Output' -e $(LazarusDir)/tools/runwait.sh $(TargetCmdLine)"/>
    7167      </local>
    7268    </RunParams>
     
    115111        <HasResources Value="True"/>
    116112        <ResourceBaseClass Value="Form"/>
    117         <UnitName Value="UFormPlayer"/>
    118113      </Unit3>
    119114      <Unit4>
     
    123118        <HasResources Value="True"/>
    124119        <ResourceBaseClass Value="Form"/>
    125         <UnitName Value="UFormSettings"/>
    126120      </Unit4>
    127121      <Unit5>
     
    139133        <HasResources Value="True"/>
    140134        <ResourceBaseClass Value="Form"/>
    141         <UnitName Value="UFormMove"/>
    142135      </Unit6>
    143136      <Unit7>
     
    147140        <HasResources Value="True"/>
    148141        <ResourceBaseClass Value="Form"/>
    149         <UnitName Value="UFormNew"/>
    150142      </Unit7>
    151143      <Unit8>
     
    155147        <HasResources Value="True"/>
    156148        <ResourceBaseClass Value="Form"/>
    157         <UnitName Value="UFormAbout"/>
    158149      </Unit8>
    159150    </Units>
     
    199190    <Other>
    200191      <CustomOptions Value="-dDEBUG"/>
    201       <CompilerPath Value="$(CompPath)"/>
    202192    </Other>
    203193  </CompilerOptions>
Note: See TracChangeset for help on using the changeset viewer.