//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> /// Rotates an InterestMatrix in increments of 90 degrees /// </summary> /// <param name="matrix"></param> /// <param name="multiplier"></param> /// <returns></returns> public static InterestMatrix RotateMatrix(InterestMatrix matrix, int multiplier) { double angle = (-90 * multiplier) / (180 / System.Math.PI); double __cos = System.Math.Cos(angle); double __sin = System.Math.Sin(angle); int[,] __finalMatrix = new int[3, 3]; int __currentValue = 0; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { __currentValue = matrix._self[i, j]; double x = (System.Math.Round(((i - 1) * __cos)) - System.Math.Round(((j - 1) * __sin))); double y = (System.Math.Round(((i - 1) * __sin)) + System.Math.Round(((j - 1) * __cos))); x++; y++; __finalMatrix[(int)x, (int)y] = __currentValue; } } return(new InterestMatrix(__finalMatrix)); }
/// <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); }