예제 #1
0
def evaluation1(self, joueur):
    """
    evalue numeriquement la situation dans lequel se trouve le joueur
    """
    if self.perdant(joueur): return -10000
    if self.gagnant(joueur): return 10000
    if self.pose:
        score = 0
        for i, pion in enumerate(self.board):
            if pion == NOIRS or pion == ROI:
                score -= self._distance_from_doo(i)
                if i % 2 == 1 and (pion == NOIRS or pion == ROI):
                    score += 2
        return score
    else:
        if cycling(self.hist):
            if joueur == J_ATT:
                return -10000
            else:
                return 10000
        nb_blancs = self.board.count(BLANCS)
        nb_noirs = 0
        smallest_distance = 3
        for i, pion in enumerate(self.board):
            if pion == NOIRS or pion == ROI:
                nb_noirs += 1
                smallest_distance = min(smallest_distance,
                                        self._distance_from_doo(i))
        return -(smallest_distance)**2 - 3 * nb_blancs
예제 #2
0
def evaluation3(self, joueur):
    """
    evalue numeriquement la situation dans lequel se trouve le joueur
    """
    if self.perdant(joueur): return -10000
    if self.gagnant(joueur): return 10000
    if self.pose:
        score = 0
        for i, pion in enumerate(self.board):
            if pion == NOIRS or pion == ROI:
                score -= self._distance_from_doo(i)
                for d in 'rudl':
                    try:
                        score += int(self.cell(i, d) == NOIRS) * 2
                    except ValueError:
                        pass
        return score
    else:
        if cycling(self.hist):
            if joueur == J_ATT:
                return -10000
            else:
                return 10000
        nb_blancs = self.board.count(BLANCS)
        nb_noirs = 0
        smallest_distance = 3
        for i, pion in enumerate(self.board):
            if pion == NOIRS or pion == ROI:
                nb_noirs += 1
                smallest_distance = min(smallest_distance,
                                        self._distance_from_doo(i))
        return -3**abs(nb_blancs - 1) + nb_noirs
예제 #3
0
def evaluation5(self, joueur):
    global pos_win
    board = self.configuration[0]
    pose = self.configuration[1] < 8
    if self.perdant(joueur): return -10000 - self.configuration[1]
    if self.gagnant(joueur): return 10000 - self.configuration[1]
    if pose:
        score = 0
        for i, pion in enumerate(self.board):
            if pion == NOIRS or pion == ROI:
                score -= self._distance_from_doo(i)
        return score
        #return random.randint(0, 100)
    else:
        if cycling(self.hist):
            if joueur == J_ATT:
                return -10000
            else:
                return 10000
        nb_blancs = board.count(BLANCS)
        nb_noirs = 0
        smallest_distance = 3
        for i, pion in enumerate(board):
            if pion == NOIRS or pion == ROI:
                nb_noirs += 1
                smallest_distance = min(smallest_distance,
                                        self._distance_from_doo(i))
        if (board[4] == BLANCS):
            return -(smallest_distance) - 4 * int(
                board[4] == BLANCS) - nb_blancs
        return -(smallest_distance) - nb_blancs * 3
예제 #4
0
def evaluation4(self, joueur):
    board = self.configuration[0]
    pose = self.configuration[1] < 8
    if self.perdant(joueur): return -10000
    if self.gagnant(joueur): return 10000
    if pose:
        score = 0
        for i, pion in enumerate(self.board):
            if pion == NOIRS or pion == ROI:
                for d in 'rudl':
                    try:
                        score -= int(self.cell(i, d) == NOIRS)
                    except ValueError:
                        pass
            score -= self._distance_from_doo(i)
            if pion == ROI:
                score -= self._distance_from_doo(i)
        return score
        #return random.randint(0,100)
    else:
        if cycling(self.hist):
            if joueur == J_ATT:
                return -10000
            else:
                return 10000
        nb_blancs = board.count(BLANCS)
        nb_noirs = 0
        smallest_distance = 3
        for i, pion in enumerate(board):
            if pion == NOIRS or pion == ROI:
                nb_noirs += 1
                smallest_distance = min(smallest_distance,
                                        self._distance_from_doo(i))
        return (-(smallest_distance) - abs(nb_blancs - 1)**2 -
                3 * int(board[4] == BLANCS) - abs(nb_noirs - 1))
예제 #5
0
def dummy(self, joueur):
    if self.perdant(joueur):
        return -100
    if self.gagnant(joueur):
        return 100
    if cycling(
            self.hist):  # On punit fortement le cycling pour les deux joueurs
        if joueur == J_ATT:
            return -10000
        else:
            return 10000
    return 0
예제 #6
0
def test_cycling():
    """ permet de tester la détection d'un cycle """
    _datas = ( [ (1,2), (2,3), (3,1), (4,2), (1,2), (2,3) ],
               [ (1,2), (2,3), (3,[1]), (4,2), (1,2), (2,3) ],
	       [ (1,[2]), (2,3), (3,1), (4,2), (1,[2]), (2,3) ],
	       [ (1,2), (2,[3]), (3,1), (4,2), (1,[2]), (2,[3]) ],
               )
    _expect = (True, False, False, False)
    _head = ( [], [ (i,j) for i in range(3) for j in range(2) ],
              [ (i,j) for i in range(3) for j in range(3) ] )
    _lstr =''
    _args = inspect.getfullargspec( tp.cycling ).args
    _lstr += check_property( len(_args) == 1 )
    for x in _head:
        for i in range(4) :
            _lstr += check_property( tp.cycling( x+_datas[i] ) == _expect[i] )
        prop = tp.cycling(x+_datas[0]+_datas[1]) == _expect[1]
        _lstr += check_property( prop )
        prop = tp.cycling(x+_datas[1]+_datas[0]) == _expect[0]
        _lstr += check_property( prop )
    return _lstr
예제 #7
0
def evaluation6(self, joueur):
    global pos_win_white, pos_lose_black, pos_lose_white, pos_win_black
    board = self.configuration[0]
    idboard = [pion if pion != ROI else NOIRS for pion in board]
    trait = J_ATT if self.configuration[1] % 2 == 1 else J_DEF
    id_ = create_id((idboard, self.configuration[1]), trait)
    pose = self.configuration[1] < 8

    if self.perdant(joueur):
        return -1000 + self.configuration[1]
    if self.gagnant(joueur):
        return 1000 - self.configuration[1]

    if pose:
        score = 0
        for i, pion in enumerate(self.board):
            if pion == NOIRS or pion == ROI:
                score -= self._distance_from_doo(i)
                for l in "rudl":
                    try:
                        score += int(
                            self.doo.cell(i, l) == BLANCS
                            or self.doo.cell(i, l) == VIDE) * 2
                    except:
                        pass
        return score
        #return random.randint(0, 100)
    else:
        if cycling(self.hist):
            if joueur == J_ATT:
                return -10000
            else:
                return 10000
        nb_blancs = board.count(BLANCS)
        nb_noirs = 0
        smallest_distance = 3
        for i, pion in enumerate(board):
            if pion == NOIRS or pion == ROI:
                nb_noirs += 1
                smallest_distance = min(smallest_distance,
                                        self._distance_from_doo(i))

        if id_ in pos_win_black or id_ in pos_lose_white:
            return 1000 - self.configuration[1] - 4 * (nb_blancs + nb_noirs)
        elif id_ in pos_win_white or id_ in pos_lose_black:
            return -1000 + self.configuration[1] + 4 * (nb_blancs + nb_noirs)
        if (board[4] == BLANCS):
            return -(smallest_distance) - 2 * int(
                board[4] == BLANCS) - nb_blancs
        return -5 * nb_blancs - smallest_distance