Changeset 65
Legend:
- Unmodified
- Added
- Removed
-
trunk/UCore.pas
r64 r65 133 133 134 134 procedure TCore.AGameEndTurnExecute(Sender: TObject); 135 var 136 I: Integer; 137 Computer: TComputer; 135 138 begin 136 139 Game.NextTurn; 137 140 FormMain.Redraw; 138 141 while Game.Running and (Game.CurrentPlayer.Mode <> pmHuman) do begin 139 if Game.CurrentPlayer.Mode = pmComputer then 140 Game.CurrentPlayer.ComputerTurn; 142 if Game.CurrentPlayer.Mode = pmComputer then begin 143 Computer := TComputer.Create; 144 Computer.Game := Game; 145 Computer.Process; 146 Computer.Free; 147 FormMain.Redraw; 148 for I := 0 to 10 do begin 149 Application.ProcessMessages; 150 Sleep(100); 151 end; 152 end; 141 153 Game.NextTurn; 142 154 FormMain.Redraw; -
trunk/UGame.pas
r64 r65 188 188 procedure LoadFromNode(Node: TDOMNode); 189 189 procedure SaveToNode(Node: TDOMNode); 190 procedure ComputerTurn;191 190 procedure Paint(PaintBox: TPaintBox); 192 191 constructor Create; … … 194 193 procedure Assign(Source: TPlayer); 195 194 property Game: TGame read FGame write SetGame; 195 end; 196 197 198 { TComputer } 199 200 TComputer = class 201 Game: TGame; 202 Targets: TObjectList; 203 procedure Process; 196 204 end; 197 205 … … 381 389 end; 382 390 391 { TComputer } 392 383 393 { TPlayers } 384 394 … … 1103 1113 end; 1104 1114 1105 procedure T Player.ComputerTurn;1115 procedure TComputer.Process; 1106 1116 var 1107 1117 AllCells: TObjectList; 1108 Cells : TCellArray;1118 Cells, Cells2: TCellArray; 1109 1119 X, Y: Integer; 1110 1120 TotalPower: Integer; 1111 1121 AttackPower: Integer; 1112 1122 TotalAttackPower: Integer; 1113 I : Integer;1123 I, J: Integer; 1114 1124 C: Integer; 1115 CanAttack: Integer; 1125 CanAttack, CanAttack2: Integer; 1126 const 1127 AttackDiff = 2; 1116 1128 begin 1117 1129 AllCells := Game.Map.Cells; 1118 1130 for C := 0 to AllCells.Count - 1 do 1119 1131 with TCell(AllCells[C]) do begin 1120 if (Terrain <> ttVoid) and (Player <> Self) then begin1132 if (Terrain <> ttVoid) and (Player <> Game.CurrentPlayer) then begin 1121 1133 // Attack to not owned cell yet 1122 1134 // Count own possible power … … 1124 1136 TotalPower := 0; 1125 1137 for I := 0 to Length(Cells) - 1 do 1126 if (Cells[I].Player = Self) then begin1138 if (Cells[I].Player = Game.CurrentPlayer) then begin 1127 1139 TotalPower := TotalPower + Cells[I].GetAvialPower; 1128 1140 end; 1129 1141 // Attack if target is weaker 1130 if TotalPower >= Powerthen begin1142 if TotalPower >= (Power + AttackDiff) then begin 1131 1143 TotalAttackPower := 0; 1132 1144 for I := 0 to Length(Cells) - 1 do 1133 if (Cells[I].Player = Self) then begin1145 if (Cells[I].Player = Game.CurrentPlayer) then begin 1134 1146 // Use only necessary power 1135 AttackPower := Power - TotalAttackPower + 1;1147 AttackPower := Power - TotalAttackPower + AttackDiff; 1136 1148 if Cells[I].GetAvialPower < AttackPower then 1137 1149 AttackPower := Cells[I].GetAvialPower; … … 1141 1153 end; 1142 1154 end else 1143 if (Terrain <> ttVoid) and (Player = Self) then begin1155 if (Terrain <> ttVoid) and (Player = Game.CurrentPlayer) then begin 1144 1156 // Inner moves 1145 1157 // We need to move available power to borders to be available for attacks … … 1148 1160 CanAttack := 0; 1149 1161 for I := 0 to Length(Cells) - 1 do 1150 if (Cells[I].Player <> Self) and (Cells[I].Terrain <> ttVoid) then begin1162 if (Cells[I].Player <> Game.CurrentPlayer) and (Cells[I].Terrain <> ttVoid) then begin 1151 1163 Inc(CanAttack); 1152 1164 end; … … 1155 1167 // For simplicty just try to balance inner area cells power 1156 1168 for I := 0 to Length(Cells) - 1 do 1157 if (Cells[I].Player = Self) and (Cells[I].Power < TCell(AllCells[C]).GetAvialPower) then begin1169 if (Cells[I].Player = Game.CurrentPlayer) and (Cells[I].Power < TCell(AllCells[C]).GetAvialPower) then begin 1158 1170 Game.SetMove(TCell(AllCells[C]), Cells[I], (TCell(AllCells[C]).GetAvialPower - Cells[I].Power) div 2); 1171 end; 1172 end else begin 1173 // Is enemy border cell, try to absorb all units from inner neighbours 1174 for I := 0 to Length(Cells) - 1 do 1175 if (Cells[I].Player = Game.CurrentPlayer) and (Cells[I].GetAvialPower > 0) then begin 1176 Cells2 := Game.Map.GetCellNeighbors(TCell(Cells[I])); 1177 CanAttack2 := 0; 1178 for J := 0 to Length(Cells2) - 1 do 1179 if (Cells2[J].Player <> Game.CurrentPlayer) and (Cells2[J].Terrain <> ttVoid) then begin 1180 Inc(CanAttack2); 1181 end; 1182 if CanAttack2 = 0 then 1183 Game.SetMove(Cells[I], TCell(AllCells[C]), Cells[I].GetAvialPower); 1159 1184 end; 1160 1185 end;
Note:
See TracChangeset
for help on using the changeset viewer.