Ejemplo n.º 1
0
    private List <TurnResponse> ComputeCoupsPossibles(PieceState[][] Plateau, Team team)
    {
        List <TurnResponse> ListeDeCoupsPossibles = new List <TurnResponse>();
        Card Carte1;
        Card Carte2;

        if (team == Team.A)
        {
            Carte1 = InfoGiver.cardA1; Carte2 = InfoGiver.cardA2;
        }
        else
        {
            Carte1 = InfoGiver.cardB1; Carte2 = InfoGiver.cardB2;
        }

        for (int i = 0; i <= 4; i++)
        {
            for (int j = 0; j <= 4; j++)
            {
                if (Plateau[i][j] != null)
                {
                    if (Plateau[i][j].team == team)
                    {
                        int[][] moves;
                        for (int IndiceCarte = 1; IndiceCarte <= 2; IndiceCarte++)
                        {
                            Card Carte;
                            if (IndiceCarte == 1)
                            {
                                Carte = Carte1;
                            }
                            else
                            {
                                Carte = Carte2;
                            }
                            if (team == Team.A)
                            {
                                moves = Carte.GetMoves();
                            }
                            else
                            {
                                moves = Carte.GetMovesReversed();
                            }
                            for (int X = 0; X <= 4; X++)
                            {
                                for (int Y = 0; Y <= 4; Y++)
                                {
                                    if (moves[X][Y] == 1)
                                    {
                                        int ii = i + X - 2;
                                        int jj = j + Y - 2;
                                        if (ii >= 0 && ii <= 4 && jj >= 0 && jj <= 4) // reste dans le damier
                                        {
                                            bool CoupCorrect = true;
                                            if (Plateau[ii][jj] != null)                  // il y a déjà une pièce
                                            {
                                                if (Plateau[ii][jj].team == team)
                                                {
                                                    CoupCorrect = false;                                   // pièce du même camp
                                                }
                                            }
                                            if (CoupCorrect == true)
                                            {
                                                ListeDeCoupsPossibles.Add(new TurnResponse(Carte.cardName,
                                                                                           new Vector2Int(i, j),
                                                                                           new Vector2Int(i + X - 2, j + Y - 2)));
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }

        if (ListeDeCoupsPossibles.Count == 0)
        {
            return(null);
        }
        else
        {
            return(ListeDeCoupsPossibles);
        }
    }