Пример #1
0
    def StatLock_routine_management(self):
        population = loadmachines()
        population = CyclingStatLock(population)

        self.log('')
        self.log('>>>>>STATLOCK ROUTINE MANAGEMENT')
        self.log('')

        setmachines(population)
Пример #2
0
    def routine_pop_management(self, LEVEL):
        if not len(LEVEL):
            return
        population = loadmachines()

        originalPOPLEN = len(population)
        # for individual in population:
        # dump_all_paramstat(individual)

        # for k in range(8):
        #    CHILD = create_hybrid(population)
        #    if CHILD: population.append(CHILD)

        DELTAind = originalPOPLEN // 16

        if "T" in LEVEL:
            halloffame = loadmachines(DIR=settings.TOPmachineDIR)
            halloffame = [mac.filename for mac in halloffame]

            currentbestinds = select_best_inds(population, 18)
            
            for mac in range(len(currentbestinds)):
                if currentbestinds[mac].filename not in halloffame:
                    sendtoHallOfFame(currentbestinds[mac])
                    self.setcounter_sentToHallOfFame += 1
                    break
            #self.Tournament = Tournament(1,1)
            #self.log('RUNNING TOURNAMENT!')

        if "B" in LEVEL:
            MODscorelimit = 2

            population = deltheworst_clonethebest(population,
                                                  -2 * DELTAind,
                                                  MODscorelimit,
                                                  ID=self.ID)
            self.setcounter_deletedmachines += 2 * DELTAind

            population += populate([], DELTAind, True, ID=self.ID)
            self.setcounter_createdmachines += DELTAind

            population += Mate(select_best_inds(population,
                                                DELTAind), DELTAind,ID=self.ID)
            self.setcounter_createdmachines += DELTAind


            numToEquilibrium = originalPOPLEN - len(population)
            if numToEquilibrium > 0:
                self.setcounter_createdmachines += numToEquilibrium
            else:
                self.setcounter_deletedmachines -= numToEquilibrium
            population = deltheworst_clonethebest(population,
                                                numToEquilibrium,
                                                  MODscorelimit,
                                                  ID=self.ID)
            
        if "C" in LEVEL:
            population = EliminateEquals(population, DELTAind)
            NUM = originalPOPLEN - len(population)
            population += populate([], NUM, True, ID=self.ID)
            self.setcounter_deletedmachines += DELTAind
            self.setcounter_createdmachines += NUM
        if "H" in LEVEL:
            population = deltheworst_clonethebest(population,
                                                  -DELTAind,
                                                  MODscorelimit,
                                                  ID=self.ID)
            self.setcounter_deletedmachines += DELTAind
            while len(population) < originalPOPLEN:
                population += clone_from_template(ID=self.ID)
                self.setcounter_createdmachines +=1
        # setmachines need to happen before management level C, which is advanced and loads
            # the population by it's own method.

        if "A" in LEVEL:
            if randrange(10) > 8:
                for k in range(1):
                    population = mutatemachines(1, population)

        if "E" in LEVEL:
            ADVmanagement()

        totalgames = (self.setcounter_illegalmove
                      + self.setcounter_forcedwin
                      + self.setcounter_checkmate
                      + self.setcounter_draws + 1)

  

        if "V" in LEVEL:
            for k in range(len(population)-1):
                for v in range(k+1, len(population)):
                    if not population[k]:
                        break
                    Similarity = EvaluateSimilarityTwoMachines(
                            population[k], population[v]) 
                    if False:
                        bareDeleteMachine(population[k].filename)
                        self.setcounter_deletedmachines +=1
                        print("Excluding %s by similarity to %s." % (
                            population[k].filename, population[v].filename))
                        population[k] = None
                    elif Similarity < 1:
                        print("Mutating %s by similarity." % population[k].filename)
                        population[k].mutate(3,5)


            population = [ x for x in population if x ]

        setmachines(population)
        AverageElo = 0
        for I in population:
            AverageElo += I.ELO
        AverageElo //= len(population)

        self.log('')
        self.log('>> %s >>ROUTINE MANAGEMENT %s' % (self.ID,LEVEL))
        self.log("ROUND = %i. checkmate-> %i; forced wins-> %i; draws-> %i; illegal moves-> %i"
                 % (self.ROUND, self.setcounter_checkmate, self.setcounter_forcedwin, self.setcounter_draws, self.setcounter_illegalmove))
        self.log("initial population size-> %i; final population size-> %i"
                 % (originalPOPLEN, len(population)))
        self.log('Illegal move percentage is %f %%.'
                 % (self.setcounter_illegalmove * 100 / totalgames))
        self.log('Average games per round equals to %i.'
                 % (totalgames // self.ROUND))
        self.log("Average ELO is %i" % AverageElo)
        self.log('')
        print('routine management %s done. Average ELO: %i' %
              (LEVEL, AverageElo))
        self.log("Running Time is %i" % (time() - self.InitTime))
        self.log("Deleted machines: %i; Created machines: %i; Sent to HOF: %i"%\
                (self.setcounter_deletedmachines,
                    self.setcounter_createdmachines,
                    self.setcounter_sentToHallOfFame))
Пример #3
0
    def __init__(self):
        print("""
        loading machines from Hall of Fame.

          Choose your opponent:

                      """)
        self.AllMachines = loadmachines(DIR=settings.TOPmachineDIR)
                        
        print("zero")
        print("0 - random")
        for M in range(len(self.AllMachines)):
            view = '%i - %s' % (M+1, self.AllMachines[M].filename)
            view += " " * (30-len(view)) + "%i :%i" %\
                (self.AllMachines[M].ELO,
                        self.AllMachines[M].getParameter("real_world_score"))
            print(view)

        print("")
        LOADED = 0
        self.AgainstMachine = False
        userchoice = self.CollectInput(
            [x for x in range(len(self.AllMachines)+1)])

        if not userchoice:
            userchoice = randrange(len(self.AllMachines))+1
        else:
            pass
            #choices = userchoice.split(" ")

        Callargs = [settings.enginebin, "--deep", '4', '--xdeep', '1', '--showinfo']

        if userchoice != "zero":
            LOADED = 1
            userchoice -= 1
            print('Loading %s. glhf' % self.AllMachines[userchoice].filename)
            Callargs += ['--specific', self.AllMachines[userchoice].filename]
        self.engineCALL = " ".join(Callargs)

        if self.AgainstMachine:
            GAME = Thread(target=self.LaunchXboardMachineXMachine)
        else:
            GAME = Thread(target=self.LaunchXboardAgainstMachine)
        GAME.start()

        LOGGER = Thread(target=self.StraceAndLogGame)
        LOGGER.start()

        if LOADED:
            try:
                print("Did this machine win the game? [y/n]")
                FeedBack = self.CollectInput(['y', 'n'])
                
            except KeyboardInterrupt:
                print("\n")
                exit()

            if FeedBack == 'y':
                result = 1
                print("logically.")
            else:
                result = -1
                print("a bad day for the computer age.")
            self.AllMachines[userchoice].getParameter("real_world_score",
                        toSUM=result)
            setmachines(self.AllMachines, DIR=settings.TOPmachineDIR)
Пример #4
0
                                     round(max([result[x] for x in result]))):
                for MAC in ApprovedMachines:
                    #if scoreNumber < result[MAC] < scoreNumber +1: # ?????????????
                    print("%s: %i" % (MAC, result[MAC]))

            BestScoreOnGroup = max([result[x] for x in ApprovedMachines])
            NumberOfBestScorers = sum(
                [1 for x in ApprovedMachines if result[x] == BestScoreOnGroup])
            for IND in range(len(pop)):
                NAME = pop[IND].filename
                if NAME not in ApprovedMachines or result[NAME] < 0:
                    management.bareDeleteMachine(_machineDIR, NAME)
                    print("Deleting machine %s." % NAME)
                    pop[IND] = None
            pop = [x for x in pop if x]

            for IND in pop:
                #if FullTestLen * 10 - result[IND.filename] < 20:
                #    core.sendtoHallOfFame(IND)
                if result[IND.filename] == BestScoreOnGroup:
                    if NumberOfBestScorers < len(pop) / 6:
                        core.Mate([IND, random.choice(pop)], 2, ID="POS")

        if options.Mutate:
            stock_popsize = 16
            while len(pop) < stock_popsize / 2 and pop:
                pop += core.Mate(pop, 2, ID="pos")
                pop = core.populate(pop, stock_popsize - len(pop), 1)
                core.mutatemachines(2, pop)
            core.setmachines(pop, DIR=_machineDIR)
Пример #5
0
import sys

import os

from evchess_evolve.core import populate, setmachines

for ARG in sys.argv:
    if ARG == "populate":
        try:
            Q = int(sys.argv[sys.argv.index(ARG) + 1])
        except:
            Q = 16
        if "quadra" in sys.argv:
            MACDIRS = ['_machines_%i' % W for W in range(1, 5)]
        elif "duo" in sys.argv:
            MACDIRS = ['_machines_%i' % W for W in range(1, 3)]
        else:
            MACDIRS = ['machines']

        for MD in MACDIRS:
            if not os.path.isdir(MD):
                os.mkdir(MD)
            if not os.path.isdir("%s/top_machines" % MD):
                os.mkdir("%s/top_machines" % MD)

            machines = populate([], Q, 1)
            for M in machines:
                M.DIR = MD
            print("creating %i machines under dir %s." % (len(machines), MD))
            setmachines(machines, MD)
Пример #6
0
    def routine_pop_management(self, LEVEL):
        if not len(LEVEL):
            return
        population = loadmachines()

        originalPOPLEN = settings.standard_popsize #len(population)

        DELTAind = originalPOPLEN // 16

        if "T" in LEVEL:
            halloffame = loadmachines(DIR=settings.HoFmachineDIR)
            halloffame = [mac.filename for mac in halloffame]

            currentbestinds = select_best_inds(population, 18)
            
            for mac in range(len(currentbestinds)):
                if currentbestinds[mac].filename not in halloffame:
                    sendtoHallOfFame(currentbestinds[mac])
                    self.setcounter_sentToHallOfFame += 1
                    break
            #self.Tournament = Tournament(1,1)
            #self.log('RUNNING TOURNAMENT!')

        if "B" in LEVEL:
            MODscorelimit = 2

            population = deltheworst_clonethebest(population,
                                                  -2 * DELTAind,
                                                  MODscorelimit,
                                                  ID=self.ID)
            self.setcounter_deletedmachines += 2 * DELTAind

            population += populate([], DELTAind, True, ID=self.ID)
            self.setcounter_createdmachines += DELTAind

            population += Mate(select_best_inds(population,
                                                DELTAind), DELTAind,ID=self.ID)
            self.setcounter_createdmachines += DELTAind


            numToEquilibrium = originalPOPLEN - len(population)
            if numToEquilibrium > 0:
                self.setcounter_createdmachines += numToEquilibrium
            else:
                self.setcounter_deletedmachines -= numToEquilibrium
            population = deltheworst_clonethebest(population,
                                                numToEquilibrium,
                                                  MODscorelimit,
                                                  ID=self.ID)
            
        if "C" in LEVEL:
            population = EliminateEquals(population, DELTAind)
            NUM = originalPOPLEN - len(population)
            population += populate([], NUM, True, ID=self.ID)
            self.setcounter_deletedmachines += DELTAind
            self.setcounter_createdmachines += NUM
        if "H" in LEVEL:
            population = deltheworst_clonethebest(population,
                                                  -DELTAind,
                                                  MODscorelimit,
                                                  ID=self.ID)
            self.setcounter_deletedmachines += DELTAind
            while len(population) < originalPOPLEN:
                population += clone_from_template(ID=self.ID)
                self.setcounter_createdmachines +=1
        # setmachines need to happen before management level C, which is advanced and loads
            # the population by it's own method.

        if "A" in LEVEL:
            if randrange(10) > 8:
                for k in range(1):
                    population = mutatemachines(1, population)

        if "E" in LEVEL:
            ADVmanagement()

        totalgames = (self.setcounter_illegalmove
                      + self.setcounter_forcedwin
                      + self.setcounter_checkmate
                      + self.setcounter_draws + 1)

  

        if "V" in LEVEL:
            for k in range(len(population)-1):
                for v in range(k+1, len(population)):
                    if not population[k]:
                        break
                    Similarity = EvaluateSimilarityTwoMachines(
                            population[k], population[v]) 
                    if False:
                        bareDeleteMachine(population[k].filename)
                        self.setcounter_deletedmachines +=1
                        print("Excluding %s by similarity to %s." % (
                            population[k].filename, population[v].filename))
                        population[k] = None
                    elif Similarity < 1:
                        print("Mutating %s by similarity." % population[k].filename)
                        population[k].mutate(3,1)


            population = [ x for x in population if x ]

        setmachines(population)
        AverageElo = 0
        for I in population:
            AverageElo += I.ELO
        AverageElo //= len(population)

        self.log('')
        self.log('>> %s >>ROUTINE MANAGEMENT %s' % (self.ID,LEVEL))
        self.log("ROUND = %i. checkmate-> %i; forced wins-> %i; draws-> %i; illegal moves-> %i"
                 % (self.ROUND, self.setcounter_checkmate, self.setcounter_forcedwin, self.setcounter_draws, self.setcounter_illegalmove))
        self.log("initial population size-> %i; final population size-> %i"
                 % (originalPOPLEN, len(population)))
        self.log('Illegal move percentage is %f %%.'
                 % (self.setcounter_illegalmove * 100 / totalgames))
        self.log('Average games per round equals to %i.'
                 % (totalgames // self.ROUND))
        self.log("Average ELO is %i" % AverageElo)
        self.log('')
        print('routine management %s done. Average ELO: %i' %
              (LEVEL, AverageElo))
        self.log("Running Time is %i" % (time() - self.InitTime))
        self.log("Deleted machines: %i; Created machines: %i; Sent to HOF: %i"%\
                (self.setcounter_deletedmachines,
                    self.setcounter_createdmachines,
                    self.setcounter_sentToHallOfFame))
Пример #7
0
    def __init__(self):
        print("""
        loading machines from Hall of Fame.

          Choose your opponent:

                      """)
        self.AllMachines = loadmachines(DIR=settings.TOPmachineDIR)

        print("zero")
        print("0 - random")
        for M in range(len(self.AllMachines)):
            view = '%i - %s' % (M + 1, self.AllMachines[M].filename)
            view += " " * (30-len(view)) + "%i :%i" %\
                (self.AllMachines[M].ELO,
                        self.AllMachines[M].getParameter("real_world_score"))
            print(view)

        print("")
        LOADED = 0
        self.AgainstMachine = False
        userchoice = self.CollectInput(
            [x for x in range(len(self.AllMachines) + 1)])

        if not userchoice:
            userchoice = randrange(len(self.AllMachines)) + 1
        else:
            pass
            #choices = userchoice.split(" ")

        Callargs = [
            settings.enginebin, "--deep", '4', '--xdeep', '1', '--showinfo'
        ]

        if userchoice != "zero":
            LOADED = 1
            userchoice -= 1
            print('Loading %s. glhf' % self.AllMachines[userchoice].filename)
            Callargs += ['--specific', self.AllMachines[userchoice].filename]
        self.engineCALL = " ".join(Callargs)

        if self.AgainstMachine:
            GAME = Thread(target=self.LaunchXboardMachineXMachine)
        else:
            GAME = Thread(target=self.LaunchXboardAgainstMachine)
        GAME.start()

        LOGGER = Thread(target=self.StraceAndLogGame)
        LOGGER.start()

        if LOADED:
            try:
                print("Did this machine win the game? [y/n]")
                FeedBack = self.CollectInput(['y', 'n'])

            except KeyboardInterrupt:
                print("\n")
                exit()

            if FeedBack == 'y':
                result = 1
                print("logically.")
            else:
                result = -1
                print("a bad day for the computer age.")
            self.AllMachines[userchoice].getParameter("real_world_score",
                                                      toSUM=result)
            setmachines(self.AllMachines, DIR=settings.TOPmachineDIR)