public void Battle(Random random, IEnumerable <CellularEmpireCellData> neighbours, out long newState, out float newStateValue) { float[] stateBattleStrength = new float[Automata.States.Count()]; foreach (CellularEmpireCellData cellularEmpireCellData in neighbours) { stateBattleStrength[CellularEmpire.StateToIndex(cellularEmpireCellData.State)] += 0.5f * CalculateBattleStrength(cellularEmpireCellData.experience); } stateBattleStrength[CellularEmpire.StateToIndex(State)] += CalculateBattleStrength(experience); float maxStrength = 0; long maxStrengthState = -1; for (int i = 0; i < stateBattleStrength.Length; i++) { float stateStrength = stateBattleStrength[i]; if (maxStrengthState != -1 && !(maxStrength < stateStrength)) { continue; } maxStrength = stateStrength; maxStrengthState = CellularEmpire.IndexToState(i); } if (maxStrengthState == State) { experience += (float)Math.Max(0.05, experience * experience); } else { State = maxStrengthState; experience = (float)(random.NextDouble() * maxStrength); } newState = State; newStateValue = StateValue; }
public CellularEmpireCellData(CellularEmpire automata, long state) { Automata = automata; State = state; experience = 0.05f; }