Exemple #1
0
    def StatLock_routine_management(self):
        population = loadmachines()
        population = CyclingStatLock(population)

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

        setmachines(population)
Exemple #2
0
    def rollThruMachines(self):
        Approved = {}
        POP = core.loadmachines(DIR=self.machineDIR)
        print("Rolling thru %i machines." % len(POP))
        machinelist = [x.filename for x in POP]
        for machine in machinelist:
            machine = machine.replace('\n', '')
            print(".%s." % machine)
            self.subject.send("load %s" % machine)
            sleep(0.3)
            SCORE, Success = self.launchTest()
            if Success:
                Approved.update({machine: SCORE})

        self.Result = Approved
Exemple #3
0
    def __init__(self, scr, RUN, DELETE):
        if scr:
            self.mainscr = scr
            self.stdscr = curses.newpad(1024, 768)
        else:
            self.mainscr = None
            self.stdscr = None

        self.verboseBoards = False

        signal.signal(signal.SIGINT, self.SIGINTFinishAndQuit)

        self.Competitors = loadmachines(DIR=settings.HoFmachineDIR)
        shuffle(self.Competitors)
        self.Competitors = self.Competitors[:settings.TournamentPoolSize]

        self.TotalDead = 0
        self.ToDeleteLosers = DELETE
        for PLAYER in self.Competitors:
            PLAYER.TournamentScore = 0

        self.Deaths = len(self.Competitors) // 2
        L = len(self.Competitors) // 2
        self.MaxTableboardSize = L if L < 7 else 7

        print("%i competitors." % len(self.Competitors))
        self.EngineCommand = [
            settings.enginebin, '-MD', settings.HoFmachineDIR, '--deep', '4',
            '--xdeep',
            str(xDeepValue), '--ydeep',
            str(yDeepValue)
        ]

        self.TABLEBOARD = [
            Table(None, forceNoGUI=True) for k in range(self.MaxTableboardSize)
        ]
        if RUN:
            self.TypeOfTournament = RUN
            print("\n\n")
            T = None
            if RUN == "tournament":
                T = Thread(target=self.ProperTournament)
            elif RUN == "killemall":
                T = Thread(target=self.KillEmAllTournament)
            if T:
                T.start()
Exemple #4
0
    def __init__(self, scr, RUN, DELETE):
        if scr:
            self.mainscr = scr
            self.stdscr = curses.newpad(1024, 768)
        else:
            self.mainscr = None
            self.stdscr = None

        self.verboseBoards = False

        signal.signal(signal.SIGINT, self.SIGINTFinishAndQuit) 

        self.Competitors = loadmachines(DIR=settings.TOPmachineDIR)
        shuffle(self.Competitors)
        self.Competitors = self.Competitors[:settings.TournamentPoolSize]
        
        self.TotalDead = 0
        self.ToDeleteLosers = DELETE
        for PLAYER in self.Competitors:
            PLAYER.TournamentScore = 0

        self.Deaths = len(self.Competitors) // 2
        L = len(self.Competitors)//2
        self.MaxTableboardSize = L if L < 7 else 7

        print("%i competitors." % len(self.Competitors))
        self.EngineCommand = [settings.enginebin,
                              '-MD', settings.TOPmachineDIR,
                              '--deep', '4',
                              '--xdeep', str(xDeepValue),
                              '--ydeep', str(yDeepValue),
                              '--specific']

        self.TABLEBOARD = [Table(None, forceNoGUI=True)
                          for k in range(self.MaxTableboardSize)]
        if RUN:
            self.TypeOfTournament = RUN
            print("\n\n")
            T = None
            if RUN == "tournament":
                T = Thread(target=self.ProperTournament)
            elif RUN == "killemall":
                T = Thread(target=self.KillEmAllTournament)
            if T:
                T.start()
Exemple #5
0
def showBestParameterValues(DIR="machines"):
    pop = loadmachines(DIR=DIR)
    VALUES = {}
    for I in pop:
        for P in I.PARAMETERS:
            VNAME = "%s:    %.2f" % (P.name, P.value)
            if not VNAME in VALUES.keys():
                VALUES[VNAME] = [0,0]
            VALUES[VNAME][0] += I.ELO
            VALUES[VNAME][1] += 1

    TEXT = []
    for K in VALUES.keys():
        MEDIAN = VALUES[K][0]/VALUES[K][1]
        TEXT += ["%s = %.0f [%i]" % (K, MEDIAN, VALUES[K][1]) ]

    TEXT = sorted(TEXT)
    TEXT = "\n".join(TEXT)
    return TEXT
Exemple #6
0
def showBestParameterValues(DIR="machines"):
    pop = loadmachines(DIR=DIR)
    VALUES = {}
    for I in pop:
        for P in I.PARAMETERS:
            VNAME = "%s:    %.2f" % (P.name, P.value)
            if not VNAME in VALUES.keys():
                VALUES[VNAME] = [0, 0]
            VALUES[VNAME][0] += I.ELO
            VALUES[VNAME][1] += 1

    TEXT = []
    for K in VALUES.keys():
        MEDIAN = VALUES[K][0] / VALUES[K][1]
        TEXT += ["%s = %.0f [%i]" % (K, MEDIAN, VALUES[K][1])]

    TEXT = sorted(TEXT)
    TEXT = "\n".join(TEXT)
    return TEXT
Exemple #7
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))
Exemple #8
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)
Exemple #9
0
    for N in range(number_iterations):
        SESSION = trainingDataFeeder('manualdb', engineargs, _machineDIR)
        result = SESSION.Result
        FullTestLen = len(SESSION.TrialPositions)
        print("Total test lenght: %i" % FullTestLen)
        print(result)

        #posLOG.write(json.dumps(result, indent=2)+"\n")
        ApprovedMachines = list(result.keys())
        posLOG.write("\nPassed Tests: %i @ %s, run #%i.\n" %
                     (SESSION.PassedTests, _machineDIR, N))
        posLOG.write('\n'.join([
            "%s: %i" % (W, result[W]) for W in ApprovedMachines
            if result[W] > 0
        ]))
        pop = core.loadmachines(DIR=_machineDIR)
        if result:
            for scoreNumber in range(1,
                                     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)
Exemple #10
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))
Exemple #11
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)