public override float Evaluate(ISpace space, Point markedPoint, Point unmarkedPoint) { // walk m_length tiles and verify they are all free Point cur = unmarkedPoint; for (int i = 0; i < m_length; ++i) { if (!space.IsAreaFree(cur)) return float.PositiveInfinity; cur = DirectionUtils.Move(cur, m_direction); } // went one too far, so back up to last tile in the dealio cur = DirectionUtils.Move(cur, m_direction.Opposite); int blockedCount = 0; if (!space.IsAreaFree(cur)) blockedCount++; if (!space.IsAreaFree(DirectionUtils.Move(cur, m_exitDir.RotationCW))) blockedCount++; if (!space.IsAreaFree(DirectionUtils.Move(cur, m_exitDir.RotationCCW))) blockedCount++; if (!space.IsAreaFree(DirectionUtils.Move(cur, m_exitDir))) blockedCount++; return blockedCount / 4.0f; }
public override float Evaluate(ISpace space, Point markedPoint, Point unmarkedPoint) { float bestCost = float.PositiveInfinity; // worst possible, best possible is 0 foreach (Direction dir in m_directions) { // walk m_length tiles and verify they are all free Point cur = unmarkedPoint; int counter = 0; int blockedCounter = 0; for (int i = 0; i < m_length; ++i) { if (!space.IsAreaFree(cur)) { blockedCounter = Int32.MaxValue - 5; break; } counter += 2; if (!space.IsAreaFree(dir.RotationCW.Move(cur))) blockedCounter++; if (!space.IsAreaFree(dir.RotationCCW.Move(cur))) blockedCounter++; cur = dir.Move(cur); } counter++; if (!space.IsAreaFree(cur)) blockedCounter++; // one past the end float score = (float)blockedCounter / counter; if (score < bestCost) { bestCost = score; m_bestEvaledDirection = dir; } } return bestCost; }