Exemple #1
0
def parcoursPlateau(jeu):
    """ jeu -> int
    Score utilisé par rapport
            - au tableau de weightsC(poids pr chaque case)
            - du nombre de pions de couleur noire ou blanche sur le plateau
            - mobilité
            - coins captures
            """
    pio = 0
    mobi = 0
    ccaptur = 0
    for i in range(8):
        for j in range(8):
            if game.getPlateau(jeu)[i][j] == moi:
                pio += weightsC[i][j]
                if [i, j] == [0, 0] or [i, j] == [0, 7] or [i, j] == [
                        7, 0
                ] or [i, j] == [7, 7]:
                    ccaptur += 1
            elif game.getPlateau(jeu)[i][j] == adv:
                pio -= weightsC[i][j]
                mobi += 1
                if [i, j] == [0, 0] or [i, j] == [0, 7] or [i, j] == [
                        7, 0
                ] or [i, j] == [7, 7]:
                    ccaptur -= 1
    return [pio, mobi, ccaptur]
def evaluationPositional(jeu):
    plateau = game.getPlateau(jeu)
    s = 0
    for i in range(8):
        for j in range(8):
            if (plateau[i][j] == monJoueur):
                s += positional[i][j]
    return s
def finalisePartie(jeu):
    """jeu->void
        Met a jour les scores des joueurs en prenant en compte les graines restantes sur le plateau
    """
    p=game.getPlateau(jeu)
    g1=reduce(lambda a,b: a+b,p[0])
    g2=reduce(lambda a,b: a+b,p[1])
    game.addScore(jeu,1,g1)
    game.addScore(jeu,2,g2)
def evalPos(jeu):
    diffExtr = 0
    
    p = 0.8
    plateau=game.getPlateau(jeu)
    j1=0
    j2=0
    ligne=plateau[0]
    ligne2=plateau[1]
    for i in range(6):
        j1 += p * ligne[i]
        j2 += p * ligne2[-i-1]
        p-=0.1

    diffExtr=j1-j2
    if(moi==2):
       diffExtr=-diffExtr
       
    return diffExtr
Exemple #5
0
def parcoursPlateau(jeu):
    """ jeu -> int
        Retourne score d utilite calcule en fonction :
        * du tableau weights qui correspond au poids de chaque Case du plateau
    -   * du nombre de pions de chaque couleur sur le plateau(noir/blanche)
        * de la mobilite
        * du nombre de corners captures(plus haut p)
        """
    plateau = game.getPlateau(jeu)
    moi_pions = 0  #NB de pions
    adv_pions = 0
    moi_pionsFrontier = 0  #pions a moi adjacents a cases vides
    adv_pionsFrontier = 0  #pions adv adjacents a cases vides
    moi_Corners = 0  #coins captures par moi
    adv_Corners = 0  #coins capturés par l'adversaire
    moi_pionsNearCorners = 0  #pions proches des coins valeur pr moi
    adv_pionsNearCorners = 0  #pions proches des coins valeur pr adversaire

    scoreP = 0

    for i in range(8):
        for j in range(8):
            if plateau[i][
                    j] == moi:  #VERIF SI piece est a moi si oui on incremente score pions
                scoreP = scoreP + weightsC[i][j]
                moi_pions += 1

                if (i == 0 and j == 0) or (i == 7 and j == 0) or (
                        i == 0 and j == 7) or (i == 7 and j == 7):
                    moi_Corners = moi_Corners + 1

            elif plateau[i][j] == adv:

                scoreP = scoreP - weightsC[i][j]
                adv_pions += 1
                if (i == 0 and j == 0) or (i == 7 and j == 0) or (
                        i == 0 and j == 7) or (i == 7 and j == 7):
                    adv_Corners = adv_Corners + 1

            if plateau[i][j] != 0:

                for k in range(8):
                    x = i + X1[k]
                    y = j + Y1[k]
                    if x >= 0 and x < 8 and y >= 0 and y < 8 and plateau[x][
                            y] == 0:
                        if plateau[i][j] == moi:
                            moi_pionsFrontier = moi_pionsFrontier + 1
                        else:
                            adv_pionsFrontier = moi_pionsFrontier + 1

                        break

#on verifie s'il y a des pieces posées autour des corners...
#COIN haut gauche:
    if plateau[0][0] == 0:
        if (plateau[0][1] == adv):
            adv_pionsNearCorners += 1
        elif (plateau[0][1] == moi):
            moi_pionsNearCorners += 1

        if (plateau[1][0] == adv):
            adv_pionsNearCorners += 1
        elif (plateau[1][0] == moi):
            moi_pionsNearCorners += 1

        if (plateau[1][1] == adv):
            adv_pionsNearCorners += 1
        elif (plateau[1][1] == moi):
            moi_pionsNearCorners += 1

#COIN bas gauche:
    if (plateau[7][0] == 0):
        if (plateau[6][1] == adv):
            adv_pionsNearCorners += 1
        elif (plateau[6][1] == moi):
            moi_pionsNearCorners += 1

        if (plateau[6][0] == adv):
            adv_pionsNearCorners += 1
        elif (plateau[6][0] == moi):
            moi_pionsNearCorners += 1

        if (plateau[7][1] == adv):
            adv_pionsNearCorners += 1
        elif (plateau[7][1] == moi):
            moi_pionsNearCorners += 1

#COIN haut droit
    if (plateau[0][7] == 0):
        if (plateau[0][6] == adv):
            adv_pionsNearCorners += 1
        elif (plateau[0][6] == moi):
            moi_pionsNearCorners += 1

        if (plateau[1][6] == adv):
            adv_pionsNearCorners += 1
        elif (plateau[1][6] == moi):
            moi_pionsNearCorners += 1

        if (plateau[1][6] == adv):
            adv_pionsNearCorners += 1
        elif (plateau[1][6] == moi):
            moi_pionsNearCorners += 1


#COIN bas droit
    if (plateau[7][7] == 0):
        if (plateau[6][6] == adv):
            adv_pionsNearCorners += 1
        elif (plateau[6][6] == moi):
            moi_pionsNearCorners += 1

        if (plateau[7][6] == adv):
            adv_pionsNearCorners += 1
        elif (plateau[7][6] == moi):
            moi_pionsNearCorners += 1

        if (plateau[6][7] == adv):
            adv_pionsNearCorners += 1
        elif (plateau[6][7] == moi):
            moi_pionsNearCorners += 1

    return [
        moi_pions, adv_pions, moi_pionsFrontier, adv_pionsFrontier,
        moi_Corners, adv_Corners, moi_pionsNearCorners, adv_pionsNearCorners,
        scoreP
    ]
Exemple #6
0
def parcoursPlateau(jeu):
    """ jeu -> int
		Retourne score d utilite calcule en fonction :
			- du tableau poidsCases
			- du nombre de pions de couleur noire ou blanche sur l echiquier
			- de la mobilite
			- du nombre de coins captures
	"""
    plateau = game.getPlateau(jeu)
    pionsMoi = 0
    pionsAdv = 0
    pionsFrontiereMoi = 0  #pions en frontiere = pions adjacents a des cases vides
    pionsFrontiereAdv = 0
    coinsMoi = 0  #coins captures
    coinsAdv = 0
    pionsProchesCoinsMoi = 0  #pions proches des coins
    pionsProchesCoinsAdv = 0
    scorePlateauPondere = 0
    for i in range(8):
        for j in range(8):
            if plateau[i][j] == moi:
                scorePlateauPondere += poidsCases[i][j]
                pionsMoi += 1
                if [i, j] == [0, 0] or [i, j] == [0, 7] or [i, j] == [
                        7, 0
                ] or [i, j] == [7, 7]:
                    coinsMoi += 1
            elif plateau[i][j] == adv:
                scorePlateauPondere -= poidsCases[i][j]
                pionsAdv += 1
                if [i, j] == [0, 0] or [i, j] == [0, 7] or [i, j] == [
                        7, 0
                ] or [i, j] == [7, 7]:
                    coinsAdv = 1
            if plateau[i][j] != 0:
                for k in range(8):
                    x = i + X1[k]
                    y = j + Y1[k]
                    if x >= 0 and x < 8 and y >= 0 and y < 8 and plateau[x][
                            y] == 0:
                        if plateau[i][j] == moi:
                            pionsFrontiereMoi += 1
                        else:
                            pionsFrontiereAdv += 1
                        break
    if plateau[0][0] == 0:
        if (plateau[0][1] == moi):
            pionsProchesCoinsMoi += 1
        elif (plateau[0][1] == adv):
            pionsProchesCoinsAdv += 1
        if (plateau[1][1] == moi):
            pionsProchesCoinsMoi += 1
        elif (plateau[1][1] == adv):
            pionsProchesCoinsAdv += 1
        if (plateau[1][0] == moi):
            pionsProchesCoinsMoi += 1
        elif (plateau[1][0] == adv):
            pionsProchesCoinsAdv += 1
    if (plateau[0][7] == 0):
        if (plateau[0][6] == moi):
            pionsProchesCoinsMoi += 1
        elif (plateau[0][6] == adv):
            pionsProchesCoinsAdv += 1
        if (plateau[1][6] == moi):
            pionsProchesCoinsMoi += 1
        elif (plateau[1][6] == adv):
            pionsProchesCoinsAdv += 1
        if (plateau[1][7] == moi):
            pionsProchesCoinsMoi += 1
        elif (plateau[1][7] == adv):
            pionsProchesCoinsAdv += 1
    if (plateau[7][0] == 0):
        if (plateau[7][1] == moi):
            pionsProchesCoinsMoi += 1
        elif (plateau[7][1] == adv):
            pionsProchesCoinsAdv += 1
        if (plateau[6][1] == moi):
            pionsProchesCoinsMoi += 1
        elif (plateau[6][1] == adv):
            pionsProchesCoinsAdv += 1
        if (plateau[6][0] == moi):
            pionsProchesCoinsMoi += 1
        elif (plateau[6][0] == adv):
            pionsProchesCoinsAdv += 1
    if (plateau[7][7] == 0):
        if (plateau[6][7] == moi):
            pionsProchesCoinsMoi += 1
        elif (plateau[6][7] == adv):
            pionsProchesCoinsAdv += 1
        if (plateau[6][6] == moi):
            pionsProchesCoinsMoi += 1
        elif (plateau[6][6] == adv):
            pionsProchesCoinsAdv += 1
        if (plateau[7][6] == moi):
            pionsProchesCoinsMoi += 1
        elif (plateau[7][6] == adv):
            pionsProchesCoinsAdv += 1

    return [
        pionsMoi, pionsAdv, pionsFrontiereMoi, pionsFrontiereAdv, coinsMoi,
        coinsAdv, pionsProchesCoinsMoi, pionsProchesCoinsAdv,
        scorePlateauPondere
    ]