예제 #1
0
파일: game.py 프로젝트: jdvr/RadikalChess
    def utility(self, state, player):
        """ This return a value between -infinity and infinity based on how good is the state for the player"""

        player_type = player.get_type()
        player_color = player.get_color()

        if player_color is Piece.WHITE:
            if state.is_check_for_enemy(Piece.BLACK):
                if state.is_check_mate_for_enemy(Piece.BLACK):
                    return 99999999
                else:
                    return 99999999 - 100000
            if state.is_check_for_enemy(Piece.WHITE):
                if state.is_check_mate_for_enemy(Piece.WHITE):
                    return -99999999
                else:
                    return -99999999 + 100000
        elif player_color is Piece.BLACK:
            if state.is_check_for_enemy(Piece.WHITE):
                if state.is_check_mate_for_enemy(Piece.WHITE):
                    return 99999999
                else:
                    return 99999999 - 100000
            if state.is_check_for_enemy(Piece.BLACK):
                if state.is_check_mate_for_enemy(Piece.BLACK):
                    return -99999999
                else:
                    return -99999999 + 100000

        if player_type is Player.IDIOT:
            return 0

        elif player_type is Player.FIGHTER:

            if state.can_kill(player_color):
                state_quality = 50000
            else:
                state_quality = 0

            for row in state.get_board():
                for pos in row:
                    if pos is not None:
                        if pos.get_color() is player_color:
                            state_quality += Piece.VALUES[pos.get_type()]
                        else:
                            state_quality -= Piece.VALUES[pos.get_type()]
            return state_quality

        elif player_type is Player.SMARTEST or player_type is Player.HUMAN:
            db_access = Load()
            can_kill = state.can_kill(player_color)
            can_be_killed = state.can_be_killed(player_color)

            if db_access.compare_with_data_base_states(state, player):
                state_quality = 20000
            else:
                state_quality = 0

            if can_kill and not can_be_killed:
                state_quality += 15000
            elif not can_kill and not can_be_killed:
                state_quality += 10000
            elif can_kill and can_be_killed:
                state_quality -= 5000
            elif not can_kill and can_be_killed:
                state_quality -= 5000

            for row in state.get_board():
                for pos in row:
                    if pos is not None:
                        if pos.get_color() is player_color:
                            state_quality += Piece.VALUES[pos.get_type()]
                        else:
                            state_quality -= Piece.VALUES[pos.get_type()]
            return state_quality
예제 #2
0
파일: game.py 프로젝트: jdvr/RadikalChess
    def utility(self, state, player):
        """ This return a value between -infinity and infinity based on how good is the state for the player"""

        player_type = player.get_type()
        player_color = player.get_color()

        if player_color is Piece.WHITE:
            if state.is_check_for_enemy(Piece.BLACK):
                if state.is_check_mate_for_enemy(Piece.BLACK):
                    return 99999999
                else:
                    return 99999999 - 100000
            if state.is_check_for_enemy(Piece.WHITE):
                if state.is_check_mate_for_enemy(Piece.WHITE):
                    return -99999999
                else:
                    return -99999999 + 100000
        elif player_color is Piece.BLACK:
            if state.is_check_for_enemy(Piece.WHITE):
                if state.is_check_mate_for_enemy(Piece.WHITE):
                    return 99999999
                else:
                    return 99999999 - 100000
            if state.is_check_for_enemy(Piece.BLACK):
                if state.is_check_mate_for_enemy(Piece.BLACK):
                    return -99999999
                else:
                    return -99999999 + 100000

        if player_type is Player.IDIOT:
            return 0

        elif player_type is Player.FIGHTER:

            if state.can_kill(player_color):
                state_quality = 50000
            else:
                state_quality = 0

            for row in state.get_board():
                for pos in row:
                    if pos is not None:
                        if pos.get_color() is player_color:
                            state_quality += Piece.VALUES[pos.get_type()]
                        else:
                            state_quality -= Piece.VALUES[pos.get_type()]
            return state_quality

        elif player_type is Player.SMARTEST or player_type is Player.HUMAN:
            db_access = Load()
            can_kill = state.can_kill(player_color)
            can_be_killed = state.can_be_killed(player_color)

            if db_access.compare_with_data_base_states(state, player):
                state_quality = 20000
            else:
                state_quality = 0

            if can_kill and not can_be_killed:
                state_quality += 15000
            elif not can_kill and not can_be_killed:
                state_quality += 10000
            elif can_kill and can_be_killed:
                state_quality -= 5000
            elif not can_kill and can_be_killed:
                state_quality -= 5000

            for row in state.get_board():
                for pos in row:
                    if pos is not None:
                        if pos.get_color() is player_color:
                            state_quality += Piece.VALUES[pos.get_type()]
                        else:
                            state_quality -= Piece.VALUES[pos.get_type()]
            return state_quality