Exemplo n.º 1
0
    def setUp(self):
        """
        Creation de la méthode setUp permettant de générer un joueur fictif.
        """
        self.tab = tableau.Tableau(5)
        self.tab.creation_tableau()

        self.j = joueur.Joueur("joueurNumero1", self.tab, 200)
        self.j.score = 9000

        self.nbr_bateaux = 3
        self.bateau1 = bateau.Bateau("porte-avion", 4, "touché")
        self.bateau1.coordonnees_bateau = [1, 1, "o"], [1, 2, "o"], [1, 3, "o"], [1, 4, "o"]

        self.bateau2 = bateau.Bateau("torpilleur", 2, "actif")
        self.bateau2.coordonnees_bateau = [4, 1, "o"], [4, 2, "o"]

        self.bateau3 = bateau.Bateau("croiseur", 2, "actif")
        self.bateau3.coordonnees_bateau = [5, 1, "o"], [5, 2, "o"]

        self.bateau4 = bateau.Bateau("canonniere", 3, "actif")

        self.bateau5 = bateau.Bateau("destroyer", 3, "actif")

        self.j.porte_avion = self.bateau1
        self.j.torpilleur = self.bateau2
        self.j.croiseur = self.bateau3
        self.j.canonniere = self.bateau4
        self.j.destroyer = self.bateau5
Exemplo n.º 2
0
Arquivo: army.py Projeto: krzhang/fotd
 def __init__(self, name, units, armyid, color, intelligence_type, morale):
     self.name = name
     self.units = units
     self.commander = self.units[0]
     self.commander.add_unit_status("is_commander")
     self.color = color
     self.armyid = armyid
     for u in units:
         u.army = self
         u.set_color(color)
         for s in u.character.skills:
             u.add_unit_status(s.skill_str)
             # crazy bug here because add_unit_status will just run the constructor to
             # blah_STATUS without the associatied string, creating a status that's not from a
             # skillstring
             # u.unit_status.append(status.Status.FromSkillName(s.skill_str))
     self.intelligence = intelligence.INTELLIGENCE_FROM_TYPE[
         intelligence_type](self)
     self.morale = morale
     self.last_turn_morale = morale
     # things to be linked later
     self.yomi_edge = None  # used in battles to see if RPS was won
     self.battle = None
     self.formation_bonus = 1.0
     self.formation = None
     self.order = None
     self.commitment_bonus = False
     self.battle_lost = False
     self.tableau = tableau.Tableau(self)
Exemplo n.º 3
0
def get_crystal_graph(shape, m=None):
    """
    Function to create crystal graph data.

    :param shape: shape of tableaux in graph
    :param m: m such that allowed entries in t are 1 to m and 1-bar to m-bar
    :return: a list of all k-n tableaux for given shape and value of m, an f_i dictionary with all the kn tableaux as keys with a list as value, where (i-1)st index in list refer to tableau obtained by applying f_i to the key tableau. A similar e_i tableaux dictionary.
    """
    if m is None:
        m = len(shape)
    starting_tableau = tab.Tableau([[a.Ordinary(i+1) for _ in range(shape[i])] for i in range(len(shape))])
    tableaux = [starting_tableau]
    fi_map, ei_map = dict(), dict()
    ei_map[starting_tableau] = [None for _ in range(m)]
    index = 0
    while index < len(tableaux):
        t = tableaux[index]
        fi_map[t] = f = [None for _ in range(m)]
        for i in range(m):
            f_of_t = f_i(t, i+1, m, False)
            if f_of_t is not None:
                if f_of_t in ei_map:
                    e = ei_map[f_of_t]
                else:
                    e = [None for _ in range(m)]
                    ei_map[f_of_t] = e
                    tableaux.append(f_of_t)
                f[i] = f_of_t
                e[i] = t
        index += 1
    return tableaux, fi_map, ei_map
Exemplo n.º 4
0
    def test_adding_constraints(self, ):
        A, b, c = self.setup_data()
        tab = tableau.Tableau()
        tab.add_constraints(A, b)

        constraints = self.create_constraints_as_list(A, b)

        self.assertEqual(tab.tab.tolist(), constraints)
Exemplo n.º 5
0
    def test_adding_constraints_after_adding_objective(self, ):
        A, b, c = self.setup_data()
        tab = tableau.Tableau()
        tab.add_objective(c, False)
        tab.add_constraints(A, b)

        constraints = self.create_constraints_as_list(A, b)
        constraints.append(c)

        self.assertEqual(tab.tab.tolist(), constraints)
Exemplo n.º 6
0
    def test_compare_algorithms(self):
        patterns = ["%s/bounded/*","%s/inf/*","%s/no/*"]
        ignore = lambda fname: not fname.endswith(".a")
        test_dirs  = [ p % TestDataRunner.test_directory for p in patterns ]
        test_files = self.flatten([filter(ignore,glob.iglob(d)) for d in test_dirs])
        debug=True

        failures_by_file = {}
        
        for tf in test_files:
            
            (A,b,c,n,m) = main.Reader.parse(file=tf)
            
            algorithms  = {"Tableau" : tableau.Tableau(A,b,c,n,m,debug=False),
                           # some reason simplex stops workign with new min index
                           #"Simplex" : simplex.Simplex(A,b,c,n,m,debug=False),
                           "Scipy"   : scipy_lprog.SciPy(A,b,c,n,m,debug=False)}
            results  = {}
            anst,ansx = None,None
            failed = False

            for (name,algo) in algorithms.items():
                try:
                    results[name] = algo.solve()
                except Exception as e:
                    print(tf)
                    import traceback
                    traceback.print_exc()
                        
                    #traceback.print_exception(Exception,e, sys.last_traceback)

                if anst is None and ansx is None:
                    anst,ansx = results[name]
                    
                cur_t,cur_x   = results[name]
                
                if cur_t != anst:
                    failed = True

            if not tf in failures_by_file and failed:
                failures_by_file[tf] = results


        for (tf,results) in failures_by_file.items():
            tf_dir,tf_file = tf.split(os.path.sep)[-2:]
            
            print("%s/%s:" %(tf_dir,tf_file))
                    
            for key in results.keys():
                anst,ansx = results[key]
                print("| %10s | %10s | %20s |" % (key,anst,matrix.map_optional(float,ansx)))
Exemplo n.º 7
0
    def build(self, signedFormulas):
        """ Vytvori a vrati uzavrete alebo uplne tablo pre zoznam oznacenych formul. """

        # vyplnime prve vrcholy podla zoznamu vstupnych formul
        tabl = tableau.Tableau()
        lastNode = None
        for sign, formula in signedFormulas:
            newNode = tableau.Node(sign, formula)
            tabl.append(lastNode, newNode)
            lastNode = newNode

        # TODO vytvorit tablo

        return tabl
Exemplo n.º 8
0
    def build(self, signedFormulas):
        """ Vytvori a vrati uzavrete alebo uplne tablo pre zoznam oznacenych formul. """

        # vyplnime prve vrcholy podla zoznamu vstupnych formul
        tabl = tableau.Tableau()
        lastNode = None
        for sf in signedFormulas:
            newNode = tableau.Node(sf)
            tabl.append(lastNode, newNode)
            lastNode = newNode
            # TODO skontrolovat, ci uz nie je rovno uztvorene

        # TODO vytvorit tablo (alebo oznacit ako zatvorene, ak sa vstupne formuly rovno uzavreli)

        return tabl
Exemplo n.º 9
0
 def renderTableau(self):
     if not self.tableauimages:
         return
     size = self.tableauimages[0].shape[0]
     radinc = numpy.sqrt(2 * size * size)
     tab = tableau.Tableau()
     for i, im in enumerate(self.tableauimages):
         ang = self.tableauangles[i]
         rad = radinc * self.tableaurads[i]
         tab.insertImage(im, angle=ang, radius=rad)
     self.tabimage, self.tabscale = tab.render()
     if self.settings['tableau type'] == 'beam tilt series-image':
         mean = self.tabimage.mean()
         std = self.tabimage.std()
         a = numpy.where(self.tabimage >= mean + 5 * std, 0, self.tabimage)
         self.tabimage = numpy.clip(a, 0, mean * 1.5)
     self.displayTableau()
     self.saveTableau()
Exemplo n.º 10
0
Arquivo: table.py Projeto: tcdude/pyos
 def __init__(
     self, callback: Callable[[card.Card, common.TableLocation, List[int]],
                              None]
 ) -> None:
     self._tableau = tableau.Tableau()
     self._foundation = foundation.Foundation()
     self._stack: List[card.Card] = []
     self._waste: List[card.Card] = []
     self._history: List[Move] = []
     self._state = State()
     self._callback = callback
     self._shuffler = rules.Shuffler()
     self._wrapped = {
         'draw': self.__wrap_method(self.__draw),
         'flip': self.__wrap_method(self.__flip),
         'undo': self.__wrap_method(self.__undo),
         'w2t': self.__wrap_method(self.__waste_to_tableau),
         'w2f': self.__wrap_method(self.__waste_to_foundation),
         't2f': self.__wrap_method(self.__tableau_to_foundation),
         't2t': self.__wrap_method(self.__tableau_to_tableau),
         'f2t': self.__wrap_method(self.__foundation_to_tableau)
     }
Exemplo n.º 11
0
block = pygame.Surface((50, 50))
block.fill(255)


#Fonction pour dessiner un tableau
def dessiner_niveau(surface, niveau):

    for j, ligne in enumerate(niveau):
        for i, case in enumerate(ligne):
            if case == 1:
                screen.blit(block, (i * 50, j * 50))


#----------------------------------------------------------------

tab1 = tableau.Tableau('abc.png', 0, 600, 500, 0, 600, 100)
tab2 = tableau.Tableau('brick-wall.png', 0, 200, 500, 500, 600, 600)
tab3 = tableau.Tableau('sky.jpg', 0, 200, 500, 500, 600, 600)
listetab = [tab1, tab2, tab3]
i = 0
screen = pygame.display.set_mode((1000, 1000))
#affichageTableau(listetab[i])
perso = pygame.image.load('perso.png')
pos_pers = perso.get_rect()

o = Personnage(perso, tab1.xdebut, tab1.ydebut - 250, 2)

screen.blit(o.image, o.pos)
pygame.display.flip()

pygame.key.set_repeat(20, 10)
Exemplo n.º 12
0
    def test_creating_maximization_problem(self, ):
        A, b, c = self.setup_data()
        tab = tableau.Tableau()
        tab.add_objective(c, True)

        self.assertEqual([-entry for entry in c], tab.tab.tolist()[-1])
Exemplo n.º 13
0
    def test_creating_minimization_problem(self, ):
        A, b, c = self.setup_data()
        tab = tableau.Tableau()
        tab.add_objective(c, False)

        self.assertEqual(c, tab.tab.tolist()[-1])
Exemplo n.º 14
0
    screen.blit(tab.background, (0, 0))
    pygame.display.flip()


def verifSortie(perso, i, listetab):

    if (perso.pos.right == listetab[i].xfin) or (perso.pos.bottom
                                                 == listetab[i].yfin):
        i += 1
        perso.pos.left = listetab[i].xdebut
        perso.pos.bottom = listetab[i].ydebut
        affichageTableau(listetab[i])


#--------------------------------------------------------
tab1 = tableau.Tableau('abc.png', 0, 600, 600, 0)
tab2 = tableau.Tableau('brick-wall.jpg', 0, 200, 600, 600)
listetab = [tab1, tab2]
i = 0
screen = pygame.display.set_mode((600, 600))
affichageTableau(listetab[i])
perso = pygame.image.load('perso.png')
pos_pers = perso.get_rect()

o = Personnage(perso, tab1.xdebut, tab1.ydebut - 250, 5)

pygame.key.set_repeat(400, 30)
while 1:
    for event in pygame.event.get():
        if event.type == KEYDOWN:
            if event.key == K_DOWN: