using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NurseRosterProb
{
    class Cls_Penalty
    {
        public int[,] Function_Calculate_Penalty(string[,] MainTab, int N_Max)
        {
            int[,] Res_Pena = new int[N_Max + 1, 2];
            int Penalty = 0;
            int pena = 0;
            int N_C = 0;
            int wd_i;
            int INC = 1;
            bool Shift_Similar;
            string[] WD_Arr = { null, null, null, null };
            while (N_C < N_Max)
            {
                // NNNNOO
                for (int Days_C = 1; Days_C <= 14; Days_C++)
                    if (MainTab[N_C, Days_C] == "N" && Days_C < 6)
                        if (MainTab[N_C, Days_C + 6] == "M")
                        { Penalty++; pena++; break; }
                        else
                            continue;
                // EEEE-or-MMMMM
                wd_i = 0;
                Shift_Similar = true;
                for (int Days_C = 1; Days_C <= 14; Days_C++)
                    if (Days_C == 14 && wd_i > 0 && MainTab[N_C, Days_C] != "O")
                    {
                        for (int i = 0; i < wd_i - 1; i++)
                            if (WD_Arr[i] != WD_Arr[i + 1])
                            { Shift_Similar = false; break; }
                        if (Shift_Similar == false)
                        { Penalty += 10; pena += 10; }
                    }
                    else
                        if (MainTab[N_C, Days_C] != "O")
                        { WD_Arr[wd_i] = MainTab[N_C, Days_C]; wd_i++; }
                        else
                            if (wd_i > 0)
                                if (wd_i < 4)
                                { Penalty += 10; wd_i = 0; pena += 10; }
                                else
                                {
                                    for (int i = 0; i < 3; i++)
                                        if (WD_Arr[i] != WD_Arr[i + 1])
                                        { Shift_Similar = false; break; }
                                    if (Shift_Similar == false)
                                    { Penalty += 10; wd_i = 0; Shift_Similar = true; pena += 10; }
                                    else
                                        wd_i = 0;
                                }
                N_C++;
                Res_Pena[INC, 0] = N_C;
                Res_Pena[INC, 1] = pena;
                INC++;
                pena = 0;
            }
            Res_Pena[0, 0] = Penalty;
            return Res_Pena;
        }
    }
}
