public static float GetFitnessForMatrix(CAMatrix matMatrix) { float dTotalFitness = 0; for (int x = 0; x < matMatrix.Width; x++) { for (int y = 0; y < matMatrix.Width; y++) { CACell celCurrCell = matMatrix.GetCell(x, y); // If the cell has nothing in it, skip it.. if (celCurrCell == null) { continue; } if (celCurrCell.clrTeamColor == PLAYER_COLOR) { dTotalFitness += 10 + celCurrCell.fAvaliableEnergy; } } } return(dTotalFitness); }
public static void DisplayMatrix(CAMatrix matMatrix, Graphics grpGraphics) { for (int x = 0; x < matMatrix.Width; x++) { for (int y = 0; y < matMatrix.Width; y++) { CACell celCurrCell = matMatrix.GetCell(x, y); // If the cell has nothing in it, skip it.. if (celCurrCell == null) { grpGraphics.FillRectangle(new SolidBrush(Color.Black), x * 10, y * 10, 10, 10); continue; } Color clrTeamColor = celCurrCell.clrTeamColor; float fEnergy = celCurrCell.fAvaliableEnergy; int nWantedRed = (int)((clrTeamColor.R / 4) + (fEnergy * 30)); int nWantedGreen = (int)((clrTeamColor.G / 4) + (fEnergy * 30)); int nWantedBlue = (int)((clrTeamColor.B / 4) + (fEnergy * 30)); int nRed = Math.Min(nWantedRed, 255); int nGreen = Math.Min(nWantedGreen, 255); int nBlue = Math.Min(nWantedBlue, 255); Color clrCombinedWithEnergy = Color.FromArgb(nRed, nGreen, nBlue); grpGraphics.FillRectangle(new SolidBrush(clrCombinedWithEnergy), x * 10, y * 10, 10, 10); } } }
public static void RunTimeStep(CAMatrix matMatrix) { int nWidth = matMatrix.Width; int nHeight = matMatrix.Height; for (int x = 0; x < nWidth; x++) { for (int y = 0; y < nHeight; y++) { CACell celCurrCell = matMatrix.GetCell(x, y); // If the cell has nothing in it, skip it.. if (celCurrCell == null) { continue; } // The cell has a program in it. run it. celCurrCell.progProgram.Run(celCurrCell); } } // Deleting cells for (int i = 0; i < matMatrix.lstCellDeletesForNextTime.Count; i++) { matMatrix.DestroyCell(matMatrix.lstCellDeletesForNextTime[i].X, matMatrix.lstCellDeletesForNextTime[i].Y); } matMatrix.lstCellDeletesForNextTime.Clear(); // Applying new cells waiting to creation for (int i = 0; i < matMatrix.lstNewCellsForNextTime.Count; i++) { matMatrix.PutCell(matMatrix.lstNewCellsForNextTime[i]); } matMatrix.lstNewCellsForNextTime.Clear(); // Transferring energies for (int i = 0; i < matMatrix.lstCellEnergyTransfersOne.Count; i++) { EnergyTransfer trnTransfer = matMatrix.lstCellEnergyTransfersOne[i]; if (trnTransfer.celFrom.fAvaliableEnergy >= trnTransfer.dEnergy) { trnTransfer.celFrom.fAvaliableEnergy -= trnTransfer.dEnergy; trnTransfer.celTo.fAvaliableEnergy += trnTransfer.dEnergy; } } matMatrix.lstCellEnergyTransfersOne.Clear(); }