Explorar el Código

Add a random symbol generator + add some variables

Yann Weber hace 6 años
padre
commit
b45e6fe081
Se han modificado 1 ficheros con 17 adiciones y 2 borrados
  1. 17
    2
      gte/turmit.py

+ 17
- 2
gte/turmit.py Ver fichero

@@ -1,9 +1,16 @@
1 1
 import collections
2 2
 import inspect
3
+import random
3 4
 
4 5
 _op_list = collections.OrderedDict()
5 6
 _var_list = collections.OrderedDict()
6 7
 
8
+_var_list['x'] = 0
9
+_var_list['y'] = 0
10
+_var_list['r'] = 0
11
+_var_list['g'] = 0
12
+_var_list['b'] = 0
13
+
7 14
 def RpnOp(method):
8 15
     ''' @brief Decorator for RPN operation that autodetect argument count
9 16
         
@@ -48,7 +55,7 @@ class RpnSymbol(object):
48 55
         if optype == self.OPERATION:
49 56
             self.value = list(_op_list.keys())[value % len(_op_list)]
50 57
         elif optype == self.VARIABLE:
51
-            self.value %= len(_var_list)
58
+            self.value = list(_var_list.keys())[value % len(_var_list)]
52 59
 
53 60
     def __str__(self):
54 61
         if self.optype == self.OPERATION:
@@ -56,7 +63,15 @@ class RpnSymbol(object):
56 63
         elif self.optype == self.VALUE:
57 64
             return '0x%04X' % self.value
58 65
         else:
59
-            return _var_list[self.value]
66
+            return self.value.upper()
67
+
68
+    @classmethod
69
+    def random(cls):
70
+        optype = [cls.OPERATION, cls.VALUE, cls.VARIABLE]
71
+        optype = optype[random.randint(0,2)]
72
+        return cls(random.randint(0, 0xFFFF), optype)
73
+
74
+
60 75
 
61 76
 class Turmit(object):
62 77
     ''' @brief Represent a turmit that act given an RPN expression with an

Loading…
Cancelar
Guardar