Example #1
0
 def joueur_suivant(self):
     j=self.get_joueur_actif()
     i=imod(j.get_idj() + 1,self.nb_joueur)
     for j in self.joueurs:
         if i==j.get_idj():
             if j.is_vendu() or not j.is_inGame():
                 # Le joueur suivant est vendu ou a fini! On donne la main au joueur d'après
                 j.activer(False)
                 i=imod(i+1,self.nb_joueur)
             else:
                 j.activer(True)
         else:
             j.activer(False)
             
     #Deuxieme tour pour la forme
     for j in self.joueurs:
         if i==j.get_idj():
             if j.is_vendu() or not j.is_inGame():
                 # Le joueur suivant est vendu ! On donne la main au joueur d'après
                 j.activer(False)
                 i=imod(i+1,self.nb_joueur)
             else:
                 j.activer(True)
         else:
             j.activer(False)
Example #2
0
 def operator_imod(size):
     a = Array(size, 'int32')
     b = Array(size, 'int32')
     for i in range(size):
         a[i] = nb_types.int32(i * 123)
         b[i] = nb_types.int32(7)
     operator.imod(a, b)
     return a
Example #3
0
def main():

    x,y = 5,6
    a,b = 7,8

    # Incremental Add : x += y
    iAdd = operator.iadd(5, 6)
    print("iAdd: ", iAdd)

    # Incremental Concatenate
    iConCat = operator.iconcat("Hello", "World")
    print("iConCat:", iConCat)

    # Incremental Subtraction
    iSub = operator.isub(5, 6)
    print("iSub: ", iSub)

    # Incremental Multiplication
    iMul = operator.imul(5,6)
    print("iMul:", iMul)

    # Incremental Division
    iDiv = operator.itruediv(10, 5)
    print("iDiv: ", iDiv)

    # Incremental Modulus
    iMod = operator.imod(10, 6)
    print("iMod: ", iMod)

    # Incremental Exponential
    iPow = operator.ipow(2, 4)
    print("iPow: ", iPow)
Example #4
0
    def legal_actions(self):
        """The list of all legal actions.

        The first two actions must be using a number as all the operators are
        binary and require two numbers.
        """

        # By checking against evaluated_expression instead of expression this
        # checks that there are enough numbers for an operator to be a legal
        # action.

        if not self.evaluated_expression:
            return self.numbers

        if len(self.evaluated_expression) == 1:
            # This assumes that step() removed the number from the expression.
            return self.numbers

        # Check if the divide operator is valid.
        if len(self.evaluated_expression) >= 2:
            if self.evaluated_expression[-1] == 0:
                # The expression would be A / 0 which is not legal.
                legal_operators = self.operators[:]
                legal_operators.remove(operator.floordiv)
                return self.numbers + legal_operators

            if operator.imod(*self.evaluated_expression[-2:]) != 0:
                # The expression A / B would result in a non-integer result.
                # This makes the floordiv operator illegal here.
                legal_operators = self.operators[:]
                legal_operators.remove(operator.floordiv)
                return self.numbers + legal_operators

        return self.numbers + self.operators
Example #5
0
 def test_inplace(self):
     #operator = self.module
     class C(object):
         def __iadd__     (self, other): return "iadd"
         def __iand__     (self, other): return "iand"
         def __ifloordiv__(self, other): return "ifloordiv"
         def __ilshift__  (self, other): return "ilshift"
         def __imod__     (self, other): return "imod"
         def __imul__     (self, other): return "imul"
         def __ior__      (self, other): return "ior"
         def __ipow__     (self, other): return "ipow"
         def __irshift__  (self, other): return "irshift"
         def __isub__     (self, other): return "isub"
         def __itruediv__ (self, other): return "itruediv"
         def __ixor__     (self, other): return "ixor"
         def __getitem__(self, other): return 5  # so that C is a sequence
     c = C()
     self.assertEqual(operator.iadd     (c, 5), "iadd")
     self.assertEqual(operator.iand     (c, 5), "iand")
     self.assertEqual(operator.ifloordiv(c, 5), "ifloordiv")
     self.assertEqual(operator.ilshift  (c, 5), "ilshift")
     self.assertEqual(operator.imod     (c, 5), "imod")
     self.assertEqual(operator.imul     (c, 5), "imul")
     self.assertEqual(operator.ior      (c, 5), "ior")
     self.assertEqual(operator.ipow     (c, 5), "ipow")
     self.assertEqual(operator.irshift  (c, 5), "irshift")
     self.assertEqual(operator.isub     (c, 5), "isub")
     self.assertEqual(operator.itruediv (c, 5), "itruediv")
     self.assertEqual(operator.ixor     (c, 5), "ixor")
     self.assertEqual(operator.iconcat  (c, c), "iadd")
Example #6
0
    def test_inplace(self):
        #operator = self.module
        class C(object):
            def __iadd__(self, other):
                return "iadd"

            def __iand__(self, other):
                return "iand"

            def __ifloordiv__(self, other):
                return "ifloordiv"

            def __ilshift__(self, other):
                return "ilshift"

            def __imod__(self, other):
                return "imod"

            def __imul__(self, other):
                return "imul"

            def __ior__(self, other):
                return "ior"

            def __ipow__(self, other):
                return "ipow"

            def __irshift__(self, other):
                return "irshift"

            def __isub__(self, other):
                return "isub"

            def __itruediv__(self, other):
                return "itruediv"

            def __ixor__(self, other):
                return "ixor"

            def __getitem__(self, other):
                return 5  # so that C is a sequence

        c = C()
        self.assertEqual(operator.iadd(c, 5), "iadd")
        self.assertEqual(operator.iand(c, 5), "iand")
        self.assertEqual(operator.ifloordiv(c, 5), "ifloordiv")
        self.assertEqual(operator.ilshift(c, 5), "ilshift")
        self.assertEqual(operator.imod(c, 5), "imod")
        self.assertEqual(operator.imul(c, 5), "imul")
        self.assertEqual(operator.ior(c, 5), "ior")
        self.assertEqual(operator.ipow(c, 5), "ipow")
        self.assertEqual(operator.irshift(c, 5), "irshift")
        self.assertEqual(operator.isub(c, 5), "isub")
        self.assertEqual(operator.itruediv(c, 5), "itruediv")
        self.assertEqual(operator.ixor(c, 5), "ixor")
        self.assertEqual(operator.iconcat(c, c), "iadd")
    def test_imod(self):
        x = 10 * pq.m
        x %= 3 * pq.m
        self.assertQuantityEqual(x, 1 * pq.m)

        x = 10 * pq.m
        x %= (3 * pq.m).rescale('ft')
        self.assertQuantityEqual(x, 10 * pq.m % (3 * pq.m))

        self.assertRaises(ValueError, lambda: op.imod(10 * pq.J, 3 * pq.m))
    def test_imod(self):
        x = 10*pq.m
        x %= 3*pq.m
        self.assertQuantityEqual(x, 1*pq.m)

        x = 10*pq.m
        x %= (3*pq.m).rescale('ft')
        self.assertQuantityEqual(x, 10*pq.m % (3*pq.m))

        self.assertRaises(ValueError, lambda: op.imod(10*pq.J, 3*pq.m))
    def test_class_binary_inplace_operators(self):
        class WithLotsOfOperators(Class):
            def __iadd__(self, other):
                return (self, "iadd", other)

            def __isub__(self, other):
                return (self, "isub", other)

            def __imul__(self, other):
                return (self, "imul", other)

            def __imod__(self, other):
                return (self, "imod", other)

            def __itruediv__(self, other):
                return (self, "itruediv", other)

            def __ifloordiv__(self, other):
                return (self, "ifloordiv", other)

            def __ilshift__(self, other):
                return (self, "ilshift", other)

            def __irshift__(self, other):
                return (self, "irshift", other)

            def __ior__(self, other):
                return (self, "ior", other)

            def __iand__(self, other):
                return (self, "iand", other)

            def __ixor__(self, other):
                return (self, "ixor", other)

            def __imatmul__(self, other):
                return (self, "imatmul", other)

        c = WithLotsOfOperators()

        self.assertEqual(operator.iadd(c, 0), (c, "iadd", 0))
        self.assertEqual(operator.isub(c, 0), (c, "isub", 0))
        self.assertEqual(operator.imul(c, 0), (c, "imul", 0))
        self.assertEqual(operator.imod(c, 0), (c, "imod", 0))
        self.assertEqual(operator.itruediv(c, 0), (c, "itruediv", 0))
        self.assertEqual(operator.ifloordiv(c, 0), (c, "ifloordiv", 0))
        self.assertEqual(operator.ilshift(c, 0), (c, "ilshift", 0))
        self.assertEqual(operator.irshift(c, 0), (c, "irshift", 0))
        self.assertEqual(operator.ior(c, 0), (c, "ior", 0))
        self.assertEqual(operator.iand(c, 0), (c, "iand", 0))
        self.assertEqual(operator.ixor(c, 0), (c, "ixor", 0))
        self.assertEqual(operator.imatmul(c, 0), (c, "imatmul", 0))
Example #10
0
 def distribuer(self, nbjoueurs=5):
     #par défaut on jouera à 5
     mains = []
     i = 0
     while i < nbjoueurs:
         mains.append(Main(i))
         i += 1
     i = 0
     for c in self.pioche:
         mains[i].ajouter_carte(c)
         i = imod(i + 1, nbjoueurs)
     self.pioche = []
     return mains
Example #11
0
    def __init__(self, players=None):
        """
        :type self: object
        """
        self.board = Board()

        self.number_stones = 11
        self.number_foxes = 1
        self.number_blockers = 1

        self.players = players
        self.nplayer = 1
        self.current_player = Color.blue
        self.other_player = Color.red
        self.board = Board()

        self.size = 10

        self.available_simple_stones = {}
        self.available_foxes = {}
        self.available_blockers = {}
        self.removed_stones = {}

        for c in Color:
            self.available_simple_stones[
                c] = self.number_stones  #[SimpleStone(c) for i in range(0, self.size)]
            self.available_foxes[c] = self.number_foxes
            self.available_blockers[c] = self.number_blockers
            self.removed_stones[c] = []

        self.player = [Color.red, Color.blue]

        self.mod_size = lambda x: operator.imod(x, self.size)
        self.ml = lambda s, x, y, z: [
            "%s_%s" % (s, i) for i in map(self.mod_size, [x, y, z])
        ]
        self.same_col = lambda a, b: a.color == b.color
        self.occupied = lambda x: x != Board.empty
        self.stones_of_same_player = lambda a, b: self.occupied(
            a) and self.occupied(b) and self.same_col(a, b)
Example #12
0
    def __init__(self, players=None):
        """
        :type self: object
        """
        self.board = Board()

        self.number_stones = 11
        self.number_foxes = 1
        self.number_blockers = 1

        self.players = players
        self.nplayer = 1
        self.current_player = Color.blue
        self.other_player = Color.red
        self.board = Board()

        self.size = 10

        self.available_simple_stones = {}
        self.available_foxes = {}
        self.available_blockers = {}
        self.removed_stones = {}

        for c in Color:
            self.available_simple_stones[c] = self.number_stones  #[SimpleStone(c) for i in range(0, self.size)]
            self.available_foxes[c] = self.number_foxes
            self.available_blockers[c] = self.number_blockers
            self.removed_stones[c] = []

        self.player = [Color.red, Color.blue]

        self.mod_size = lambda x: operator.imod(x, self.size)
        self.ml = lambda s, x, y, z: ["%s_%s" % (s, i) for i in map(self.mod_size, [x, y, z])]
        self.same_col = lambda a, b: a.color == b.color
        self.occupied = lambda x: x != Board.empty
        self.stones_of_same_player = lambda a, b: self.occupied(a) and self.occupied(b) and self.same_col(a, b)
 def _test_quantity_mod(self, unit, func):
     a = self.Q_("10*meter")
     b = self.Q_("3*second")
     with pytest.raises(DimensionalityError):
         op.mod(a, b)
     with pytest.raises(DimensionalityError):
         op.mod(3, b)
     with pytest.raises(DimensionalityError):
         op.mod(a, 3)
     with pytest.raises(DimensionalityError):
         op.imod(a, b)
     with pytest.raises(DimensionalityError):
         op.imod(3, b)
     with pytest.raises(DimensionalityError):
         op.imod(a, 3)
     func(
         op.mod,
         unit * self.NON_INT_TYPE("10"),
         "4.2*meter/meter",
         self.NON_INT_TYPE("1.6"),
         unit,
     )
Example #14
0
      such as strings, numbers and tuples.'''
      
import operator
# using iadd() to add and assign value 
x = 2;y = 3
x = operator.iadd(x,y)
print("Addition",x)

x = 2;y = 3
x = operator.isub(x,y)
print("Subtraction", x)

x = 2;y = 3
x = operator.imul(x,y)
print("Multiply",x)

x = 10;y = 5
x = operator.itruediv(x,y)
print("Divide",x)

x = 10; y = 6
x = operator.imod(x,y)
print("Mod",x)


# initializing another values
y = 'geeks'
z = 'forgeeks'
# using iconcat() to concat the sequences
y = operator.iconcat(y,z)
print(y)
Example #15
0
 def imod_usecase(x, y):
     return operator.imod(x, y)
Example #16
0
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE."""
import platform
import operator
import os


# version x.y.z
#   This version will have same meaning as Linux
#       x -- Production version with big different feature
#       y -- Odd number means formal version, Even number means development version
#       z -- Count of fixing bugs
__version__ = '0.1.1'
__os_platform__ = platform.system().upper() if platform.system() else 'LINUX'
__running_mode__ = (0 == operator.imod(int(__version__.split('.')[1]), 2))


DATABASE_CONFIG = {
    'authentication': {
        'user': os.getenv('DB_USER'),
        'password': os.getenv('DB_PASSWORD'),
    },
    'type': os.getenv('DB_TYPE', 'mongodb'),
    'channel': os.getenv('DB_CHANNEL', 'Channel') if __running_mode__ else os.getenv('DB_CHANNEL', 'beta-channel'),
    'trans': os.getenv('DB_TRANS','Transaction') if __running_mode__ else os.getenv('DB_TRANS','beta-trans'),
    'history': os.getenv('DB_HISTORY','History') if __running_mode__ else os.getenv('DB_HISTORY','beta-history'),
    'host': os.getenv('DB_HOST', '127.0.0.1'),
    'port': int(os.getenv('DB_PORT', 27017))
}
Example #17
0
b = 6
print(operator.imul(a, b))

"""5.itruediv() :- This function is used to assign and divide the current value. This operation does “a/=b” operation. Assigning is not performed in case of immutable
containers, such as strings, numbers and tuples."""

a = 64
b = 8
print(operator.itruediv(a, b))

"""6.imod()- This function is used to assign and return remainder. This operation does “a%=b” operation. Assigning is not performed in case of immutable containers,
such as strings, numbers and tuples."""

a = 3
b = 2
print(operator.imod(a, b))

"""7. ixor() :- This function is used to assign and xor the current value. This operation does “a^ = b” operation. Assigning is not performed in case of immutable
containers, such as strings, numbers and tuples."""

a = 1
b = 0
print(operator.ixor(a, b))

"""8.ipow() :- This function is used to assign and exponentiate the current value. This operation does “a ** = b” operation. Assigning is not performed in case of
immutable containers, such as strings, numbers and tuples."""

a = 3
b = 2
print(operator.ipow(a, b))
Example #18
0
 def __imod__(self, other):
     return operator.imod(self._wrapped(), other)
Example #19
0
# using isub() to subtract and assign value
x = operator.isub(2, 3);

# printing the modified value
print ("The value after subtracting and assigning : ", end="")
print (x)

# using imul() to multiply and assign value
x = operator.imul(2, 3);

# printing the modified value
print ("The value after multiplying and assigning : ", end="")
print (x)



# using itruediv() to divide and assign value
x = operator.itruediv(10, 5);

# printing the modified value
print ("The value after dividing and assigning : ", end="")
print (x)

# using imod() to modulus and assign value
x = operator.imod(10, 6);

# printing the modified value
print ("The value after modulus and assigning : ", end="")
print (x)
Example #20
0
 def imod_usecase(x, y):
     return operator.imod(x, y)
if math.isnan(math.nan):
    print("True : Not a number")
else:
    print("its a number")

if math.isinf(math.inf):
    print("True: infinite number")
else:
    print("not infinite number")
#------- Random related functions

mylist = ['purushotham', 'chandra', 'ravi']
print(random.randint(1, 5))
print(random.random())
print(random.choice(mylist))
random.shuffle(mylist)

#--- Number of seconds from EPOCH time i.e from Jan1st 1970
print(time.time())

print(date.fromtimestamp(1565335861.4913108))

#------------- operator(Inplace) related functions --------------------

print(operator.iadd(2, 3))
print(operator.isub(3, 2))
print(operator.imul(3, 2))
print(operator.itruediv(5, 3))
print(operator.imod(5, 3))
print(operator.iconcat('Purushotham', 'Reddy'))
print(li)
operator.delitem(li, slice(1, 4))
print(li)
print(operator.getitem(li, slice(0, 2)))
s1 = "testing "
s2 = "operator"
print(operator.concat(s1, s2))
if (operator.contains(s1, s2)):
    print("Contains")
else:
    print("It doesn't")
a = 1
b = 0
print(operator.and_(a, b))
print(operator.or_(a, b))
print(operator.invert(a))

x = 10
y = 5
print(operator.iadd(x, y))
print(operator.isub(x, y))
print(operator.iconcat(s1, s2))
print(operator.imul(x, y))
print(operator.itruediv(x, y))
print(operator.imod(x, y))
print(operator.ixor(x, y))
print(operator.ipow(x, y))
print(operator.iand(x, y))
print(operator.ior(x, y))
print(operator.ilshift(x, y))
print(operator.irshift(x, y))
Example #23
0
 def update_event(self, inp=-1):
     self.set_output_val(0, operator.imod(self.input(0), self.input(1)))
# using isub() to subtract and assign value
x = operator.isub(2, 3)

# printing the modified value
print("The value after subtracting and assigning : ", end="")
print(x)

# using imul() to multiply and assign value
x = operator.imul(2, 3)

# printing the modified value
print("The value after multiplying and assigning : ", end="")
print(x)

# Python code to demonstrate the working of
# itruediv() and imod()

# using itruediv() to divide and assign value
x = operator.itruediv(10, 5)

# printing the modified value
print("The value after dividing and assigning : ", end="")
print(x)

# using imod() to modulus and assign value
x = operator.imod(10.0, 6)

# printing the modified value
print("The value after modulus and assigning : ", end="")
print(x)