private void OilValueCalc(clsOilBalanceLoopArgs Args) { double num; int num7; clsOilPossibilities.clsPossibility possibility = new clsOilPossibilities.clsPossibility(); double[] numArray = new double[(this.TopLeftPlayerCount - 1) + 1]; possibility.PlayerOilScoreAddition = new double[(this.TopLeftPlayerCount - 1) + 1]; double maxValue = double.MaxValue; int num16 = this.TopLeftPlayerCount - 1; int index = 0; while (index <= num16) { possibility.PlayerOilScoreAddition[index] = 0.0; index++; } int num17 = this.OilAtATime - 1; for (num7 = 0; num7 <= num17; num7++) { double num8; int num10; int num13; double[] playerOilScoreAddition; int num25; int num6 = Args.OilNodes[num7].Num; int num18 = this.OilAtATime - 1; int num11 = num7 + 1; while (num11 <= num18) { num10 = Args.OilNodes[num11].Num; num8 = 4.0 * this.PassageNodeDists[0, num6, 0, num10]; if (num8 < maxValue) { maxValue = num8; } num11++; } int num19 = this.OilAtATime - 1; for (num11 = 0; num11 <= num19; num11++) { num10 = Args.OilNodes[num11].Num; int num20 = this.SymmetryBlockCount - 1; num13 = 1; while (num13 <= num20) { num8 = 4.0 * this.PassageNodeDists[0, num6, num13, num10]; if (num8 < maxValue) { maxValue = num8; } num13++; } } int num21 = this.PassageNodeCount - 1; for (int i = 0; i <= num21; i++) { int num22 = this.SymmetryBlockCount - 1; num13 = 0; while (num13 <= num22) { if (this.PassageNodes[num13, i].OilCount > 0) { double num9; num8 = (4.0 * num9) / ((double) this.PassageNodeDists[0, num6, num13, i]); if (num8 < maxValue) { maxValue = num8; } } num13++; } } int num23 = this.TopLeftPlayerCount - 1; index = 0; while (index <= num23) { numArray[index] = 0.0; int num24 = this.SymmetryBlockCount - 1; for (num13 = 0; num13 <= num24; num13++) { modMath.sXY_int _int = this.PlayerBases[index].Nodes[0].Pos - this.PassageNodes[num13, num6].Pos; num = (this.PassageNodeDists[0, this.PlayerBases[index].Nodes[0].Num, num13, num6] * 2.0) + _int.ToDoubles().GetMagnitude(); playerOilScoreAddition = numArray; num25 = index; playerOilScoreAddition[num25] += 100.0 / num; } index++; } int num26 = this.TopLeftPlayerCount - 1; index = 0; while (index <= num26) { playerOilScoreAddition = possibility.PlayerOilScoreAddition; num25 = index; playerOilScoreAddition[num25] += Args.OilClusterSizes[num7] * numArray[index]; index++; } } double num3 = double.MaxValue; double minValue = double.MinValue; int num27 = this.TopLeftPlayerCount - 1; for (index = 0; index <= num27; index++) { num = Args.PlayerOilScore[index] + possibility.PlayerOilScoreAddition[index]; if (num < num3) { num3 = num; } if (num > minValue) { minValue = num; } } double num14 = minValue - num3; if (maxValue == double.MaxValue) { maxValue = 0.0; } else { maxValue = 10.0 / maxValue; } double num15 = (this.OilDispersion * maxValue) + num14; possibility.Score = num15; possibility.Nodes = new clsPassageNode[(this.OilAtATime - 1) + 1]; int num28 = this.OilAtATime - 1; for (num7 = 0; num7 <= num28; num7++) { possibility.Nodes[num7] = Args.OilNodes[num7]; } Args.OilPossibilities.NewPossibility(possibility); }
private void OilBalanceLoop(clsOilBalanceLoopArgs Args, int LoopNum) { int loopNum = LoopNum + 1; int num4 = this.PassageNodeCount - 1; for (int i = 0; i <= num4; i++) { clsPassageNode node = this.PassageNodes[0, i]; if ((((node.PlayerBaseNum < 0) & !node.IsOnBorder) & (node.OilCount == 0)) & !node.IsWater) { int num5 = LoopNum - 1; int index = 0; while (index <= num5) { if (Args.OilNodes[index] == node) { break; } index++; } if (index == LoopNum) { Args.OilNodes[LoopNum] = node; if (loopNum < this.OilAtATime) { this.OilBalanceLoop(Args, loopNum); } else { this.OilValueCalc(Args); } } } } }
public clsResult GenerateOil() { int num; int num2; int num6; clsPassageNode[,] passageNodes; int num17; int num18; clsResult result2 = new clsResult("Oil"); int num7 = this.PassageNodeCount - 1; for (num = 0; num <= num7; num++) { int num8 = this.SymmetryBlockCount - 1; num2 = 0; while (num2 <= num8) { this.PassageNodes[num2, num].OilCount = 0; num2++; } } clsPassageNodeNework nework = this.MakePassageNodeNetwork(); PathfinderNode[] startNodes = new PathfinderNode[1]; this.PassageNodeDists = new float[(this.SymmetryBlockCount - 1) + 1, (this.PassageNodeCount - 1) + 1, (this.SymmetryBlockCount - 1) + 1, (this.PassageNodeCount - 1) + 1]; int num9 = this.PassageNodeCount - 1; for (num = 0; num <= num9; num++) { int num10 = this.SymmetryBlockCount - 1; for (int i = 0; i <= num10; i++) { this.PassageNodeDists[i, num, i, num] = 0f; int num11 = this.PassageNodeCount - 1; num2 = 0; while (num2 <= num11) { int num12 = this.SymmetryBlockCount - 1; for (int j = 0; j <= num12; j++) { if ((this.PassageNodes[0, num].IsWater | this.PassageNodes[j, num2].IsWater) | ((j != 0) & (i != 0))) { this.PassageNodeDists[i, num, j, num2] = float.MaxValue; this.PassageNodeDists[j, num2, i, num] = float.MaxValue; } else { startNodes[0] = nework.PassageNodePathNodes[i, num]; PathfinderNetwork.PathList[] listArray = nework.Network.GetPath(startNodes, nework.PassageNodePathNodes[j, num2], -1, 0); if (listArray == null) { result2.ProblemAdd("Map is not all connected."); nework.Network.Deallocate(); return result2; } if (listArray[0].PathCount != 1) { Debugger.Break(); } this.PassageNodeDists[i, num, j, num2] = listArray[0].Paths[0].Value; this.PassageNodeDists[j, num2, i, num] = listArray[0].Paths[0].Value; } } num2++; } } } nework.Network.Deallocate(); int num5 = 1; int num13 = this.OilAtATime - 1; num = 0; while (num <= num13) { num5 *= this.PassageNodeCount; num++; } clsOilBalanceLoopArgs args = new clsOilBalanceLoopArgs { OilClusterSizes = new int[(this.OilAtATime - 1) + 1], PlayerOilScore = new double[(this.TopLeftPlayerCount - 1) + 1], OilNodes = new clsPassageNode[(this.OilAtATime - 1) + 1] }; while (num6 < this.ExtraOilCount) { int num14 = this.OilAtATime - 1; num = 0; while (num <= num14) { args.OilClusterSizes[num] = Math.Min(this.ExtraOilClusterSizeMin + ((int) Math.Round((double) ((float) (App.Random.Next() * ((this.ExtraOilClusterSizeMax - this.ExtraOilClusterSizeMin) + 1))))), Math.Max((int) Math.Round(Math.Ceiling((double) (((double) (this.ExtraOilCount - num6)) / ((double) this.SymmetryBlockCount)))), 1)); num++; } args.OilPossibilities = new clsOilPossibilities(); this.OilBalanceLoop(args, 0); clsOilPossibilities.clsPossibility bestPossibility = args.OilPossibilities.BestPossibility; if (bestPossibility != null) { int num15 = this.OilAtATime - 1; num2 = 0; while (num2 <= num15) { int num16 = this.SymmetryBlockCount - 1; num = 0; while (num <= num16) { passageNodes = this.PassageNodes; num17 = num; num18 = bestPossibility.Nodes[num2].Num; passageNodes[num17, num18].OilCount += args.OilClusterSizes[num2]; num++; } num6 += args.OilClusterSizes[num2] * this.SymmetryBlockCount; num2++; } int num19 = this.TopLeftPlayerCount - 1; num = 0; while (num <= num19) { double[] playerOilScore = args.PlayerOilScore; num18 = num; playerOilScore[num18] += bestPossibility.PlayerOilScoreAddition[num]; num++; } } else { result2.WarningAdd("Could not place all of the oil. " + Conversions.ToString(num6) + " oil was placed."); break; } } int num20 = this.TopLeftPlayerCount - 1; for (num = 0; num <= num20; num++) { int num21 = this.SymmetryBlockCount - 1; for (num2 = 0; num2 <= num21; num2++) { passageNodes = this.PassageNodes; num18 = num2; num17 = this.PlayerBases[num].Nodes[0].Num; passageNodes[num18, num17].OilCount += this.BaseOilCount; } } return result2; }
private void OilValueCalc(clsOilBalanceLoopArgs Args) { //Dim OilDistScore As Double //Dim OilStraightDistScore As Double double LowestScore = 0; double HighestScore = 0; //Dim TotalOilScore As Double double UnbalancedScore = 0; double dblTemp = 0; double Value = 0; clsOilPossibilities.clsPossibility NewPossibility = new clsOilPossibilities.clsPossibility(); double[] BaseOilScore = new double[TopLeftPlayerCount]; NewPossibility.PlayerOilScoreAddition = new double[TopLeftPlayerCount]; int NewOilNum = 0; int OtherOilNum = 0; int NewOilNodeNum = 0; int OtherOilNodeNum = 0; int SymmetryBlockNum = 0; int MapNodeNum = 0; int PlayerNum = 0; //Dim NewOilCount As Integer double OilMassMultiplier = 0; double OilDistValue = 0; double NearestOilValue = double.MaxValue; //OilDistScore = 0.0# //OilStraightDistScore = 0.0# for ( PlayerNum = 0; PlayerNum <= TopLeftPlayerCount - 1; PlayerNum++ ) { NewPossibility.PlayerOilScoreAddition[PlayerNum] = 0.0D; } for ( NewOilNum = 0; NewOilNum <= OilAtATime - 1; NewOilNum++ ) { NewOilNodeNum = Args.OilNodes[NewOilNum].Num; //other oil to be placed in the first area for ( OtherOilNum = NewOilNum + 1; OtherOilNum <= OilAtATime - 1; OtherOilNum++ ) { OtherOilNodeNum = Args.OilNodes[OtherOilNum].Num; //OilMassMultiplier = Args.OilClusterSizes(NewOilNum) * Args.OilClusterSizes(OtherOilNum) //OilDistScore += OilMassMultiplier / PassageNodeDists(0, NewOilNodeNum, 0, OtherOilNodeNum) //OilStraightDistScore += OilMassMultiplier / GetDist_XY_int(PassageNodes(0, NewOilNodeNum).Pos, PassageNodes(0, OtherOilNodeNum).Pos) OilDistValue = 4.0D * PassageNodeDists[0, NewOilNodeNum, 0, OtherOilNodeNum]; //+ GetDist_XY_int(PassageNodes(0, NewOilNodeNum).Pos, PassageNodes(0, OtherOilNodeNum).Pos)) if ( OilDistValue < NearestOilValue ) { NearestOilValue = OilDistValue; } } //other oil to be placed in symmetrical areas for ( OtherOilNum = 0; OtherOilNum <= OilAtATime - 1; OtherOilNum++ ) { OtherOilNodeNum = Args.OilNodes[OtherOilNum].Num; //OilMassMultiplier = Args.OilClusterSizes(NewOilNum) * Args.OilClusterSizes(OtherOilNum) for ( SymmetryBlockNum = 1; SymmetryBlockNum <= SymmetryBlockCount - 1; SymmetryBlockNum++ ) { //OilDistScore += OilMassMultiplier / PassageNodeDists(0, NewOilNodeNum, SymmetryBlockNum, OtherOilNodeNum) //OilStraightDistScore += OilMassMultiplier / GetDist_XY_int(PassageNodes(0, NewOilNodeNum).Pos, PassageNodes(SymmetryBlockNum, OtherOilNodeNum).Pos) OilDistValue = 4.0D * PassageNodeDists[0, NewOilNodeNum, SymmetryBlockNum, OtherOilNodeNum]; // + GetDist_XY_int(PassageNodes(0, NewOilNodeNum).Pos, PassageNodes(SymmetryBlockNum, OtherOilNodeNum).Pos)) if ( OilDistValue < NearestOilValue ) { NearestOilValue = OilDistValue; } } } //oil on the map for ( MapNodeNum = 0; MapNodeNum <= PassageNodeCount - 1; MapNodeNum++ ) { for ( SymmetryBlockNum = 0; SymmetryBlockNum <= SymmetryBlockCount - 1; SymmetryBlockNum++ ) { if ( PassageNodes[SymmetryBlockNum, MapNodeNum].OilCount > 0 ) { //OilMassMultiplier = Args.OilClusterSizes(NewOilNum) * PassageNodes(SymmetryBlockNum, MapNodeNum).OilCount //OilDistScore += OilMassMultiplier / PassageNodeDists(0, NewOilNodeNum, SymmetryBlockNum, MapNodeNum) //OilStraightDistScore += OilMassMultiplier / GetDist_XY_int(PassageNodes(0, NewOilNodeNum).Pos, PassageNodes(SymmetryBlockNum, MapNodeNum).Pos) OilDistValue = 4.0D * OilMassMultiplier / PassageNodeDists[0, NewOilNodeNum, SymmetryBlockNum, MapNodeNum]; // + GetDist_XY_int(PassageNodes(0, NewOilNodeNum).Pos, PassageNodes(SymmetryBlockNum, MapNodeNum).Pos)) if ( OilDistValue < NearestOilValue ) { NearestOilValue = OilDistValue; } } } } //extra oil score for players for ( PlayerNum = 0; PlayerNum <= TopLeftPlayerCount - 1; PlayerNum++ ) { BaseOilScore[PlayerNum] = 0.0D; for ( SymmetryBlockNum = 0; SymmetryBlockNum <= SymmetryBlockCount - 1; SymmetryBlockNum++ ) { dblTemp = Convert.ToDouble(PassageNodeDists[0, PlayerBases[PlayerNum].Nodes[0].Num, SymmetryBlockNum, NewOilNodeNum] * 2.0D + (PlayerBases[PlayerNum].Nodes[0].Pos - PassageNodes[SymmetryBlockNum, NewOilNodeNum].Pos).ToDoubles().GetMagnitude()); BaseOilScore[PlayerNum] += 100.0D / dblTemp; } } //TotalOilScore = 0.0# //For PlayerNum = 0 To PlayerCount - 1 // TotalOilScore += BaseOilScore(PlayerNum) //Next for ( PlayerNum = 0; PlayerNum <= TopLeftPlayerCount - 1; PlayerNum++ ) { NewPossibility.PlayerOilScoreAddition[PlayerNum] += Args.OilClusterSizes[NewOilNum] * BaseOilScore[PlayerNum]; } } LowestScore = double.MaxValue; HighestScore = double.MinValue; for ( PlayerNum = 0; PlayerNum <= TopLeftPlayerCount - 1; PlayerNum++ ) { dblTemp = Args.PlayerOilScore[PlayerNum] + NewPossibility.PlayerOilScoreAddition[PlayerNum]; if ( dblTemp < LowestScore ) { LowestScore = dblTemp; } if ( dblTemp > HighestScore ) { HighestScore = dblTemp; } } UnbalancedScore = HighestScore - LowestScore; //NewOilCount = 0 //For NewOilNum = 0 To OilAtATime - 1 // NewOilCount += Args.OilClusterSizes(NewOilNum) //Next //divide all dists by the number of oil resources placed. does not include other symmetries, since they were never added in, and are exactly the same. if ( NearestOilValue == double.MaxValue ) { NearestOilValue = 0.0D; } else { NearestOilValue = 10.0D / NearestOilValue; } //Value = OilDispersion * (OilDistScore * 4.0# + OilStraightDistScore) + UnbalancedScore Value = OilDispersion * NearestOilValue + UnbalancedScore; NewPossibility.Score = Value; NewPossibility.Nodes = new clsPassageNode[OilAtATime]; for ( NewOilNum = 0; NewOilNum <= OilAtATime - 1; NewOilNum++ ) { NewPossibility.Nodes[NewOilNum] = Args.OilNodes[NewOilNum]; } Args.OilPossibilities.NewPossibility(NewPossibility); }
private void OilBalanceLoop(clsOilBalanceLoopArgs Args, int LoopNum) { int A = 0; int C = 0; int NextLoopNum = LoopNum + 1; clsPassageNode tmpPassageNodeA = default(clsPassageNode); for ( A = 0; A <= PassageNodeCount - 1; A++ ) { tmpPassageNodeA = PassageNodes[0, A]; if ( tmpPassageNodeA.PlayerBaseNum < 0 && !tmpPassageNodeA.IsOnBorder && tmpPassageNodeA.OilCount == 0 && !tmpPassageNodeA.IsWater ) { for ( C = 0; C <= LoopNum - 1; C++ ) { if ( Args.OilNodes[C] == tmpPassageNodeA ) { break; } } if ( C == LoopNum ) { Args.OilNodes[LoopNum] = tmpPassageNodeA; if ( NextLoopNum < OilAtATime ) { OilBalanceLoop(Args, NextLoopNum); } else { OilValueCalc(Args); } } } } }
public clsResult GenerateOil() { clsResult ReturnResult = new clsResult("Oil"); int A = 0; int B = 0; int C = 0; int D = 0; for ( A = 0; A <= PassageNodeCount - 1; A++ ) { for ( B = 0; B <= SymmetryBlockCount - 1; B++ ) { PassageNodes[B, A].OilCount = 0; } } //store passage node route distances clsPassageNodeNework PassageNodePathMap = MakePassageNodeNetwork(); PathfinderNode[] GetPathStartNodes = new PathfinderNode[1]; PathfinderNetwork.PathList[] ResultPaths = null; PassageNodeDists = new float[SymmetryBlockCount, PassageNodeCount, SymmetryBlockCount, PassageNodeCount]; for ( A = 0; A <= PassageNodeCount - 1; A++ ) { for ( D = 0; D <= SymmetryBlockCount - 1; D++ ) { PassageNodeDists[D, A, D, A] = 0.0F; for ( B = 0; B <= PassageNodeCount - 1; B++ ) { for ( C = 0; C <= SymmetryBlockCount - 1; C++ ) { if ( PassageNodes[0, A].IsWater || PassageNodes[C, B].IsWater || (C != 0 & D != 0) ) { PassageNodeDists[D, A, C, B] = float.MaxValue; PassageNodeDists[C, B, D, A] = float.MaxValue; } else { GetPathStartNodes[0] = PassageNodePathMap.PassageNodePathNodes[D, A]; ResultPaths = PassageNodePathMap.Network.GetPath(GetPathStartNodes, PassageNodePathMap.PassageNodePathNodes[C, B], -1, 0); if ( ResultPaths == null ) { ReturnResult.ProblemAdd("Map is not all connected."); PassageNodePathMap.Network.Deallocate(); return ReturnResult; } else { if ( ResultPaths[0].PathCount != 1 ) { Debugger.Break(); } PassageNodeDists[D, A, C, B] = ResultPaths[0].Paths[0].Value; PassageNodeDists[C, B, D, A] = ResultPaths[0].Paths[0].Value; } } } } } } PassageNodePathMap.Network.Deallocate(); //place oil int PlacedExtraOilCount = 0; int MaxBestNodeCount = 0; MaxBestNodeCount = 1; for ( A = 0; A <= OilAtATime - 1; A++ ) { MaxBestNodeCount *= PassageNodeCount; } var oilArgs = new clsOilBalanceLoopArgs { OilClusterSizes = new int[OilAtATime], PlayerOilScore = new double[TopLeftPlayerCount], OilNodes = new clsPassageNode[OilAtATime] }; //balanced oil while ( PlacedExtraOilCount < ExtraOilCount ) { //place oil farthest away from other oil and where it best balances the player oil score for ( A = 0; A <= OilAtATime - 1; A++ ) { oilArgs.OilClusterSizes[A] = Math.Min(ExtraOilClusterSizeMin + (int)(Conversion.Int(VBMath.Rnd() * (ExtraOilClusterSizeMax - ExtraOilClusterSizeMin + 1))), Math.Max((int)(Math.Ceiling(Convert.ToDecimal((ExtraOilCount - PlacedExtraOilCount) / SymmetryBlockCount))), 1)); } oilArgs.OilPossibilities = new clsOilPossibilities(); OilBalanceLoop(oilArgs, 0); clsOilPossibilities.clsPossibility bestPossibility = oilArgs.OilPossibilities.BestPossibility; if ( bestPossibility != null ) { for ( B = 0; B <= OilAtATime - 1; B++ ) { for ( A = 0; A <= SymmetryBlockCount - 1; A++ ) { PassageNodes[A, bestPossibility.Nodes[B].Num].OilCount += oilArgs.OilClusterSizes[B]; } PlacedExtraOilCount += oilArgs.OilClusterSizes[B] * SymmetryBlockCount; } for ( A = 0; A <= TopLeftPlayerCount - 1; A++ ) { oilArgs.PlayerOilScore[A] += bestPossibility.PlayerOilScoreAddition[A]; } } else { ReturnResult.WarningAdd("Could not place all of the oil. " + Convert.ToString(PlacedExtraOilCount) + " oil was placed."); break; } } //base oil for ( A = 0; A <= TopLeftPlayerCount - 1; A++ ) { for ( B = 0; B <= SymmetryBlockCount - 1; B++ ) { PassageNodes[B, PlayerBases[A].Nodes[0].Num].OilCount += BaseOilCount; } } return ReturnResult; }