//Evaluation private int ReEvaluateAdjacency(ref Agent agent) { int __adjFitness = 0; int __directionSize = System.Enum.GetNames(typeof(Directions)).Length; for (int i = 0; i < agent.Count; i++) { for (int j = 0; j < agent[i].Count; j++) { InterestMatrix __adjMatrix = new InterestMatrix(agent[i][j].type); __adjMatrix = InterestMatrix.RotateMatrix(__adjMatrix, (int)agent[i][j].direction); for (int direction = 0; direction < __directionSize; direction++) { DirectionCoord __direction = new DirectionCoord((Directions)i); if (__adjMatrix.ValidAtIndex(__direction)) { if (i + __direction.X >= 0 && i + __direction.X < agent.Count) { if (j + __direction.Y >= 0 && j + __direction.Y < agent[i].Count) { __adjFitness += ScoreAdjacency(agent[i][j], agent[i + __direction.X][j + __direction.Y], __direction.Dir, true); } } } } } } return(__adjFitness); }
/// <summary> /// Aplies a score based on the block next to the root tile. Quick mode as the name implies is quicker but has less options for scoring /// </summary> /// <param name="root"></param> /// <param name="comp"></param> /// <param name="rootToComp"></param> /// <param name="quick"></param> /// <returns></returns> private int ScoreAdjacency(TileData root, TileData comp, Directions rootToComp, bool quick = false) { int __localScore = 0; if (quick) { InterestMatrix __rootMatrix = new InterestMatrix(root.type); __rootMatrix = InterestMatrix.RotateMatrix(__rootMatrix, (int)root.direction); InterestMatrix __compMatrix = new InterestMatrix(comp.type); __compMatrix = InterestMatrix.RotateMatrix(__compMatrix, (int)comp.direction); switch (rootToComp) { case Directions.Up: { if (__rootMatrix.ValidAtIndex(0, 1) && __compMatrix.ValidAtIndex(2, 1)) { __localScore += _defaultQuickScore; } else { __localScore -= _defaultQuickScore; } } break; case Directions.Right: { if (__rootMatrix.ValidAtIndex(1, 2) && __compMatrix.ValidAtIndex(1, 0)) { __localScore += _defaultQuickScore; } else { __localScore -= _defaultQuickScore; } } break; case Directions.Down: { if (__rootMatrix.ValidAtIndex(2, 1) && __compMatrix.ValidAtIndex(0, 1)) { __localScore += _defaultQuickScore; } else { __localScore -= _defaultQuickScore; } } break; case Directions.Left: { if (__rootMatrix.ValidAtIndex(1, 0) && __compMatrix.ValidAtIndex(1, 2)) { __localScore += _defaultQuickScore; } else { __localScore -= _defaultQuickScore; } } break; } } else { } return(__localScore); }